Vehicle server-spawning functions/callback

This commit is contained in:
Kakarot
2022-07-22 22:59:01 -05:00
parent 8b5f5b2b37
commit 1b2915a75f
2 changed files with 35 additions and 0 deletions
+24
View File
@@ -167,6 +167,30 @@ function QBCore.Functions.GetEntitiesInBucket(bucket --[[ int ]])
end
end
-- Server side vehicle creation with optional callback
-- the CreateVehicle RPC still uses the client for creation so players must be near
function QBCore.Functions.SpawnVehicle(model, cb, coords, warp)
model = type(model) == 'string' and GetHashKey(model) or model
if not coords then coords = GetEntityCoords(GetPlayerPed(source)) end
local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, true, true)
while not DoesEntityExist(veh) do Wait(0) end
if warp then TaskWarpPedIntoVehicle(GetPlayerPed(source), veh, -1) end
if cb then cb(veh) end
end
-- Server side vehicle creation with optional callback
-- the CreateAutomobile native is still experimental but doesn't use client for creation
-- doesn't work for all vehicles!
function QBCore.Functions.CreateVehicle(model, cb, coords, warp)
model = type(model) == 'string' and GetHashKey(model) or model
if not coords then coords = GetEntityCoords(GetPlayerPed(source)) end
local CreateAutomobile = GetHashKey("CREATE_AUTOMOBILE")
local veh = Citizen.InvokeNative(CreateAutomobile, model, coords, coords.w, true, true)
while not DoesEntityExist(veh) do Wait(0) end
if warp then TaskWarpPedIntoVehicle(GetPlayerPed(source), veh, -1) end
if cb then cb(veh) end
end
-- Paychecks (standalone - don't touch)
function PaycheckInterval()