From 698707c992c8741f665a079fcaffb13fc939152f Mon Sep 17 00:00:00 2001 From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com> Date: Tue, 26 Sep 2023 23:00:51 +0200 Subject: [PATCH] fix(vehicle): netId & properties inconsistencies --- client/vehicle/main.lua | 25 +++++++++++++++---------- server/vehicle.lua | 6 ++++-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/client/vehicle/main.lua b/client/vehicle/main.lua index b66d37a..2d4287c 100644 --- a/client/vehicle/main.lua +++ b/client/vehicle/main.lua @@ -241,13 +241,16 @@ local function getVehicleBlipSprite(entity) return typeBlip[model] or classBlip[class] or 225 -- 255 is default car blip end -RegisterNetEvent("ND_Vehicles:blip", function(netId, status) +local function getVehFromNetId(netId) local time = GetCloudTimeAsInt() while not NetworkDoesNetworkIdExist(netId) or not NetworkDoesEntityExistWithNetworkId(netId) and time-GetCloudTimeAsInt() < 5 do Wait(100) end + return NetToVeh(netId) +end - local veh = NetToVeh(netId) +RegisterNetEvent("ND_Vehicles:blip", function(netId, status) + local veh = getVehFromNetId(netId) if not veh then return end if not status then local blip = GetBlipFromEntity(veh) @@ -265,16 +268,16 @@ RegisterNetEvent("ND_Vehicles:blip", function(netId, status) EndTextCommandSetBlipName(blip) end) -RegisterNetEvent("ND_Vehicles:syncAlarm", function(netid) - local veh = NetToVeh(netid) +RegisterNetEvent("ND_Vehicles:syncAlarm", function(netId) + local veh = getVehFromNetId(netId) if not veh then return end SetVehicleAlarmTimeLeft(veh, 1) SetVehicleAlarm(veh, true) StartVehicleAlarm(veh) end) -RegisterNetEvent("ND_VehicleSystem:setOwnedIfNot", function(netid) - local veh = NetToVeh(netid) +RegisterNetEvent("ND_VehicleSystem:setOwnedIfNot", function(netId) + local veh = getVehFromNetId(netId) if not veh then return end setVehicleOwned(veh, true) setVehicleLocked(veh, true) @@ -312,8 +315,8 @@ local function playKeyFob(veh) return keyFob and DeleteEntity(keyFob) end -RegisterNetEvent("ND_Vehicles:keyFob", function(vehicleNetId) - playKeyFob(NetToVeh(vehicleNetId)) +RegisterNetEvent("ND_Vehicles:keyFob", function(netId) + playKeyFob(getVehFromNetId(netId)) end) local dontLock = { @@ -339,10 +342,12 @@ AddStateBagChangeHandler("locked", nil, function(bagName, key, value, reserved, end) end) -lib.callback.register("ND_Vehicles:getProps", function() - local veh = GetVehiclePedIsIn(cache.ped) +lib.callback.register("ND_Vehicles:getProps", function(netId) + local veh = getVehFromNetId(netId) local props = lib.getVehicleProperties(veh) local colorPrimary, colorSecondary = GetVehicleColours(veh) + if not props then return end + props.colorNamePrimary = vehicleColorNames[colorPrimary] props.colorNameSecondary = vehicleColorNames[colorSecondary] props.colorName = props.colorNamePrimary == props.colorNameSecondary and props.colorNamePrimary or ("%s & %s"):format(props.colorNamePrimary, props.colorNameSecondary) diff --git a/server/vehicle.lua b/server/vehicle.lua index 861e7bc..e4844b9 100644 --- a/server/vehicle.lua +++ b/server/vehicle.lua @@ -87,8 +87,10 @@ function NDCore.getVehicle(entity) function self.delete(saveProperties) if not DoesEntityExist(entity) then return end if saveProperties and self.id and self.owner then - local properties = lib.callback.await("ND_Vehicles:getProps", NetworkGetEntityOwner(entity)) - MySQL.query("UPDATE nd_vehicles SET properties = ? WHERE id = ?", {json.encode(properties), self.id}) + local properties = lib.callback.await("ND_Vehicles:getProps", NetworkGetEntityOwner(entity), self.netId) + if properties then + MySQL.query("UPDATE nd_vehicles SET properties = ? WHERE id = ?", {json.encode(properties), self.id}) + end end DeleteEntity(entity) end