From 2aefa093408a5779cb588349313d26cb3178f4a7 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Mon, 7 Nov 2022 13:35:49 -0600 Subject: [PATCH] Fixes for new IV sync --- scripts/client/business.js | 2 +- scripts/client/house.js | 2 +- scripts/client/job.js | 2 +- scripts/client/sync.js | 29 +++++++++++++++-------------- scripts/server/business.js | 6 +++--- scripts/server/event.js | 18 ++++++++++-------- scripts/server/house.js | 4 ++-- scripts/server/vehicle.js | 12 ++++-------- 8 files changed, 37 insertions(+), 38 deletions(-) diff --git a/scripts/client/business.js b/scripts/client/business.js index 50eed775..f151cc6f 100644 --- a/scripts/client/business.js +++ b/scripts/client/business.js @@ -38,7 +38,7 @@ function initBusinessScript() { function receiveBusinessFromServer(businessId, name, entrancePosition, blipModel, pickupModel, buyPrice, rentPrice, hasInterior, locked, hasItems) { logToConsole(LOG_DEBUG, `[AGRP.Business] Received business ${businessId} (${name}) from server`); - if (!areServerElementsSupported() || getGame() == AGRP_GAME_MAFIA_ONE) { + if (!areServerElementsSupported() || getGame() == AGRP_GAME_MAFIA_ONE || getGame() == AGRP_GAME_GTA_IV) { if (getBusinessData(businessId) != false) { let businessData = getBusinessData(businessId); businessData.name = name; diff --git a/scripts/client/house.js b/scripts/client/house.js index d84dff36..f31ec154 100644 --- a/scripts/client/house.js +++ b/scripts/client/house.js @@ -29,7 +29,7 @@ class HouseData { function receiveHouseFromServer(houseId, description, entrancePosition, blipModel, pickupModel, buyPrice, rentPrice, hasInterior, locked) { logToConsole(LOG_DEBUG, `[AGRP.House] Received house ${houseId} (${name}) from server`); - if (!areServerElementsSupported() || getGame() == AGRP_GAME_MAFIA_ONE) { + if (!areServerElementsSupported() || getGame() == AGRP_GAME_MAFIA_ONE || getGame() == AGRP_GAME_GTA_IV) { if (getHouseData(houseId) != false) { let houseData = getHouseData(houseId); houseData.description = description; diff --git a/scripts/client/job.js b/scripts/client/job.js index 2b57a2f0..1e7fff6f 100644 --- a/scripts/client/job.js +++ b/scripts/client/job.js @@ -140,7 +140,7 @@ function hideJobRouteLocation() { function receiveJobFromServer(jobId, jobLocationId, name, position, blipModel, pickupModel) { logToConsole(LOG_DEBUG, `[AGRP.Job] Received job ${jobId} (${name}) from server`); - if (getGame() == AGRP_GAME_GTA_IV) { + if (!areServerElementsSupported() || getGame() == AGRP_GAME_MAFIA_ONE || getGame() == AGRP_GAME_GTA_IV) { if (getJobData(jobId) != false) { let jobData = getJobData(jobId); jobData.jobLocationId = jobLocationId; diff --git a/scripts/client/sync.js b/scripts/client/sync.js index 34cc7a78..3af0c8f5 100644 --- a/scripts/client/sync.js +++ b/scripts/client/sync.js @@ -47,15 +47,15 @@ function processSync(event, deltaTime) { // =========================================================================== function setVehicleLights(vehicleId, state) { - if (getGame() == AGRP_GAME_GTA_IV) { - if (!state) { - natives.forceCarLights(natives.getVehicleFromNetworkId(vehicleId, 0)); - } else { - natives.forceCarLights(natives.getVehicleFromNetworkId(vehicleId, 1)); - } - } else { - getElementFromId(vehicleId).lights = state; - } + //if (getGame() == AGRP_GAME_GTA_IV) { + // if (!state) { + // natives.forceCarLights(natives.getVehicleFromNetworkId(vehicleId, 0)); + // } else { + // natives.forceCarLights(natives.getVehicleFromNetworkId(vehicleId, 1)); + // } + //} else { + getElementFromId(vehicleId).lights = state; + //} } // =========================================================================== @@ -73,11 +73,12 @@ function syncVehicleProperties(vehicle) { if (doesEntityDataExist(vehicle, "agrp.lights")) { let lightStatus = getEntityData(vehicle, "agrp.lights"); - if (!lightStatus) { - vehicle.lightStatus = 2; - } else { - vehicle.lightStatus = 1; - } + vehicle.lights = lightStatus; + } + + if (doesEntityDataExist(vehicle, "agrp.locked")) { + let lockStatus = getEntityData(vehicle, "agrp.locked"); + vehicle.locked = lockStatus; } if (doesEntityDataExist(vehicle, "agrp.invincible")) { diff --git a/scripts/server/business.js b/scripts/server/business.js index bc2dd99b..774f3ed4 100644 --- a/scripts/server/business.js +++ b/scripts/server/business.js @@ -2028,7 +2028,7 @@ function createBusinessEntrancePickup(businessId) { logToConsole(LOG_VERBOSE, `[AGRP.Job]: Creating entrance pickup for business ${businessData.name}`); - if (areServerElementsSupported() && getGame() != AGRP_GAME_MAFIA_ONE) { + if (areServerElementsSupported() && getGame() != AGRP_GAME_MAFIA_ONE && getGame() != AGRP_GAME_GTA_IV) { let entrancePickup = null; if (isGameFeatureSupported("pickup")) { let pickupModelId = getGameConfig().pickupModels[getGame()].Business; @@ -2105,7 +2105,7 @@ function createBusinessEntranceBlip(businessId) { logToConsole(LOG_VERBOSE, `[AGRP.Job]: Creating entrance blip for business ${businessData.name} (model ${blipModelId})`); - if (areServerElementsSupported() && getGame() != AGRP_GAME_MAFIA_ONE) { + if (areServerElementsSupported() && getGame() != AGRP_GAME_MAFIA_ONE && getGame() != AGRP_GAME_GTA_IV) { let entranceBlip = createGameBlip(businessData.entrancePosition, blipModelId, 1, getColourByType("businessBlue")); if (entranceBlip != null) { if (businessData.entranceDimension != -1) { @@ -2875,7 +2875,7 @@ function getBusinessIdFromDatabaseId(databaseId) { // Updates all pickup data for a business by businessId function updateBusinessPickupLabelData(businessId) { - if (!areServerElementsSupported() || getGame() == AGRP_GAME_MAFIA_ONE) { + if (!areServerElementsSupported() || getGame() == AGRP_GAME_MAFIA_ONE || getGame() == AGRP_GAME_GTA_IV) { sendBusinessToPlayer(null, businessId, getBusinessData(businessId).name, getBusinessData(businessId).entrancePosition, getBusinessEntranceBlipModelForNetworkEvent(businessId), getBusinessEntrancePickupModelForNetworkEvent(businessId), getBusinessData(businessId).buyPrice, getBusinessData(businessId).rentPrice, getBusinessData(businessId).hasInterior, getBusinessData(businessId).locked, doesBusinessHaveAnyItemsToBuy(businessId)); return false; } diff --git a/scripts/server/event.js b/scripts/server/event.js index 4c8808f2..b710b80c 100644 --- a/scripts/server/event.js +++ b/scripts/server/event.js @@ -393,7 +393,7 @@ function onPedSpawn(ped) { logToConsole(LOG_WARN | LOG_DEBUG, `[AGRP.Event] Ped ${ped.id} spawned!`); //if (ped.type == ELEMENT_PLAYER) { - // if (getGame() != AGRP_GAME_MAFIA_ONE && getGame() != AGRP_GAME_GTA_IV) { + // if (getGame() != AGRP_GAME_MAFIA_ONE) { // //setTimeout(onPlayerSpawn, 250, getClientFromPlayerElement(ped)); // //onPlayerSpawn(getClientFromPlayerElement(ped)); // } @@ -454,7 +454,7 @@ async function onPlayerSpawn(client) { // return false; //} - if (isCustomCameraSupported() && getGame() != AGRP_GAME_GTA_IV && getGame() != AGRP_GAME_GTA_IV_EFLC) { + if (isCustomCameraSupported()) { logToConsole(LOG_DEBUG, `[AGRP.Event] Restoring ${getPlayerDisplayForConsole(client)}'s camera`); restorePlayerCamera(client); } @@ -585,11 +585,13 @@ async function onPlayerSpawn(client) { sendNameTagDistanceToClient(client, getServerConfig().nameTagDistance); } - if (!areServerElementsSupported() || getGame() == AGRP_GAME_MAFIA_ONE) { + if (!areServerElementsSupported() || getGame() == AGRP_GAME_MAFIA_ONE || getGame() == AGRP_GAME_GTA_IV) { logToConsole(LOG_DEBUG, `[AGRP.Event] Sending properties, jobs, and vehicles to ${getPlayerDisplayForConsole(client)} (no server elements)`); sendAllBusinessesToPlayer(client); sendAllHousesToPlayer(client); - sendAllJobsToPlayer(client); + if (getGame() != AGRP_GAME_GTA_IV) { + sendAllJobsToPlayer(client); + } requestPlayerPedNetworkId(client); } @@ -672,6 +674,10 @@ function onPlayerCommand(event, client, command, params) { function onPedExitedVehicle(event, ped, vehicle, seat) { logToConsole(LOG_WARN | LOG_DEBUG, `[AGRP.Event] Ped ${ped.id} exited vehicle ${vehicle.id} from seat ${seat}!`); + if (getVehicleData(vehicle) == false) { + return false; + } + if (ped.isType(ELEMENT_PLAYER)) { let client = getClientFromPlayerElement(ped); if (client != null) { @@ -716,10 +722,6 @@ function onPedEnteredVehicle(event, ped, vehicle, seat) { return false; } - if (getGame() == AGRP_GAME_GTA_IV) { - vehicle = getVehicleFromIVNetworkId(clientVehicle); - } - if (!getVehicleData(vehicle)) { return false; } diff --git a/scripts/server/house.js b/scripts/server/house.js index cdb4ffae..5531537f 100644 --- a/scripts/server/house.js +++ b/scripts/server/house.js @@ -1056,7 +1056,7 @@ function createHouseEntrancePickup(houseId) { return false; } - if (areServerElementsSupported() && getGame() != AGRP_GAME_MAFIA_ONE) { + if (areServerElementsSupported() && getGame() != AGRP_GAME_MAFIA_ONE && getGame() != AGRP_GAME_GTA_IV) { let entrancePickup = null; if (isGameFeatureSupported("pickup")) { let pickupModelId = getGameConfig().pickupModels[getGame()].House; @@ -1781,7 +1781,7 @@ function getHouseFromParams(params) { // =========================================================================== function updateHousePickupLabelData(houseId) { - if (!areServerElementsSupported() || getGame() == AGRP_GAME_MAFIA_ONE) { + if (!areServerElementsSupported() || getGame() == AGRP_GAME_MAFIA_ONE || getGame() == AGRP_GAME_GTA_IV) { sendHouseToPlayer(null, houseId, getHouseData(houseId).description, getHouseData(houseId).entrancePosition, getHouseEntranceBlipModelForNetworkEvent(houseId), getHouseEntrancePickupModelForNetworkEvent(houseId), getHouseData(houseId).buyPrice, getHouseData(houseId).rentPrice, getHouseData(houseId).hasInterior, getHouseData(houseId).locked); return false; } diff --git a/scripts/server/vehicle.js b/scripts/server/vehicle.js index 3699a92b..6e026798 100644 --- a/scripts/server/vehicle.js +++ b/scripts/server/vehicle.js @@ -338,15 +338,11 @@ function spawnAllVehicles() { * @return {VehicleData} The vehicles's data (class instance) */ function getVehicleData(vehicle) { - if (getGame() != AGRP_GAME_GTA_IV) { - if (isVehicleObject(vehicle)) { - let dataIndex = getEntityData(vehicle, "agrp.dataSlot"); - if (typeof getServerData().vehicles[dataIndex] != "undefined") { - return getServerData().vehicles[dataIndex]; - } + if (isVehicleObject(vehicle)) { + let dataIndex = getEntityData(vehicle, "agrp.dataSlot"); + if (typeof getServerData().vehicles[dataIndex] != "undefined") { + return getServerData().vehicles[dataIndex]; } - } else { - return getServerData().vehicles.find((v) => v.ivNetworkId == vehicle); } return false;