Location overhaul

This commit is contained in:
Vortrex
2021-01-01 01:13:28 -06:00
parent 8d88b31110
commit 3793bbd63f
3 changed files with 71 additions and 64 deletions

View File

@@ -68,7 +68,7 @@ function loadBusinessesFromDatabase() {
// ---------------------------------------------------------------------------
function loadBusinessLocationsFromDatabase(businessId) {
console.log(`[Asshat.Business]: Loading locations for business '${getBusinessData(businessId).name}' from database ...`);
console.log(`[Asshat.Business]: Loading locations for business ${businessId} from database ...`);
let tempBusinessLocations = [];
let dbConnection = connectToDatabase();
@@ -82,7 +82,7 @@ function loadBusinessLocationsFromDatabase(businessId) {
while(dbAssoc = fetchQueryAssoc(dbQuery)) {
let tempBusinessLocationData = new serverClasses.businessLocationData(dbAssoc);
tempBusinessLocations.push(tempBusinessLocationData);
console.log(`[Asshat.Business]: Location for business '${getBusinessData(businessId).name}' loaded from database successfully!`);
console.log(`[Asshat.Business]: Location for business '${businessId}' loaded from database successfully!`);
}
}
freeDatabaseQuery(dbQuery);
@@ -90,7 +90,7 @@ function loadBusinessLocationsFromDatabase(businessId) {
disconnectFromDatabase(dbConnection);
}
console.log(`[Asshat.Business]: ${tempBusinessLocations.length} locations for business '${getBusinessData(businessId).name}' loaded from database successfully`);
console.log(`[Asshat.Business]: ${tempBusinessLocations.length} locations for business ${businessId} loaded from database successfully`);
return tempBusinessLocations;
}
@@ -117,7 +117,7 @@ function createBusinessLocationCommand(command, params, client) {
}
let locationType = toString(splitParams[0]);
let businessId = (isPlayerInAnyBusiness(splitParams[1])) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client));
let businessId = (isPlayerInAnyBusiness(splitParams[1])) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!areParamsEmpty(params)) {
businessId = getBusinessFromParams(params);
@@ -160,7 +160,7 @@ function createBusiness(name, entrancePosition, exitPosition, entrancePickupMode
// ---------------------------------------------------------------------------
function deleteBusinessCommand(command, params, client) {
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client));
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!areParamsEmpty(params)) {
businessId = getBusinessFromParams(params);
@@ -188,7 +188,7 @@ function deleteBusinessLocationCommand(command, params, client) {
function setBusinessNameCommand(command, params, client) {
let newBusinessName = toString(params);
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client));
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!getBusinessData(businessId)) {
messagePlayerError("Business not found!");
@@ -205,7 +205,7 @@ function setBusinessNameCommand(command, params, client) {
function setBusinessOwnerCommand(command, params, client) {
let newBusinessOwner = getPlayerFromParams(params);
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client));
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!newBusinessOwner) {
messagePlayerError("Player not found!");
@@ -226,7 +226,7 @@ function setBusinessOwnerCommand(command, params, client) {
function setBusinessClanCommand(command, params, client) {
let clanId = getClanFromParams(params);
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client));
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!getBusinessData(businessId)) {
messagePlayerError("Business not found!");
@@ -246,7 +246,7 @@ function setBusinessClanCommand(command, params, client) {
// ---------------------------------------------------------------------------
function setBusinessJobCommand(command, params, client) {
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client));
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!areParamsEmpty(params)) {
businessId = getBusinessFromParams(params);
@@ -277,7 +277,7 @@ function setBusinessJobCommand(command, params, client) {
// ---------------------------------------------------------------------------
function setBusinessPublicCommand(command, params, client) {
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client));
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!areParamsEmpty(params)) {
businessId = getBusinessFromParams(params);
@@ -296,7 +296,7 @@ function setBusinessPublicCommand(command, params, client) {
// ---------------------------------------------------------------------------
function lockBusinessCommand(command, params, client) {
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client));
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!areParamsEmpty(params)) {
businessId = getBusinessFromParams(params);
@@ -317,7 +317,7 @@ function lockBusinessCommand(command, params, client) {
function setBusinessEntranceFeeCommand(command, params, client) {
let splitParams = params.split(" ");
let entranceFee = toInteger(splitParams[0]) || 0;
let businessId = getBusinessFromParams(splitParams[1]) || (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client));
let businessId = getBusinessFromParams(splitParams[1]) || (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!getBusinessData(businessId)) {
messagePlayerError("Business not found!");
@@ -374,7 +374,7 @@ function getBusinessInfoCommand(command, params, client) {
function setBusinessPickupCommand(command, params, client) {
let splitParams = params.split(" ");
let typeParam = splitParams[0] || "business";
let businessId = getBusinessFromParams(splitParams[1]) || (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client));
let businessId = getBusinessFromParams(splitParams[1]) || (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!getBusinessData(businessId)) {
messagePlayerError(client, "Business not found!");
@@ -407,7 +407,8 @@ function setBusinessBlipCommand(command, params, client) {
let splitParams = params.split(" ");
let typeParam = splitParams[0] || "business";
let businessId = getBusinessFromParams(splitParams[1]) || (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client));
let closestEntrance = getClosestBusinessEntrance(getPlayerPosition(client));
let businessId = getBusinessFromParams(splitParams[1]) || (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : closestEntrance.business;
if(!getBusinessData(businessId)) {
messagePlayerError(client, "Business not found!");
@@ -426,10 +427,10 @@ function setBusinessBlipCommand(command, params, client) {
getBusinessData(businessId).entranceBlipModel = toInteger(typeParam);
}
deleteBusinessEntranceBlip(businessId);
deleteBusinessExitBlip(businessId);
createBusinessEntranceBlip(businessId);
createBusinessExitBlip(businessId);
deleteBusinessLocationEntranceBlip(businessId, closestEntrance.index);
deleteBusinessLocationExitBlip(businessId, closestEntrance.index);
createBusinessLocationEntranceBlip(businessId, closestEntrance.index);
createBusinessLocationExitBlip(businessId, closestEntrance.index);
messageAdmins(`[#AAAAAA]${client.name} [#FFFFFF]set business [#0099FF]${getBusinessData(businessId).name} [#FFFFFF]blip display to [#AAAAAA]${toLowerCase(typeParam)}`);
}
@@ -445,7 +446,7 @@ function withdrawFromBusinessCommand(command, params, client) {
let splitParams = params.split(" ");
let amount = toInteger(splitParams[0]) || 0;
let businessId = getBusinessFromParams(splitParams[1]) || (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client));
let businessId = getBusinessFromParams(splitParams[1]) || (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!getBusinessData(businessId)) {
messagePlayerError("Business not found!");
@@ -476,7 +477,7 @@ function depositIntoBusinessCommand(command, params, client) {
let splitParams = params.split(" ");
let amount = toInteger(splitParams[0]) || 0;
let businessId = getBusinessFromParams(splitParams[1]) || (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client));
let businessId = getBusinessFromParams(splitParams[1]) || (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!getBusinessData(businessId)) {
messagePlayerError(client, "Business not found!");
@@ -497,7 +498,7 @@ function depositIntoBusinessCommand(command, params, client) {
// ---------------------------------------------------------------------------
function viewBusinessTillAmountCommand(command, params, client) {
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client));
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!areParamsEmpty(params)) {
businessId = getBusinessFromParams(params);
@@ -514,7 +515,7 @@ function viewBusinessTillAmountCommand(command, params, client) {
// ---------------------------------------------------------------------------
function moveBusinessEntranceCommand(command, params, client) {
let businessId = toInteger((isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)));
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!areParamsEmpty(params)) {
businessId = getBusinessFromParams(params);
@@ -541,7 +542,7 @@ function moveBusinessEntranceCommand(command, params, client) {
// ---------------------------------------------------------------------------
function moveBusinessExitCommand(command, params, client) {
let businessId = toInteger((isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)));
let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business;
if(!areParamsEmpty(params)) {
businessId = getBusinessFromParams(params);
@@ -578,11 +579,12 @@ function getBusinessDataFromDatabaseId(databaseId) {
// ---------------------------------------------------------------------------
function getClosestBusinessEntrance(position) {
let closest = 0;
let businesses = getServerData().businesses;
let closest = getServerData().businesses[0].locations[0];
for(let i in businesses) {
if(getDistance(position, businesses[i].entrancePosition) <= getDistance(position, businesses[closest].entrancePosition)) {
closest = i;
for(let j in getServerData().businesses[i].locations) {
if(getDistance(position, businesses[i].locations[j].entrancePosition) <= getDistance(position, closest.entrancePosition)) {
closest = getServerData().businesses[i].locations[j];
}
}
}
return closest;

View File

@@ -11,10 +11,10 @@
// ----------------------------------------------------------------------------
let databaseConfig = {
host: "158.69.238.64",
user: "db24053",
pass: "G3At3d7BsA",
name: "db24053",
host: "127.0.0.1",
user: "gtac-main",
pass: "nEs38AWo4IQEvatEmOteMoruzeREQe",
name: "gtac_main",
port: 3306,
usePersistentConnection: true,
}

View File

@@ -90,7 +90,7 @@ function createHouseCommand(command, params, client) {
// ---------------------------------------------------------------------------
function lockUnlockHouseCommand(command, params, client) {
let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)));
let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house;
if(!getHouseData(houseId)) {
messagePlayerError("House not found!");
@@ -107,7 +107,7 @@ function lockUnlockHouseCommand(command, params, client) {
function setHouseDescriptionCommand(command, params, client) {
let newHouseDescription = toString(params);
let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)));
let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house;
if(!getHouseData(houseId)) {
messagePlayerError("House not found!");
@@ -124,7 +124,7 @@ function setHouseDescriptionCommand(command, params, client) {
function setHouseOwnerCommand(command, params, client) {
let newHouseOwner = getPlayerFromParams(params);
let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)));
let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house;
if(!newHouseOwner) {
messagePlayerError("Player not found!");
@@ -144,7 +144,7 @@ function setHouseOwnerCommand(command, params, client) {
// ---------------------------------------------------------------------------
function setHouseClanCommand(command, params, client) {
let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)));
let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house;
let clan = getClanFromParams(params);
@@ -167,47 +167,51 @@ function setHouseClanCommand(command, params, client) {
function setHousePickupCommand(command, params, client) {
let typeParam = params || "house";
let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)));
let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house;
if(!getHouseData(houseId)) {
messagePlayerError(client, "House not found!");
return false;
}
let entrancePickupModel = getGameConfig().pickupModels[getServerGame()].house;
if(isNaN(typeParam)) {
if(isNull(getGameConfig().pickupModels[getServerGame()][typeParam])) {
messagePlayerError(client, "Invalid house type! Use a house type name or a pickup model ID");
messagePlayerInfo(client, `Pickup Types: [#AAAAAA]${Object.keys(getGameConfig().pickupModels[getServerGame()]).join(", ")}`)
messagePlayerInfo(client, `Pickup Types: [#AAAAAA]${Object.keys(getGameConfig().pickupModels[getServerGame()]).join(", ")}`);
return false;
}
getHouseData(houseId).entrancePickupModel = getGameConfig().pickupModels[getServerGame()][typeParam];
entrancePickupModel = getGameConfig().pickupModels[getServerGame()][typeParam];
} else {
getHouseData(houseId).entrancePickupModel = toInteger(typeParam);
entrancePickupModel = toInteger(typeParam);
}
if(getHouseData(houseId).entrancePickupModel != -1) {
if(getHouseData(houseId).entrancePickup != null) {
destroyElement(getHouseData(houseId).entrancePickup);
for(let i in getHouseData(houseId).locations) {
getHouseData(houseId).locations[i].entrancePickupModel = entrancePickupModel;
deleteHouseLocationEntrancePickup(houseId, i);
if(getHouseData(houseId).locations[i].entrancePickupModel != -1) {
createHouseLocationEntrancePickup(houseId, i);
}
}
createHouseEntrancePickup(houseId);
}
messageAdmins(`[#AAAAAA]${client.name} [#FFFFFF]set house [#11CC11]${getHouseData(houseId).description} [#FFFFFF]pickup display to [#AAAAAA]${toLowerCase(typeParam)}`);
messageAdmins(`[#AAAAAA]${client.name} [#FFFFFF]set house [#11CC11]${getHouseData(houseId).description} [#FFFFFF]pickup display to [#AAAAAA]${entrancePickupModel}`);
}
// ---------------------------------------------------------------------------
function setHouseBlipCommand(command, params, client) {
let typeParam = params || "house";
let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)));
let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house;
if(!getHouseData(houseId)) {
messagePlayerError(client, "House not found!");
return false;
}
let entranceBlipModel = getGameConfig().blipSprites[getServerGame()].house;
if(isNaN(typeParam)) {
if(isNull(getGameConfig().blipSprites[getServerGame()][typeParam])) {
messagePlayerError(client, "Invalid house type! Use a house type name or a blip image ID");
@@ -215,26 +219,26 @@ function setHouseBlipCommand(command, params, client) {
return false;
}
getHouseData(houseId).entranceBlipModel = getGameConfig().blipSprites[getServerGame()][typeParam];
entranceBlipModel = getGameConfig().blipSprites[getServerGame()][typeParam];
} else {
getHouseData(houseId).entranceBlipModel = toInteger(typeParam);
entranceBlipModel = toInteger(typeParam);
}
if(getHouseData(houseId).entranceBlipModel != -1) {
if(getHouseData(houseId).entranceBlip != null) {
destroyElement(getHouseData(houseId).entranceBlip);
for(let i in getHouseData(houseId).locations) {
getHouseData(houseId).locations[i].entranceBlipModel = entranceBlipModel;
deleteHouseLocationEntranceBlip(houseId, i);
if(getHouseData(houseId).locations[i].entranceBlipModel != -1) {
createHouseLocationEntranceBlip(houseId, i);
}
}
createHouseEntranceBlip(houseId);
}
messageAdmins(`[#AAAAAA]${client.name} [#FFFFFF]set house [#11CC11]${getHouseData(houseId).description} [#FFFFFF]blip display to [#AAAAAA]${toLowerCase(typeParam)}`);
messageAdmins(`[#AAAAAA]${client.name} [#FFFFFF]set house [#11CC11]${getHouseData(houseId).description} [#FFFFFF]blip display to [#AAAAAA]${entranceBlipModel}`);
}
// ---------------------------------------------------------------------------
function moveHouseEntranceCommand(command, params, client) {
let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)));
let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house;
getHouseData(houseId).entrancePosition = getPlayerPosition(client);
getHouseData(houseId).entranceDimension = getPlayerVirtualWorld(client);
@@ -252,7 +256,7 @@ function moveHouseEntranceCommand(command, params, client) {
// ---------------------------------------------------------------------------
function moveHouseExitCommand(command, params, client) {
let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)));
let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house;
getHouseData(houseId).entrancePosition = getPlayerPosition(client);
getHouseData(houseId).entranceDimension = getPlayerVirtualWorld(client);
@@ -270,7 +274,7 @@ function moveHouseExitCommand(command, params, client) {
// ---------------------------------------------------------------------------
function deleteHouseCommand(command, params, client) {
let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)));
let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house;
if(!getHouseData(houseId)) {
messagePlayerError("House not found!");
@@ -353,11 +357,12 @@ function getHouseDataFromDatabaseId(databaseId) {
// ---------------------------------------------------------------------------
function getClosestHouseEntrance(position) {
let houses = getServerData().houses;
let closest = 0;
let closest = getServerData().houses[0].locations[0];
for(let i in houses) {
if(getDistance(houses[i].entrancePosition, position) <= getDistance(houses[closest].entrancePosition, position)) {
closest = i;
for(let j in getServerData().houses[i].locations) {
if(getDistance(position, houses[i].locations[j].entrancePosition) <= getDistance(position, closest.entrancePosition)) {
closest = getServerData().houses[i].locations[j];
}
}
}
return closest;
@@ -566,7 +571,7 @@ function getHouseOwnerTypeText(ownerType) {
// ---------------------------------------------------------------------------
function getHouseInfoCommand(command, params, client) {
let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client));
let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house;
if(!areParamsEmpty(params)) {
houseId = toInteger(params);