Skip to content

Commit

Permalink
Merge pull request #911 from TheFantomas/main
Browse files Browse the repository at this point in the history
refactor(es_extended/client/main.lua): VehicleProperties better way (Credits for Luke <3)
  • Loading branch information
TheFantomas authored Feb 21, 2023
2 parents 4534c9f + 4933b07 commit 26257ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
39 changes: 23 additions & 16 deletions [core]/es_extended/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,31 @@ AddEventHandler('esx:restoreLoadout', function()
end
end)

-- Credit: https://github.com/LukeWasTakenn, https://github.com/LukeWasTakenn/luke_garages/blob/master/client/client.lua#L331-L352
AddStateBagChangeHandler('VehicleProperties', nil, function(bagName, key, value)
if value then
Wait(0)
local NetId = value.NetId
local Vehicle = NetworkGetEntityFromNetworkId(NetId)
local Tries = 0
while Vehicle == 0 do
Vehicle = NetworkGetEntityFromNetworkId(NetId)
Wait(100)
Tries = Tries + 1
if Tries > 300 then
break
end
end
if NetworkGetEntityOwner(Vehicle) == PlayerId() then
ESX.Game.SetVehicleProperties(Vehicle, value)
end
if not value then
return
end

local netId = bagName:gsub('entity:', '')
local timer = GetGameTimer()
while not NetworkDoesEntityExistWithNetworkId(tonumber(netId)) do
Wait(0)
if GetGameTimer() - timer > 10000 then
return
end
end

local vehicle = NetToVeh(tonumber(netId))
local timer = GetGameTimer()
while NetworkGetEntityOwner(vehicle) ~= PlayerId() do
Wait(0)
if GetGameTimer() - timer > 10000 then
return
end
end

This comment has been minimized.

Copy link
@mahanmoulaei

mahanmoulaei Feb 21, 2023

It is unbelievable how ESX accepts/come up with this kind of crappy PRs...

ESX.Game.SetVehicleProperties(vehicle, value)
end)

RegisterNetEvent('esx:setAccountMoney')
Expand Down
1 change: 0 additions & 1 deletion [core]/es_extended/server/onesync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ function ESX.OneSync.SpawnVehicle(model, coords, heading, properties, cb)
end

local networkId = NetworkGetNetworkIdFromEntity(createdVehicle)
vehicleProperties.NetId = networkId
Entity(createdVehicle).state:set('VehicleProperties', vehicleProperties, true)
cb(networkId)
else
Expand Down

0 comments on commit 26257ac

Please sign in to comment.