Skip to main content

SpawnVehicle

ESX.Game.SpawnVehicle(modelOrHash, coords, heading, cb)

This function spawns an vehicle visible to everyone on the server.

!!! warning This is an async function because it awaits the vehicle model to be streamed, there is an example below on how to properly utilize it.

Arguments

ArgumentData TypeOptionalDefault ValueExplanation
modelOrHashstring&numberNo-You can either specify a model, for example blista, or a vehicle hash.
coordstableNo-The coords where the vehicle should be spawned. You can also parse an vector type without any issues
headingnumberNo-The heading of the spawned vehicle, must contain a decimal
cbfunctionYes-The returned function when the vehicle has been spawned. The invoked function has one argument, which is the vehicle handle

Example

ESX.Game.SpawnVehicle('blista', vector3(120.0, -200.0, 30.0), 100.0, function(vehicle)
print(DoesEntityExist(vehicle), 'this code is async!')
end)

print('this code is sync!')