mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-18 22:36:03 +01:00
fix(vehicle): netId & properties inconsistencies
This commit is contained in:
@@ -241,13 +241,16 @@ local function getVehicleBlipSprite(entity)
|
|||||||
return typeBlip[model] or classBlip[class] or 225 -- 255 is default car blip
|
return typeBlip[model] or classBlip[class] or 225 -- 255 is default car blip
|
||||||
end
|
end
|
||||||
|
|
||||||
RegisterNetEvent("ND_Vehicles:blip", function(netId, status)
|
local function getVehFromNetId(netId)
|
||||||
local time = GetCloudTimeAsInt()
|
local time = GetCloudTimeAsInt()
|
||||||
while not NetworkDoesNetworkIdExist(netId) or not NetworkDoesEntityExistWithNetworkId(netId) and time-GetCloudTimeAsInt() < 5 do
|
while not NetworkDoesNetworkIdExist(netId) or not NetworkDoesEntityExistWithNetworkId(netId) and time-GetCloudTimeAsInt() < 5 do
|
||||||
Wait(100)
|
Wait(100)
|
||||||
end
|
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 veh then return end
|
||||||
if not status then
|
if not status then
|
||||||
local blip = GetBlipFromEntity(veh)
|
local blip = GetBlipFromEntity(veh)
|
||||||
@@ -265,16 +268,16 @@ RegisterNetEvent("ND_Vehicles:blip", function(netId, status)
|
|||||||
EndTextCommandSetBlipName(blip)
|
EndTextCommandSetBlipName(blip)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent("ND_Vehicles:syncAlarm", function(netid)
|
RegisterNetEvent("ND_Vehicles:syncAlarm", function(netId)
|
||||||
local veh = NetToVeh(netid)
|
local veh = getVehFromNetId(netId)
|
||||||
if not veh then return end
|
if not veh then return end
|
||||||
SetVehicleAlarmTimeLeft(veh, 1)
|
SetVehicleAlarmTimeLeft(veh, 1)
|
||||||
SetVehicleAlarm(veh, true)
|
SetVehicleAlarm(veh, true)
|
||||||
StartVehicleAlarm(veh)
|
StartVehicleAlarm(veh)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent("ND_VehicleSystem:setOwnedIfNot", function(netid)
|
RegisterNetEvent("ND_VehicleSystem:setOwnedIfNot", function(netId)
|
||||||
local veh = NetToVeh(netid)
|
local veh = getVehFromNetId(netId)
|
||||||
if not veh then return end
|
if not veh then return end
|
||||||
setVehicleOwned(veh, true)
|
setVehicleOwned(veh, true)
|
||||||
setVehicleLocked(veh, true)
|
setVehicleLocked(veh, true)
|
||||||
@@ -312,8 +315,8 @@ local function playKeyFob(veh)
|
|||||||
return keyFob and DeleteEntity(keyFob)
|
return keyFob and DeleteEntity(keyFob)
|
||||||
end
|
end
|
||||||
|
|
||||||
RegisterNetEvent("ND_Vehicles:keyFob", function(vehicleNetId)
|
RegisterNetEvent("ND_Vehicles:keyFob", function(netId)
|
||||||
playKeyFob(NetToVeh(vehicleNetId))
|
playKeyFob(getVehFromNetId(netId))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local dontLock = {
|
local dontLock = {
|
||||||
@@ -339,10 +342,12 @@ AddStateBagChangeHandler("locked", nil, function(bagName, key, value, reserved,
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
lib.callback.register("ND_Vehicles:getProps", function()
|
lib.callback.register("ND_Vehicles:getProps", function(netId)
|
||||||
local veh = GetVehiclePedIsIn(cache.ped)
|
local veh = getVehFromNetId(netId)
|
||||||
local props = lib.getVehicleProperties(veh)
|
local props = lib.getVehicleProperties(veh)
|
||||||
local colorPrimary, colorSecondary = GetVehicleColours(veh)
|
local colorPrimary, colorSecondary = GetVehicleColours(veh)
|
||||||
|
if not props then return end
|
||||||
|
|
||||||
props.colorNamePrimary = vehicleColorNames[colorPrimary]
|
props.colorNamePrimary = vehicleColorNames[colorPrimary]
|
||||||
props.colorNameSecondary = vehicleColorNames[colorSecondary]
|
props.colorNameSecondary = vehicleColorNames[colorSecondary]
|
||||||
props.colorName = props.colorNamePrimary == props.colorNameSecondary and props.colorNamePrimary or ("%s & %s"):format(props.colorNamePrimary, props.colorNameSecondary)
|
props.colorName = props.colorNamePrimary == props.colorNameSecondary and props.colorNamePrimary or ("%s & %s"):format(props.colorNamePrimary, props.colorNameSecondary)
|
||||||
|
|||||||
@@ -87,9 +87,11 @@ function NDCore.getVehicle(entity)
|
|||||||
function self.delete(saveProperties)
|
function self.delete(saveProperties)
|
||||||
if not DoesEntityExist(entity) then return end
|
if not DoesEntityExist(entity) then return end
|
||||||
if saveProperties and self.id and self.owner then
|
if saveProperties and self.id and self.owner then
|
||||||
local properties = lib.callback.await("ND_Vehicles:getProps", NetworkGetEntityOwner(entity))
|
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})
|
MySQL.query("UPDATE nd_vehicles SET properties = ? WHERE id = ?", {json.encode(properties), self.id})
|
||||||
end
|
end
|
||||||
|
end
|
||||||
DeleteEntity(entity)
|
DeleteEntity(entity)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user