diff --git a/scripts/server/business.js b/scripts/server/business.js index 8839aa69..91ce9b3e 100644 --- a/scripts/server/business.js +++ b/scripts/server/business.js @@ -131,7 +131,6 @@ function createBusinessLocationCommand(command, params, client) { } let locationType = toString(splitParams[0]); - let businessId = (isPlayerInAnyBusiness(splitParams[1])) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business; if(!areParamsEmpty(params)) { businessId = getBusinessFromParams(params); @@ -174,7 +173,6 @@ function createBusiness(name, entrancePosition, exitPosition, entrancePickupMode // =========================================================================== function deleteBusinessCommand(command, params, client) { - let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business; if(!areParamsEmpty(params)) { businessId = getBusinessFromParams(params); @@ -202,7 +200,6 @@ function deleteBusinessLocationCommand(command, params, client) { function setBusinessNameCommand(command, params, client) { let newBusinessName = toString(params); - let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business; if(!getBusinessData(businessId)) { messagePlayerError(client, "Business not found!"); @@ -219,7 +216,6 @@ function setBusinessNameCommand(command, params, client) { function setBusinessOwnerCommand(command, params, client) { let newBusinessOwner = getPlayerFromParams(params); - let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business; if(!newBusinessOwner) { messagePlayerError(client, "Player not found!"); @@ -240,7 +236,6 @@ function setBusinessOwnerCommand(command, params, client) { function setBusinessClanCommand(command, params, client) { let clanId = getClanFromParams(params); - let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business; if(!getBusinessData(businessId)) { messagePlayerError(client, "Business not found!"); @@ -260,7 +255,6 @@ function setBusinessClanCommand(command, params, client) { // =========================================================================== function setBusinessJobCommand(command, params, client) { - let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business; if(!areParamsEmpty(params)) { businessId = getBusinessFromParams(params); @@ -291,7 +285,6 @@ function setBusinessJobCommand(command, params, client) { // =========================================================================== function setBusinessPublicCommand(command, params, client) { - let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business; if(!areParamsEmpty(params)) { businessId = getBusinessFromParams(params); @@ -310,7 +303,6 @@ function setBusinessPublicCommand(command, params, client) { // =========================================================================== function lockBusinessCommand(command, params, client) { - let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business; if(!areParamsEmpty(params)) { businessId = getBusinessFromParams(params); @@ -489,10 +481,6 @@ function setBusinessBlipCommand(command, params, client) { getBusinessData(businessId).entranceBlipModel = toInteger(typeParam); } - deleteBusinessLocationEntranceBlip(businessId, closestEntrance.index); - deleteBusinessLocationExitBlip(businessId, closestEntrance.index); - createBusinessLocationEntranceBlip(businessId, closestEntrance.index); - createBusinessLocationExitBlip(businessId, closestEntrance.index); messageAdmins(`${getInlineChatColourByName("lightGrey")}${getPlayerName(client)} ${getInlineChatColourByName("white")}set business ${getInlineChatColourByType("businessBlue")}${getBusinessData(businessId).name} ${getInlineChatColourByName("white")}blip display to ${getInlineChatColourByName("lightGrey")}${toLowerCase(typeParam)}`); } @@ -726,7 +714,6 @@ function orderItemForBusiness(businessId, itemType, amount) { // =========================================================================== function viewBusinessTillAmountCommand(command, params, client) { - let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business; if(!areParamsEmpty(params)) { businessId = getBusinessFromParams(params); @@ -772,7 +759,6 @@ function buyBusinessCommand(command, params, client) { // =========================================================================== function moveBusinessEntranceCommand(command, params, client) { - let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business; if(!areParamsEmpty(params)) { businessId = getBusinessFromParams(params); @@ -799,7 +785,6 @@ function moveBusinessEntranceCommand(command, params, client) { // =========================================================================== function moveBusinessExitCommand(command, params, client) { - let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)).business; if(!areParamsEmpty(params)) { businessId = getBusinessFromParams(params); @@ -836,12 +821,9 @@ function getBusinessDataFromDatabaseId(databaseId) { // =========================================================================== function getClosestBusinessEntrance(position) { - let closest = getServerData().businesses[0].locations[0]; + let closest = 0; for(let i in getServerData().businesses) { - 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]; - } + if(getDistance(position, getServerData().businesses[i].entrancePosition) <= getDistance(position, getServerData().businesses[closest].entrancePosition)) { } } return closest; @@ -987,10 +969,8 @@ function saveBusinessToDatabase(businessId) { function createAllBusinessPickups() { for(let i in getServerData().businesses) { - for(let j in getServerData().businesses[i].locations) { - createBusinessLocationEntrancePickup(i, j); - createBusinessLocationExitPickup(i, j); - } + createBusinessEntrancePickup(i); + createBusinessExitPickup(i); } } @@ -998,92 +978,91 @@ function createAllBusinessPickups() { function createAllBusinessBlips() { for(let i in getServerData().businesses) { - for(let j in getServerData().businesses[i].locations) { - createBusinessLocationEntranceBlip(i, j); - createBusinessLocationExitBlip(i, j); - } + createBusinessEntranceBlip(i); + createBusinessExitBlip(i); } } // =========================================================================== -function createBusinessLocationEntrancePickup(businessId, locationId) { - if(getBusinessData(businessId).locations[locationId].entrancePickupModel != -1) { +function createBusinessEntrancePickup(businessId) { + if(getBusinessData(businessId).entrancePickupModel != -1) { let pickupModelId = getGameConfig().pickupModels[getServerGame()].business; if(getServerData().businesses[businessId].locations[locationId].entrancePickupModel != 0) { pickupModelId = getBusinessData(businessId).locations[locationId].entrancePickupModel; + if(getServerData().businesses[businessId].entrancePickupModel != 0) { + pickupModelId = getBusinessData(businessId).entrancePickupModel; } getBusinessData(businessId).locations[locationId].entrancePickup = gta.createPickup(pickupModelId, getBusinessData(businessId).locations[locationId].entrancePosition); getBusinessData(businessId).locations[locationId].entrancePickup.onAllDimensions = false; - getBusinessData(businessId).locations[locationId].entrancePickup.dimension = getBusinessData(businessId).locations[locationId].entranceDimension; - getBusinessData(businessId).locations[locationId].entrancePickup.setData("ag.owner.type", VRR_PICKUP_BUSINESS_ENTRANCE, false); - getBusinessData(businessId).locations[locationId].entrancePickup.setData("ag.owner.id", businessId, false); - getBusinessData(businessId).locations[locationId].entrancePickup.setData("ag.label.type", VRR_LABEL_BUSINESS, true); - //addToWorld(getBusinessData(businessId).locations[locationId].entrancePickup); + getBusinessData(businessId).entrancePickup = gta.createPickup(pickupModelId, getBusinessData(businessId).entrancePosition); + getBusinessData(businessId).entrancePickup.onAllDimensions = false; + getBusinessData(businessId).entrancePickup.dimension = getBusinessData(businessId).entranceDimension; + updateBusinessPickupLabelData(businessId); + addToWorld(getBusinessData(businessId).entrancePickup); } } // =========================================================================== -function createBusinessLocationEntranceBlip(businessId, locationId) { - if(getBusinessData(businessId).locations[locationId].entranceBlipModel != -1) { +function createBusinessEntranceBlip(businessId) { + if(getBusinessData(businessId).entranceBlipModel != -1) { let blipModelId = getGameConfig().blipSprites[getServerGame()].business; if(getServerData().businesses[businessId].entranceBlipModel != 0) { - blipModelId = getBusinessData(businessId).locations[locationId].entranceBlipModel; + blipModelId = getBusinessData(businessId).entranceBlipModel; } - getBusinessData(businessId).locations[locationId].entranceBlip = gta.createBlip(getBusinessData(businessId).locations[locationId].entrancePosition, blipModelId, 1, getColourByName("businessBlue")); - getBusinessData(businessId).locations[locationId].entranceBlip.onAllDimensions = false; - getBusinessData(businessId).locations[locationId].entranceBlip.dimension = getBusinessData(businessId).locations[locationId].entranceDimension; - getBusinessData(businessId).locations[locationId].entranceBlip.setData("ag.owner.type", VRR_BLIP_BUSINESS_ENTRANCE, false); - getBusinessData(businessId).locations[locationId].entranceBlip.setData("ag.owner.id", businessId, false); - //addToWorld(getBusinessData(businessId).locations[locationId].entranceBlip); + getBusinessData(businessId).entranceBlip = gta.createBlip(blipModelId, getBusinessData(businessId).entrancePosition, 1, getColourByName("businessBlue")); + getBusinessData(businessId).entranceBlip.onAllDimensions = false; + getBusinessData(businessId).entranceBlip.dimension = getBusinessData(businessId).entranceDimension; + //getBusinessData(businessId).entranceBlip.interior = getBusinessData(businessId).entranceInterior; + setEntityData(getBusinessData(businessId).entranceBlip, "ag.owner.type", AG_BLIP_BUSINESS_ENTRANCE, false); + setEntityData(getBusinessData(businessId).entranceBlip, "ag.owner.id", businessId, false); + addToWorld(getBusinessData(businessId).entranceBlip); } } // =========================================================================== -function createBusinessLocationExitPickup(businessId, locationId) { +function createBusinessExitPickup(businessId) { if(getBusinessData(businessId).hasInterior) { - if(getBusinessData(businessId).locations[locationId].exitPickupModel != -1) { + if(getBusinessData(businessId).exitPickupModel != -1) { let pickupModelId = getGameConfig().pickupModels[getServerGame()].exit; - if(getServerData().businesses[businessId].locations[locationId].exitPickupModel != 0) { - pickupModelId = getBusinessData(businessId).locations[locationId].exitPickupModel; + if(getServerData().businesses[businessId].exitPickupModel != 0) { + pickupModelId = getBusinessData(businessId).exitPickupModel; } - getBusinessData(businessId).locations[locationId].exitPickup = gta.createPickup(pickupModelId, getBusinessData(businessId).locations[locationId].exitPosition); - getBusinessData(businessId).locations[locationId].exitPickup.onAllDimensions = false; - getBusinessData(businessId).locations[locationId].exitPickup.dimension = getBusinessData(businessId).locations[locationId].exitDimension; - getBusinessData(businessId).locations[locationId].exitPickup.setData("ag.owner.type", VRR_PICKUP_BUSINESS_EXIT, false); - getBusinessData(businessId).locations[locationId].exitPickup.setData("ag.owner.id", businessId, false); - getBusinessData(businessId).locations[locationId].exitPickup.setData("ag.label.type", VRR_LABEL_EXIT, true); - //addToWorld(getBusinessData(businessId).locations[locationId].exitPickup); + getBusinessData(businessId).exitPickup = gta.createPickup(pickupModelId, getBusinessData(businessId).exitPosition); + getBusinessData(businessId).exitPickup.onAllDimensions = false; + getBusinessData(businessId).exitPickup.dimension = getBusinessData(businessId).exitDimension; + //getBusinessData(businessId).exitPickup.interior = getBusinessData(businessId).exitInterior; + addToWorld(getBusinessData(businessId).exitPickup); } } } // =========================================================================== -function createBusinessLocationExitBlip(businessId, locationId) { +function createBusinessExitBlip(businessId) { if(getBusinessData(businessId).hasInterior) { - if(getBusinessData(businessId).locations[locationId].exitBlipModel != -1) { + if(getBusinessData(businessId).exitBlipModel != -1) { let blipModelId = getGameConfig().blipSprites[getServerGame()].business; - if(getServerData().businesses[businessId].locations[locationId].exitBlipModel != 0) { - blipModelId = getBusinessData(businessId).locations[locationId].exitBlipModel; + if(getServerData().businesses[businessId].exitBlipModel != 0) { + blipModelId = getBusinessData(businessId).exitBlipModel; } - getBusinessData(businessId).locations[locationId].exitBlip = gta.createBlip(getBusinessData(businessId).locations[locationId].exitPosition, blipModelId, 1, getColourByName("businessBlue")); - getBusinessData(businessId).locations[locationId].exitBlip.onAllDimensions = false; - getBusinessData(businessId).locations[locationId].exitBlip.dimension = getBusinessData(businessId).locations[locationId].entranceDimension; + getBusinessData(businessId).exitBlip = gta.createBlip(blipModelId, getBusinessData(businessId).exitPosition, 1, getColourByName("businessBlue")); + getBusinessData(businessId).exitBlip.onAllDimensions = false; + getBusinessData(businessId).exitBlip.dimension = getBusinessData(businessId).entranceDimension; //getBusinessData(businessId).exitBlip.interior = getBusinessData(businessId).exitInterior; - getBusinessData(businessId).locations[locationId].exitBlip.setData("ag.owner.type", VRR_BLIP_BUSINESS_EXIT, false); - getBusinessData(businessId).locations[locationId].exitBlip.setData("ag.owner.id", businessId, false); - //addToWorld(getBusinessData(businessId).locations[locationId].exitBlip); + setEntityData(getBusinessData(businessId).exitBlip, "ag.owner.type", AG_BLIP_BUSINESS_EXIT, false); + setEntityData(getBusinessData(businessId).exitBlip, "ag.owner.id", businessId, false); + addToWorld(getBusinessData(businessId).exitBlip); } } } @@ -1101,19 +1080,14 @@ function deleteBusiness(businessId, deletedBy = 0) { if(dbQuery) { freeDatabaseQuery(dbQuery); } - - dbQuery = queryDatabase(dbConnection, `DELETE FROM biz_loc WHERE biz_loc_biz = ${tempBusinessData.databaseId}`); - if(dbQuery) { - freeDatabaseQuery(dbQuery); - } disconnectFromDatabase(dbConnection); } - deleteBusinessEntrancePickups(businessId); - deleteBusinessExitPickups(businessId); + deleteBusinessEntrancePickup(businessId); + deleteBusinessExitPickup(businessId); - deleteBusinessEntranceBlips(businessId); - deleteBusinessExitBlips(businessId); + deleteBusinessEntranceBlip(businessId); + deleteBusinessExitBlip(businessId); removePlayersFromBusiness(businessId); @@ -1193,69 +1167,41 @@ function doesBusinessHaveInterior(businessId) { // =========================================================================== -function deleteBusinessEntrancePickups(businessId) { - for(let i in getServerData().businesses[businessId].locations) { - deleteBusinessLocationEntrancePickup(businessId, i); +function deleteBusinessEntrancePickup(businessId) { + if(getBusinessData(businessId).entrancePickup != null) { + //removeFromWorld(getBusinessData(businessId).entrancePickup); + deleteGameElement(getBusinessData(businessId).entrancePickup); + getBusinessData(businessId).entrancePickup = null; } } // =========================================================================== -function deleteBusinessEntranceBlips(businessId) { - for(let i in getServerData().businesses[businessId].locations) { - deleteBusinessLocationEntranceBlip(businessId, i); +function deleteBusinessExitPickup(businessId) { + if(getBusinessData(businessId).exitPickup != null) { + //removeFromWorld(getBusinessData(businessId).exitPickup); + deleteGameElement(getBusinessData(businessId).exitPickup); + getBusinessData(businessId).exitPickup = null; } } // =========================================================================== -function deleteBusinessExitPickups(businessId) { - for(let i in getServerData().businesses[businessId].locations) { - deleteBusinessLocationExitPickup(businessId, i); +function deleteBusinessEntranceBlip(businessId) { + if(getBusinessData(businessId).entranceBlip != null) { + //removeFromWorld(getBusinessData(businessId).entranceBlip); + deleteGameElement(getBusinessData(businessId).entranceBlip); + getBusinessData(businessId).entranceBlip = null; } } // =========================================================================== -function deleteBusinessExitBlips(businessId) { - for(let i in getServerData().businesses[businessId].locations) { - deleteBusinessLocationExitBlip(businessId, i); - } -} - -// =========================================================================== - -function deleteBusinessLocationEntrancePickup(businessId, locationId) { - if(getBusinessData(businessId).locations[locationId].entrancePickup) { - destroyElement(getBusinessData(businessId).locations[locationId].entrancePickup); - getBusinessData(businessId).locations[locationId].entrancePickup = false; - } -} - -// =========================================================================== - -function deleteBusinessLocationExitPickup(businessId, locationId) { - if(getBusinessData(businessId).locations[locationId].exitPickup) { - destroyElement(getBusinessData(businessId).locations[locationId].exitPickup); - getBusinessData(businessId).locations[locationId].exitPickup = false; - } -} - -// =========================================================================== - -function deleteBusinessLocationEntranceBlip(businessId, locationId) { - if(getBusinessData(businessId).locations[locationId].entranceBlip) { - destroyElement(getBusinessData(businessId).locations[locationId].entranceBlip); - getBusinessData(businessId).locations[locationId].entranceBlip = false; - } -} - -// =========================================================================== - -function deleteBusinessLocationExitBlip(businessId, locationId) { - if(getBusinessData(businessId).locations[locationId].exitBlip) { - destroyElement(getBusinessData(businessId).locations[locationId].exitBlip); - getBusinessData(businessId).locations[locationId].exitBlip = false; +function deleteBusinessExitBlip(businessId) { + if(getBusinessData(businessId).exitBlip != null) { + //removeFromWorld(getBusinessData(businessId).exitBlip); + deleteGameElement(getBusinessData(businessId).exitBlip); + getBusinessData(businessId).exitBlip = null; } } diff --git a/scripts/server/class.js b/scripts/server/class.js index 91f141c1..55d9e248 100644 --- a/scripts/server/class.js +++ b/scripts/server/class.js @@ -512,27 +512,16 @@ function initClassTable() { businessLocationData: class { constructor(dbAssoc) { this.databaseId = 0; - this.name = "Unnamed"; + this.name = ""; + this.type = 0; this.business = 0; this.enabled = false; + this.index = -1; + this.needsSaved = false; - this.entrancePosition = false; - this.entranceRotation = 0.0; - this.entranceInterior = 0; - this.entranceDimension = 0; - this.entrancePickupModel = -1; - this.entranceBlipModel = -1; - this.entrancePickup = null; - this.entranceBlip = null; - - this.exitPosition = false; - this.exitRotation = 0.0; - this.exitInterior = 0; - this.exitDimension = -1; - this.exitPickupModel = -1; - this.exitBlipModel = -1; - this.exitPickup = null; - this.exitBlip = null; + this.position = toVector3(0.0, 0.0, 0.0); + this.interior = 0; + this.dimension = 0; if(dbAssoc) { this.databaseId = toInteger(dbAssoc("biz_loc_id")); @@ -540,68 +529,11 @@ function initClassTable() { this.type = toInteger(dbAssoc("biz_loc_type")); this.business = toInteger(dbAssoc("biz_loc_biz")); this.enabled = intToBool(toInteger(dbAssoc("biz_loc_enabled"))); + this.index = -1; - this.entrancePosition = toVector3(toFloat(dbAssoc["biz_loc_entrance_pos_x"]), toFloat(dbAssoc["biz_loc_entrance_pos_y"]), toFloat(dbAssoc["biz_loc_entrance_pos_z"])); - this.entranceRotation = toFloat(dbAssoc["biz_loc_entrance_rot_z"]); - this.entranceInterior = toInteger(dbAssoc["biz_loc_entrance_int"]); - this.entranceDimension = toInteger(dbAssoc["biz_loc_entrance_vw"]); - this.entrancePickupModel = toInteger(dbAssoc["biz_loc_entrance_pickup"]); - this.entranceBlipModel = toInteger(dbAssoc["biz_loc_entrance_blip"]); - - this.exitPosition = toVector3(toFloat(dbAssoc["biz_loc_exit_pos_x"]), toFloat(dbAssoc["biz_loc_exit_pos_y"]), toFloat(dbAssoc["biz_loc_exit_pos_z"])); - this.exitRotation = toFloat(dbAssoc["biz_loc_exit_rot_z"]); - this.exitInterior = toInteger(dbAssoc["biz_loc_exit_int"]); - this.exitDimension = toInteger(dbAssoc["biz_loc_exit_vw"]); - this.exitPickupModel = toInteger(dbAssoc["biz_loc_exit_pickup"]); - this.exitBlipModel = toInteger(dbAssoc["biz_loc_exit_blip"]); - } - } - }, - houseLocationData: class { - constructor(dbAssoc) { - this.databaseId = 0; - this.name = "Unnamed"; - this.house = 0; - this.enabled = false; - - this.entrancePosition = false; - this.entranceRotation = 0.0; - this.entranceInterior = 0; - this.entranceDimension = 0; - this.entrancePickupModel = -1; - this.entranceBlipModel = -1; - this.entrancePickup = null; - this.entranceBlip = null; - - this.exitPosition = false; - this.exitRotation = 0.0; - this.exitInterior = 0; - this.exitDimension = -1; - this.exitPickupModel = -1; - this.exitBlipModel = -1; - this.exitPickup = null; - this.exitBlip = null; - - if(dbAssoc) { - this.databaseId = toInteger(dbAssoc("house_loc_id")); - this.name = toString(dbAssoc("house_loc_name")); - this.type = toInteger(dbAssoc("house_loc_type")); - this.business = toInteger(dbAssoc("house_loc_biz")); - this.enabled = intToBool(toInteger(dbAssoc("house_loc_enabled"))); - - this.entrancePosition = toVector3(toFloat(dbAssoc["house_loc_entrance_pos_x"]), toFloat(dbAssoc["house_loc_entrance_pos_y"]), toFloat(dbAssoc["house_loc_entrance_pos_z"])); - this.entranceRotation = toFloat(dbAssoc["house_loc_entrance_rot_z"]); - this.entranceInterior = toInteger(dbAssoc["house_loc_entrance_int"]); - this.entranceDimension = toInteger(dbAssoc["house_loc_entrance_vw"]); - this.entrancePickupModel = toInteger(dbAssoc["house_loc_entrance_pickup"]); - this.entranceBlipModel = toInteger(dbAssoc["house_loc_entrance_blip"]); - - this.exitPosition = toVector3(toFloat(dbAssoc["house_loc_exit_pos_x"]), toFloat(dbAssoc["house_loc_exit_pos_y"]), toFloat(dbAssoc["house_loc_exit_pos_z"])); - this.exitRotation = toFloat(dbAssoc["house_loc_exit_rot_z"]); - this.exitInterior = toInteger(dbAssoc["house_loc_exit_int"]); - this.exitDimension = toInteger(dbAssoc["house_loc_exit_vw"]); - this.exitPickupModel = toInteger(dbAssoc["house_loc_exit_pickup"]); - this.exitBlipModel = toInteger(dbAssoc["house_loc_exit_blip"]); + this.position = toVector3(toFloat(dbAssoc["biz_loc_pos_x"]), toFloat(dbAssoc["biz_loc_pos_y"]), toFloat(dbAssoc["biz_loc_pos_z"])); + this.interior = toInteger(dbAssoc["biz_loc_int"]); + this.dimension = toInteger(dbAssoc["biz_loc_vw"]); } } }, @@ -645,6 +577,8 @@ function initClassTable() { this.ownerType = toInteger(dbAssoc["house_owner_type"]); this.ownerId = toInteger(dbAssoc["house_owner_id"]); this.buyPrice = toInteger(dbAssoc["house_buy_price"]); + this.rentPrice = toInteger(dbAssoc["house_rent_price"]); + this.renter = toInteger(dbAssoc["house_renter"]); this.locked = intToBool(toInteger(dbAssoc["house_locked"])); this.hasInterior = intToBool(toInteger(dbAssoc["house_has_interior"])); @@ -977,6 +911,7 @@ function initClassTable() { this.whiteListEnabled = dbAssoc["job_wl"]; this.blackListEnabled = dbAssoc["job_bl"]; this.walkieTalkieFrequency = dbAssoc["job_walkietalkiefreq"]; + this.equipment = []; this.uniforms = []; this.locations = []; diff --git a/scripts/server/house.js b/scripts/server/house.js index f7d12131..9b3796da 100644 --- a/scripts/server/house.js +++ b/scripts/server/house.js @@ -38,7 +38,6 @@ function loadHousesFromDatabase() { if(dbQuery.numRows > 0) { while(dbAssoc = fetchQueryAssoc(dbQuery)) { let tempHouseData = new serverClasses.houseData(dbAssoc); - tempHouseData.locations = loadHouseLocationsFromDatabase(tempHouseData.databaseId); tempHouses.push(tempHouseData); logToConsole(LOG_VERBOSE, `[VRR.House]: House '${tempHouseData.description}' (ID ${tempHouseData.databaseId}) loaded!`); } @@ -53,39 +52,6 @@ function loadHousesFromDatabase() { // =========================================================================== -function loadHouseLocationsFromDatabase(houseId) { - if(!getHouseData(houseId)) { - return false; - } - - console.log(`[VRR.House]: Loading locations for house '${getHouseData(houseId).description}' from database ...`); - - let tempHouseLocations = []; - let dbConnection = connectToDatabase(); - let dbQuery = null; - let dbAssoc; - - if(dbConnection) { - dbQuery = queryDatabase(dbConnection, `SELECT * FROM house_loc WHERE house_loc_house=${houseId}`); - if(dbQuery) { - if(dbQuery.numRows > 0) { - while(dbAssoc = fetchQueryAssoc(dbQuery)) { - let tempHouseLocationData = new serverClasses.houseLocationData(dbAssoc); - tempHouseLocations.push(tempHouseLocationData); - console.log(`[VRR.House]: Location for house '${getHouseData(houseId).name}' loaded from database successfully!`); - } - } - freeDatabaseQuery(dbQuery); - } - disconnectFromDatabase(dbConnection); - } - - console.log(`[VRR.House]: ${tempHouseLocations.length} locations for house '${getHouseData(houseId).name}' loaded from database successfully`); - return tempHouseLocations; -} - -// --------------------------------------------------------------------------- - function createHouseCommand(command, params, client) { let tempHouseData = createHouse(params, getPlayerPosition(client), toVector3(0.0, 0.0, 0.0), getGameConfig().pickupModels[getServerGame()].house, getGameConfig().blipSprites[getServerGame()].house, getPlayerInterior(client), getPlayerDimension(client)); let houseId = getServerData().houses.push(tempHouseData); @@ -102,6 +68,7 @@ function createHouseCommand(command, params, client) { function lockUnlockHouseCommand(command, params, client) { let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client))); + if(!getHouseData(houseId)) { messagePlayerError("House not found!"); return false; @@ -123,7 +90,7 @@ function lockUnlockHouseCommand(command, params, client) { function setHouseDescriptionCommand(command, params, client) { let newHouseDescription = toString(params); - let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house; + let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client))); if(!getHouseData(houseId)) { messagePlayerError("House not found!"); @@ -146,7 +113,7 @@ function setHouseDescriptionCommand(command, params, client) { function setHouseOwnerCommand(command, params, client) { let newHouseOwner = getPlayerFromParams(params); - let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house; + let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client))); if(!newHouseOwner) { messagePlayerError("Player not found!"); @@ -166,7 +133,7 @@ function setHouseOwnerCommand(command, params, client) { // =========================================================================== function setHouseClanCommand(command, params, client) { - let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house; + let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client))); let clan = getClanFromParams(params); @@ -189,36 +156,34 @@ function setHouseClanCommand(command, params, client) { function setHousePickupCommand(command, params, client) { let typeParam = params || "house"; - let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house; + let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client))); 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: ${getInlineChatColourByName("lightGrey")}${Object.keys(getGameConfig().pickupModels[getServerGame()]).join(", ")}`); + messagePlayerInfo(client, `Pickup Types: [#AAAAAA]${Object.keys(getGameConfig().pickupModels[getServerGame()]).join(", ")}`) return false; } - entrancePickupModel = getGameConfig().pickupModels[getServerGame()][typeParam]; + getHouseData(houseId).entrancePickupModel = getGameConfig().pickupModels[getServerGame()][typeParam]; } else { - entrancePickupModel = toInteger(typeParam); + getHouseData(houseId).entrancePickupModel = toInteger(typeParam); } - 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); + if(getHouseData(houseId).entrancePickupModel != -1) { + if(getHouseData(houseId).entrancePickup != null) { + deleteGameElement(getHouseData(houseId).entrancePickup); } + + createHouseEntrancePickup(houseId); } - messageAdmins(`${getInlineChatColourByName("lightGrey")}${getPlayerName(client)} ${getInlineChatColourByName("white")}set house ${getInlineChatColourByType("houseGreen")}${getHouseData(houseId).description} ${getInlineChatColourByName("white")}pickup display to ${getInlineChatColourByName("lightGrey")}${entrancePickupModel}`); + messageAdmins(`[#AAAAAA]${client.name} [#FFFFFF]set house [#11CC11]${getHouseData(houseId).description} [#FFFFFF]pickup display to [#AAAAAA]${toLowerCase(typeParam)}`); } // =========================================================================== @@ -249,29 +214,58 @@ function setHouseInteriorTypeCommand(command, params, client) { messagePlayerInfo(client, `Interior Types: ${getInlineChatColourByName("lightGrey")}${Object.keys(getGameConfig().interiorTemplates[getServerGame()]).join(", ")}`) return false; } - - deleteHouseEntrancePickup(houseId); - deleteHouseExitPickup(houseId); - - getHouseData(houseId).locations = []; - - tempHouseLocation.exitPosition = getGameConfig().interiorTemplates[getServerGame()][typeParam].exitPosition; - tempHouseLocation.exitInterior = getGameConfig().interiorTemplates[getServerGame()][typeParam].exitInterior; - tempHouseLocation.exitDimension = getHouseData(houseId).databaseId+getGlobalConfig().houseDimensionStart; + getHouseData(houseId).exitPosition = getHouseData(houseId).exitPosition; + getHouseData(houseId).exitInterior = getHouseData(houseId).exitInterior; + getHouseData(houseId).exitDimension = getHouseData(houseId).databaseId+getGlobalConfig().houseDimensionStart; getHouseData(houseId).hasInterior = true; - - getHouseData(houseId).locations.push(tempHouseLocation); - createHouseEntrancePickups(houseId); - createHouseExitPickups(houseId); } - messageAdmins(`${getInlineChatColourByName("lightGrey")}${getPlayerName(client)} ${getInlineChatColourByName("white")}set house ${getInlineChatColourByType("houseGreen")}${getHouseData(houseId).description} ${getInlineChatColourByName("white")}interior type to ${getInlineChatColourByName("lightGrey")}${toLowerCase(typeParam)}`); + deleteHouseEntrancePickup(houseId); + deleteHouseExitPickup(houseId); + createHouseEntrancePickup(houseId); + createHouseExitPickup(houseId); + + messageAdmins(`[#AAAAAA]${client.name} [#FFFFFF]set house [#11CC11]${getHouseData(houseId).description} [#FFFFFF]interior type to [#AAAAAA]${toLowerCase(typeParam)}`); +} + +// =========================================================================== + +function setHouseBlipCommand(command, params, client) { + let typeParam = params || "house"; + let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client))); + + if(!getHouseData(houseId)) { + messagePlayerError(client, "House not found!"); + return false; + } + + if(isNaN(typeParam)) { + if(isNull(getGameConfig().blipSprites[getServerGame()][typeParam])) { + messagePlayerError(client, "Invalid house type! Use a house type name or a blip image ID"); + messagePlayerInfo(client, `Pickup Types: [#AAAAAA]${Object.keys(getGameConfig().blipSprites[getServerGame()]).join(", ")}`) + return false; + } + + getHouseData(houseId).entranceBlipModel = getGameConfig().blipSprites[getServerGame()][typeParam]; + } else { + getHouseData(houseId).entranceBlipModel = toInteger(typeParam); + } + + if(getHouseData(houseId).entranceBlipModel != -1) { + if(getHouseData(houseId).entranceBlip != null) { + deleteGameElement(getHouseData(houseId).entranceBlip); + } + + createHouseEntranceBlip(houseId); + } + + messageAdmins(`[#AAAAAA]${client.name} [#FFFFFF]set house [#11CC11]${getHouseData(houseId).description} [#FFFFFF]blip display to [#AAAAAA]${toLowerCase(typeParam)}`); } // =========================================================================== function moveHouseEntranceCommand(command, params, client) { - let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house; + let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client))); if(!getHouseData(houseId)) { messagePlayer(client, "You need to be near or inside a house!"); @@ -293,7 +287,7 @@ function moveHouseEntranceCommand(command, params, client) { // =========================================================================== function moveHouseExitCommand(command, params, client) { - let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house; + let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client))); if(!getHouseData(houseId)) { messagePlayer(client, "You need to be near or inside a house!"); @@ -317,7 +311,7 @@ function moveHouseExitCommand(command, params, client) { // =========================================================================== function deleteHouseCommand(command, params, client) { - let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house; + let houseId = toInteger((isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client))); if(!getHouseData(houseId)) { messagePlayerError("House not found!"); @@ -400,12 +394,11 @@ function getHouseDataFromDatabaseId(databaseId) { // =========================================================================== function getClosestHouseEntrance(position) { - let closest = getServerData().houses[0].locations[0]; - for(let i in getServerData().houses) { - 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]; - } + let houses = getServerData().houses; + let closest = 0; + for(let i in houses) { + if(getDistance(houses[i].entrancePosition, position) <= getDistance(houses[closest].entrancePosition, position)) { + closest = i; } } return closest; @@ -487,36 +480,10 @@ function saveHouseToDatabase(houseId) { // =========================================================================== -function saveHouseLocationToDatabase(houseId, locationId) { - let tempHouseLocationData = getHouseData(houseId).locations[locationId]; - - console.log(`[VRR.House]: Saving house location ${tempHouseLocationData.databaseId} to database ...`); - let dbConnection = connectToDatabase(); - if(dbConnection) { - if(tempHouseLocationData.databaseId == 0) { - let dbQueryString = `INSERT INTO house_loc (house_loc_house, house_loc_locked, house_loc_entrance_pos_x, house_loc_entrance_pos_y, house_loc_entrance_pos_z, house_loc_entrance_rot_z, house_loc_entrance_int, house_loc_entrance_vw, house_loc_exit_pos_x, house_loc_exit_pos_y, house_loc_exit_pos_z, house_loc_exit_rot_z, house_loc_exit_int, house_loc_exit_vw) VALUES (${tempHouseLocationData.databaseId}, ${boolToInt(tempHouseLocationData.locked)}, ${tempHouseLocationData.entrancePosition.x}, ${tempHouseLocationData.entrancePosition.y}, ${tempHouseLocationData.entrancePosition.z}, ${tempHouseLocationData.entranceRotation}, ${tempHouseLocationData.entranceInterior}, ${tempHouseLocationData.entranceDimension}, ${tempHouseLocationData.exitPosition.x}, ${tempHouseLocationData.exitPosition.y}, ${tempHouseLocationData.exitPosition.z}, ${tempHouseLocationData.exitRotation}, ${tempHouseLocationData.exitInterior}, ${tempHouseLocationData.exitDimension})`; - queryDatabase(dbConnection, dbQueryString); - tempHouseLocationData.databaseId = getDatabaseInsertId(dbConnection); - } else { - let dbQueryString = `UPDATE house_loc SET house_loc_house=${getHouseData(houseId).databaseId}', house_loc_locked=${tempHouseLocationData.locked}, house_loc_entrance_pos_x=${tempHouseLocationData.entrancePosition.x}, house_loc_entrance_pos_y=${tempHouseLocationData.entrancePosition.y}, house_loc_entrance_pos_z=${tempHouseLocationData.entrancePosition.z}, house_loc_entrance_rot_z=${tempHouseLocationData.entranceRotation}, house_loc_entrance_int=${tempHouseLocationData.entranceInterior}, house_loc_entrance_vw=${tempHouseLocationData.entranceDimension}, house_loc_exit_pos_x=${tempHouseLocationData.exitPosition.x}, house_loc_exit_pos_y=${tempHouseLocationData.exitPosition.y}, house_loc_exit_pos_z=${tempHouseLocationData.exitPosition.z}, house_loc_exit_rot_z=${tempHouseData.exitRotation}, house_loc_exit_int=${tempHouseLocationData.exitInterior}, house_loc_exit_vw=${tempHouseLocationData.exitDimension} WHERE house_loc_id=${tempHouseLocationData.databaseId}`; - queryDatabase(dbConnection, dbQueryString); - } - disconnectFromDatabase(dbConnection); - return true; - } - console.log(`[VRR.house]: Saved house location ${tempHouseLocationData.databaseId} to database!`); - - return false; -} - -// --------------------------------------------------------------------------- - function createAllHousePickups() { for(let i in getServerData().houses) { - for(let j in getServerData().houses[i].locations) { - createHouseLocationEntrancePickup(i, j); - createHouseLocationExitPickup(i, j); - } + createHouseEntrancePickup(i); + createHouseExitPickup(i); } } @@ -524,96 +491,94 @@ function createAllHousePickups() { function createAllHouseBlips() { for(let i in getServerData().houses) { - for(let j in getServerData().houses[i].locations) { - createHouseLocationEntranceBlip(i, j); - createHouseLocationExitBlip(i, j); - } + createHouseEntranceBlip(i); + createHouseExitBlip(i); } } // =========================================================================== -function createHouseEntrancePickup(houseId, locationId) { - if(getHouseData(houseId).locations[locationId].entrancePickupModel != -1) { +function createHouseEntrancePickup(houseId) { + if(getHouseData(houseId).entrancePickupModel != -1) { let pickupModelId = getGameConfig().pickupModels[getServerGame()].house; if(getServerData().houses[houseId].entrancePickupModel != 0) { - pickupModelId = getHouseData(houseId).locations[locationId].entrancePickupModel; + pickupModelId = getHouseData(houseId).entrancePickupModel; } - getHouseData(houseId).locations[locationId].entrancePickup = gta.createPickup(pickupModelId, getHouseData(houseId).locations[locationId].entrancePosition); - getHouseData(houseId).locations[locationId].entrancePickup.onAllDimensions = false; - getHouseData(houseId).locations[locationId].entrancePickup.dimension = getHouseData(houseId).locations[locationId].entranceDimension; - getHouseData(houseId).locations[locationId].entrancePickup.setData("ag.owner.type", VRR_PICKUP_HOUSE_ENTRANCE, false); - getHouseData(houseId).locations[locationId].entrancePickup.setData("ag.owner.id", houseId, false); - getHouseData(houseId).locations[locationId].entrancePickup.setData("ag.label.type", VRR_LABEL_HOUSE, true); - getHouseData(houseId).locations[locationId].entrancePickup.setData("ag.label.name", getHouseData(houseId).description, true); - getHouseData(houseId).locations[locationId].entrancePickup.setData("ag.label.locked", getHouseData(houseId).locked, true); + getHouseData(houseId).entrancePickup = gta.createPickup(pickupModelId, getHouseData(houseId).entrancePosition); + getHouseData(houseId).entrancePickup.onAllDimensions = false; + getHouseData(houseId).entrancePickup.dimension = getHouseData(houseId).entranceDimension; + setEntityData(getHouseData(houseId).entrancePickup, "ag.owner.type", AG_PICKUP_HOUSE_ENTRANCE, false); + setEntityData(getHouseData(houseId).entrancePickup, "ag.owner.id", houseId, false); + setEntityData(getHouseData(houseId).entrancePickup, "ag.label.type", AG_LABEL_HOUSE, true); + setEntityData(getHouseData(houseId).entrancePickup, "ag.label.name", getHouseData(houseId).description, true); + setEntityData(getHouseData(houseId).entrancePickup, "ag.label.locked", getHouseData(houseId).locked, true); if(getHouseData(houseId).buyPrice > 0) { - getHouseData(houseId).locations[locationId].entrancePickup.setData("ag.label.price", getHouseData(houseId).buyPrice, true); + setEntityData(getHouseData(houseId).entrancePickup, "ag.label.price", getHouseData(houseId).buyPrice, true); } - addToWorld(getHouseData(houseId).locations[locationId].entrancePickup); + addToWorld(getHouseData(houseId).entrancePickup); } } // =========================================================================== -function createHouseEntranceBlip(houseId, locationId) { - if(getHouseData(houseId).locations[locationId].entranceBlipModel != -1) { +function createHouseEntranceBlip(houseId) { + if(getHouseData(houseId).entranceBlipModel != -1) { let blipModelId = getGameConfig().blipSprites[getServerGame()].house; - if(getServerData().houses[houseId].locations[locationId].entranceBlipModel != 0) { - blipModelId = getHouseData(houseId).locations[locationId].entranceBlipModel; + if(getServerData().houses[houseId].entranceBlipModel != 0) { + blipModelId = getHouseData(houseId).entranceBlipModel; } - getHouseData(houseId).locations[locationId].entranceBlip = gta.createBlip(getHouseData(houseId).locations[locationId].entrancePosition, blipModelId, 1, getColourByName("houseGreen")); - getHouseData(houseId).locations[locationId].entranceBlip.onAllDimensions = false; - getHouseData(houseId).locations[locationId].entranceBlip.dimension = getHouseData(houseId).locations[locationId].entranceDimension; - getHouseData(houseId).locations[locationId].entranceBlip.setData("ag.owner.type", VRR_BLIP_HOUSE_ENTRANCE, false); - getHouseData(houseId).locations[locationId].entranceBlip.setData("ag.owner.id", houseId, false); - addToWorld(getHouseData(houseId).locations[locationId].entranceBlip); + getHouseData(houseId).entranceBlip = gta.createBlip(getHouseData(houseId).entrancePosition, blipModelId, 1, getColourByName("houseGreen")); + getHouseData(houseId).entranceBlip.onAllDimensions = false; + getHouseData(houseId).entranceBlip.dimension = getHouseData(houseId).entranceDimension; + setEntityData(getHouseData(houseId).entranceBlip, "ag.owner.type", AG_BLIP_HOUSE_ENTRANCE, false); + setEntityData(getHouseData(houseId).entranceBlip, "ag.owner.id", houseId, false); + addToWorld(getHouseData(houseId).entranceBlip); } } // =========================================================================== -function createHouseExitPickup(houseId, locationId) { +function createHouseExitPickup(houseId) { if(getHouseData(houseId).hasInterior) { - if(getHouseData(houseId).locations[locationId].exitPickupModel != -1) { + if(getHouseData(houseId).exitPickupModel != -1) { let pickupModelId = getGameConfig().pickupModels[getServerGame()].exit; - if(getServerData().houses[houseId].locations[locationId].exitPickupModel != 0) { - pickupModelId = getHouseData(houseId).locations[locationId].exitPickupModel; + if(getServerData().houses[houseId].exitPickupModel != 0) { + pickupModelId = getHouseData(houseId).exitPickupModel; } - getHouseData(houseId).locations[locationId].exitPickup = gta.createPickup(pickupModelId, getHouseData(houseId).locations[locationId].exitPosition); - getHouseData(houseId).locations[locationId].exitPickup.onAllDimensions = false; - getHouseData(houseId).locations[locationId].exitPickup.dimension = getHouseData(houseId).locations[locationId].exitDimension; - getHouseData(houseId).locations[locationId].exitPickup.setData("ag.owner.type", VRR_PICKUP_HOUSE_EXIT, false); - getHouseData(houseId).locations[locationId].exitPickup.setData("ag.owner.id", houseId, false); - getHouseData(houseId).locations[locationId].exitPickup.setData("ag.label.type", VRR_LABEL_EXIT, true); - addToWorld(getHouseData(houseId).locations[locationId].exitPickup); + getHouseData(houseId).exitPickup = gta.createPickup(pickupModelId, getHouseData(houseId).exitPosition); + getHouseData(houseId).exitPickup.onAllDimensions = false; + getHouseData(houseId).exitPickup.dimension = getHouseData(houseId).exitDimension; + setEntityData(getHouseData(houseId).exitPickup, "ag.owner.type", AG_PICKUP_HOUSE_EXIT, false); + setEntityData(getHouseData(houseId).exitPickup, "ag.owner.id", houseId, false); + setEntityData(getHouseData(houseId).exitPickup, "ag.label.type", AG_LABEL_EXIT, true); + addToWorld(getHouseData(houseId).exitPickup); } } } // =========================================================================== -function createHouseExitBlip(houseId, locationId) { +function createHouseExitBlip(houseId) { if(getHouseData(houseId).hasInterior) { - if(getHouseData(houseId).locations[locationId].exitBlipModel != -1) { - let blipModelId = getGameConfig().locations[locationId].blipSprites[getServerGame()].house; + if(getHouseData(houseId).exitBlipModel != -1) { + let blipModelId = getGameConfig().blipSprites[getServerGame()].house; if(getServerData().houses[houseId].exitBlipModel != 0) { - blipModelId = getHouseData(houseId).locations[locationId].exitBlipModel; + blipModelId = getHouseData(houseId).exitBlipModel; } - getHouseData(houseId).locations[locationId].exitBlip = gta.createBlip(getHouseData(houseId).locations[locationId].exitPosition, blipModelId, 1, getColourByName("houseGreen")); - getHouseData(houseId).locations[locationId].exitBlip.onAllDimensions = false; - getHouseData(houseId).locations[locationId].exitBlip.dimension = getHouseData(houseId).locations[locationId].entranceDimension; - getHouseData(houseId).locations[locationId].exitBlip.setData("ag.owner.type", VRR_BLIP_HOUSE_EXIT, false); - getHouseData(houseId).locations[locationId].exitBlip.setData("ag.owner.id", houseId, false); - addToWorld(getHouseData(houseId).locations[locationId].exitBlip); + getHouseData(houseId).exitBlip = gta.createBlip(blipModelId, getHouseData(houseId).exitPosition, 1, getColourByName("houseGreen")); + getHouseData(houseId).exitBlip.onAllDimensions = false; + getHouseData(houseId).exitBlip.dimension = getHouseData(houseId).entranceDimension; + setEntityData(getHouseData(houseId).exitBlip, "ag.owner.type", AG_BLIP_HOUSE_EXIT, false); + setEntityData(getHouseData(houseId).exitBlip, "ag.owner.id", houseId, false); + addToWorld(getHouseData(houseId).exitBlip); } } } @@ -645,7 +610,7 @@ function getHouseOwnerTypeText(ownerType) { // =========================================================================== function getHouseInfoCommand(command, params, client) { - let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)).house; + let houseId = (isPlayerInAnyHouse(client)) ? getPlayerHouse(client) : getClosestHouseEntrance(getPlayerPosition(client)); if(!areParamsEmpty(params)) { houseId = toInteger(params); @@ -703,37 +668,43 @@ function doesHouseHaveInterior(houseId) { return getHouseData(houseId).hasInterior; } -function deleteHouseLocationEntrancePickup(houseId) { - if(getHouseData(houseId).locations[locationId].entrancePickup != null) { - destroyElement(getHouseData(houseId).locations[locationId].entrancePickup); - getHouseData(houseId).locations[locationId].entrancePickup = null; +// =========================================================================== + +function deleteHouseEntrancePickup(houseId) { + if(getHouseData(houseId).entrancePickup != null) { + //removeFromWorld(getHouseData(houseId).entrancePickup); + deleteGameElement(getHouseData(houseId).entrancePickup); + getHouseData(houseId).entrancePickup = null; } } // =========================================================================== -function deleteHouseLocationExitPickup(houseId, locationId) { - if(getHouseData(houseId).locations[locationId].exitPickup != null) { - destroyElement(getHouseData(houseId).locations[locationId].exitPickup); - getHouseData(houseId).locations[locationId].exitPickup = null; +function deleteHouseExitPickup(houseId) { + if(getHouseData(houseId).exitPickup != null) { + //removeFromWorld(getHouseData(houseId).exitPickup); + deleteGameElement(getHouseData(houseId).exitPickup); + getHouseData(houseId).exitPickup = null; } } // =========================================================================== -function deleteHouseLocationEntranceBlip(houseId, locationId) { - if(getHouseData(houseId).locations[locationId].entranceBlip != null) { - destroyElement(getHouseData(houseId).locations[locationId].entranceBlip); - getHouseData(houseId).locations[locationId].entranceBlip = null; +function deleteHouseEntranceBlip(houseId) { + if(getHouseData(houseId).entranceBlip != null) { + //removeFromWorld(getHouseData(houseId).entranceBlip); + deleteGameElement(getHouseData(houseId).entranceBlip); + getHouseData(houseId).entranceBlip = null; } } // =========================================================================== -function deleteHouseLocationExitBlip(houseId, locationId) { - if(getHouseData(houseId).locations[locationId].exitBlip != null) { - destroyElement(getHouseData(houseId).locations[locationId].exitBlip); - getHouseData(houseId).locations[locationId].exitBlip = null; +function deleteHouseExitBlip(houseId) { + if(getHouseData(houseId).exitBlip != null) { + //removeFromWorld(getHouseData(houseId).exitBlip); + deleteGameElement(getHouseData(houseId).exitBlip); + getHouseData(houseId).exitBlip = null; } } @@ -748,10 +719,10 @@ function reloadAllHousesCommand(command, params, client) { } for(let i in getServerData().houses) { - deleteHouseExitBlips(i); - deleteHouseEntranceBlips(i); - deleteHouseExitPickups(i); - deleteHouseEntrancePickups(i); + deleteHouseExitBlip(i); + deleteHouseEntranceBlip(i); + deleteHouseExitPickup(i); + deleteHouseEntrancePickup(i); } getServerData().houses = null; diff --git a/scripts/server/job.js b/scripts/server/job.js index 2a36efc9..1cd8e99e 100644 --- a/scripts/server/job.js +++ b/scripts/server/job.js @@ -1331,35 +1331,6 @@ function saveJobToDatabase(jobData) { // =========================================================================== -function saveJobToDatabase(jobData) { - if(jobData == null) { - // Invalid job data - return false; - } - - console.log(`[VRR.Job]: Saving job ${jobData.name} to database ...`); - let dbConnection = connectToDatabase(); - if(dbConnection) { - let safeName = escapeDatabaseString(dbConnection, jobData.name); - // If job hasn't been added to database, ID will be 0 - if(jobData.databaseId == 0) { - let dbQueryString = `INSERT INTO job_main (job_name, job_enabled, job_pickup, job_blip, job_type, job_colour_r, job_colour_g, job_colour_b, job_whitelist, job_blacklist) VALUES ('${safeName}', ${boolToInt(jobData.enabled)}, ${jobData.pickupModel}, ${jobData.blipModel}, ${jobData.type}, ${jobData.colourArray[0]}, ${jobData.colourArray[1]}, ${jobData.colourArray[2]})`; - queryDatabase(dbConnection, dbQueryString); - jobData.databaseId = getDatabaseInsertId(dbConnection); - } else { - let dbQueryString = `UPDATE job_main SET job_name='${safeName}', job_enabled=${boolToInt(jobData.enabled)}, job_pickup=${jobData.pickupModel}, job_blip=${jobData.blipModel}, job_type=${jobData.type}, job_colour_r=${jobData.colourArray[0]}, job_colour_g=${jobData.colourArray[1]}, job_colour_b=${jobData.colourArray[2]} WHERE job_id=${jobData.databaseId}`; - queryDatabase(dbConnection, dbQueryString); - } - disconnectFromDatabase(dbConnection); - return true; - } - console.log(`[VRR.Job]: Saved job ${jobData.name} to database!`); - - return false; -} - -// --------------------------------------------------------------------------- - function saveJobLocationToDatabase(jobLocationData) { if(jobLocationData == null) { // Invalid job location data