make sure the vehicle exists on the client

This commit is contained in:
Mycroft
2022-08-11 19:54:02 +01:00
parent ef8fde3026
commit 16c747fc2a
2 changed files with 17 additions and 12 deletions
+4
View File
@@ -489,6 +489,10 @@ function ESX.Game.SpawnVehicle(vehicle, coords, heading, cb, networked)
print("Spawned Vehicle: " .. NetID)
if NetID then
local vehicle = NetworkGetEntityFromNetworkId(NetID)
while not DoesEntityExist(vehicle) do
vehicle = NetworkGetEntityFromNetworkId(NetID)
Wait(0)
end
SetEntityAsMissionEntity(vehicle, true, true)
SetVehicleHasBeenOwnedByPlayer(vehicle, true)
SetVehicleNeedsToBeHotwired(vehicle, false)
+13 -12
View File
@@ -61,18 +61,19 @@ end
---@param heading number
---@param cb function
function ESX.OneSync.SpawnVehicle(model, coords, heading, autoMobile, cb)
if type(model) == 'string' then model = GetHashKey(model) end
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
if type(autoMobile) ~= 'boolean' then
return
end
local tries = 0
local Entity = autoMobile and Citizen.InvokeNative(`CREATE_AUTOMOBILE`, model, coords.x, coords.y, coords.z, heading) or CreateVehicle(model, coords, heading, true, true)
while not DoesEntityExist(Entity) do
Wait(0)
end
local netID = NetworkGetNetworkIdFromEntity(Entity)
cb(netID)
if type(model) == 'string' then model = GetHashKey(model) end
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
if type(autoMobile) ~= 'boolean' then
return
end
CreateThread(function()
local Entity = autoMobile and Citizen.InvokeNative(`CREATE_AUTOMOBILE`, model, coords.x, coords.y, coords.z, heading) or CreateVehicle(model, coords, heading, true, true)
while not DoesEntityExist(Entity) do
Wait(0)
end
local netID = NetworkGetNetworkIdFromEntity(Entity)
cb(netID)
end)
end
---@param model number|string