refactor(esx_lscustom\server):fix nil table values

This commit is contained in:
Amir_Lynx
2022-12-14 17:40:03 +03:30
parent 88af523408
commit 8b466eb2b2
+15 -6
View File
@@ -4,10 +4,10 @@ local Customs = {}
RegisterNetEvent('esx_lscustom:startModing', function(props, netId)
local src = tostring(source)
if Customs[src] then
Customs[src][props.plate] = {props = props, netId = netId}
Customs[src][tostring(props.plate)] = {props = props, netId = netId}
else
Customs[src] = {}
Customs[src][props.plate] = {props = props, netId = netId}
Customs[src][tostring(props.plate)] = {props = props, netId = netId}
end
end)
@@ -25,7 +25,7 @@ AddEventHandler('esx:playerDropped', function(src)
for k,v in pairs(Customs[src]) do
local entity = NetworkGetEntityFromNetworkId(v.netId)
if DoesEntityExist(entity) then
if players > 0 then
if playersCount > 0 then
TriggerClientEvent('esx_lscustom:restoreMods', -1, v.netId, v.props)
else
DeleteEntity(entity)
@@ -70,16 +70,25 @@ AddEventHandler('esx_lscustom:buyMod', function(price)
end)
RegisterServerEvent('esx_lscustom:refreshOwnedVehicle')
AddEventHandler('esx_lscustom:refreshOwnedVehicle', function(vehicleProps)
AddEventHandler('esx_lscustom:refreshOwnedVehicle', function(vehicleProps, netId)
local src = tostring(source)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.single('SELECT vehicle FROM owned_vehicles WHERE plate = ?', {vehicleProps.plate},
function(result)
if result then
local vehicle = json.decode(result.vehicle)
if vehicleProps.model == vehicle.model then
MySQL.update('UPDATE owned_vehicles SET vehicle = ? WHERE plate = ?', {json.encode(vehicleProps), vehicleProps.plate})
Customs[tostring(source)][tostring(vehicleProps.plate)].props = props
if Customs[src] then
if Customs[src][tostring(vehicleProps.plate)] then
Customs[src][tostring(vehicleProps.plate)].props = vehicleProps
else
Customs[src][tostring(vehicleProps.plate)] = {props = vehicleProps, netId = netId}
end
else
Customs[src] = {}
Customs[src][tostring(vehicleProps.plate)] = {props = vehicleProps, netId = netId}
end
else
print(('[^3WARNING^7] Player ^5%s^7 Attempted To upgrade with mismatching vehicle model'):format(xPlayer.source))
end