mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 09:18:53 +00:00
make sure the vehicle exists on the client
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user