diff --git a/server/events.lua b/server/events.lua index 7f076ff..8526153 100644 --- a/server/events.lua +++ b/server/events.lua @@ -247,11 +247,18 @@ end) -- use the netid on the client with the NetworkGetEntityFromNetworkId native -- convert it to a vehicle via the NetToVeh native QBCore.Functions.CreateCallback('QBCore:Server:SpawnVehicle', function(source, cb, model, coords, warp) - model = type(model) == 'string' and GetHashKey(model) or model - if not coords then coords = GetEntityCoords(GetPlayerPed(source)) end + local ped = GetPlayerPed(source) + model = type(model) == 'string' and joaat(model) or model + if not coords then coords = GetEntityCoords(ped) 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 warp then + while GetVehiclePedIsIn(ped) ~= veh do + Wait(0) + TaskWarpPedIntoVehicle(ped, veh, -1) + end + end + while NetworkGetEntityOwner(veh) ~= source do Wait(0) end cb(NetworkGetNetworkIdFromEntity(veh)) end) diff --git a/server/functions.lua b/server/functions.lua index e4a1000..145ca0a 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -170,11 +170,18 @@ 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(source, model, coords, warp) + local ped = GetPlayerPed(source) model = type(model) == 'string' and joaat(model) or model - if not coords then coords = GetEntityCoords(GetPlayerPed(source)) end + if not coords then coords = GetEntityCoords(ped) 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 warp then + while GetVehiclePedIsIn(ped) ~= veh do + Wait(0) + TaskWarpPedIntoVehicle(ped, veh, -1) + end + end + while NetworkGetEntityOwner(veh) ~= source do Wait(0) end return veh end