Lua:
ESX.SpawnOwnedVehicle = function(modelName, coords, heading, cb)
local model = (type(modelName) == 'number' and modelName or GetHashKey(modelName))
Citizen.CreateThread(function()
ESX.Streaming.RequestModel(model)
if coords == nil then
local playerPed = PlayerPedId()
coords = GetEntityCoords(playerPed) -- get the position of the local player ped
heading = GetEntityHeading(playerPed)
end
local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, heading, true, false)
local id = NetworkGetNetworkIdFromEntity(vehicle)
SetNetworkIdCanMigrate(id, true)
SetEntityAsMissionEntity(vehicle, true, false)
SetVehicleHasBeenOwnedByPlayer(vehicle, true)
SetVehicleNeedsToBeHotwired(vehicle, false)
SetVehicleAutoRepairDisabled(vehicle, true)
SetModelAsNoLongerNeeded(model)
RequestCollisionAtCoord(coords.x, coords.y, coords.z)
while not HasCollisionLoadedAroundEntity(vehicle) do
RequestCollisionAtCoord(coords.x, coords.y, coords.z)
Citizen.Wait(0)
end
SetVehRadioStation(vehicle, 'OFF')
if cb then
cb(vehicle)
end
end)
end