- Documentation
- Shared functions
- createVehicle
Function
createVehicle
Creates a vehicle in the world: model, position, rotation and number plate text.
Syntax
vehicle createVehicle(int model, float x, float y, float z [, float rx = 0, float ry = 0, float rz = 0, string plate, bool direction, int variant1, int variant2])Arguments
modelint- San Andreas vehicle model number, from
400to611. For example411is the Infernus,536is the Blade. x, y, zfloat- Position in the world.
rx, ry, rzfloat, optional = 0- Rotation in degrees. Usually
rz, the direction the car faces, is enough. platestring, optional- Number plate text. Without it the game picks a random plate.
directionbool, optional- Accepted for compatibility with existing scripts.
variant1, variant2int, optional- Body variant for models that have them.
Differences from MTA:SA
- These MTA:SA arguments are not here:
bool synced = true
In MTA:SA
createVehicle(int model, float x, float y, float z, float rx, float ry, float rz, string numberplate, bool bDirection, int variant1, int variant2, bool synced = true)Returns
The created vehicle, or false if the model or position is wrong.
Example
The /car command places an Infernus next to the player and puts them straight in it.
addCommandHandler("car", function(player, _, model)
local x, y, z = getElementPosition(player)
local car = createVehicle(tonumber(model) or 411, x + 3, y, z, 0, 0, 0, "GROVE 4L")
if not car then
outputChatBox("There is no such model.", player, 255, 80, 80)
return
end
warpPedIntoVehicle(player, car)
end)
Notes
RGB colours. Set the body colour with setVehicleColor(car, r1, g1, b1, r2, g2, b2) using full RGB values, not just the game's palette numbers.
The vehicle belongs to the resource. After stop or restart of the resource, all its vehicles disappear. If cars should stay, save their state and create them again on start.
See also
getElementPositionReturns an element's position in the world: a player, vehicle, object or marker.outputChatBoxWrites a message in chat. On the server to one player or everyone, on the client in the local player's chat.spawnPlayerSpawns a player at the given place: position, rotation, skin, interior and dimension.