createVehicle | Multi Theft Auto: Wiki Skip to content

createVehicle

Client-side
Server-side
Shared
Needs checking

This function was partially migrated from the old wiki. Please review manually:

  • Missing section: Using trains

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function creates a vehicle at the specified location.

Note

Vehicles (and other elements) created client-side are only seen by the client that created them, aren't synced and players cannot enter them. They are essentially for display only.

Note

Due to how GTA works, creating a lot of vehicles in the same place will cause lag. The more geometries and unique textures has model the bigger the lag is. Even a lot of default vehicles will cause lag if in the same place.

OOP Syntax Help! I don't understand this!

Syntax

vehicle 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 ] )
Required Arguments
  • model: The vehicle ID of the vehicle being created.
  • x: A floating point number representing the X coordinate on the map.
  • y: A floating point number representing the Y coordinate on the map.
  • z: A floating point number representing the Z coordinate on the map.
  • rx: A floating point number representing the rotation about the X axis in degrees.
  • ry: A floating point number representing the rotation about the Y axis in degrees.
  • rz: A floating point number representing the rotation about the Z axis in degrees.
  • numberplate: A string that will go on the number plate of the vehicle (max 8 characters).
  • bDirection: Placeholder boolean which provides backward compatibility with some scripts. It never had any effect, but it is read by the code. It is recommended to ignore this argument, passing false or the variant1 argument in its place.
  • variant1: MISSING_PARAM_DESC
  • variant2: MISSING_PARAM_DESC
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • synced (default: true): MISSING_PARAM_DESC

Returns

  • vehicle: value

Returns the vehicle element that was created. Returns false if the arguments are incorrect, or if the vehicle limit of 65535 is exceeded.

Code Examples

shared

This example creates a 'vehicle spawner' marker that gives the player a vehicle as soon they step into it.

local vehMark = createMarker(-2426.34106, -639.12714, 132.93631,"cylinder")
function vehicleSpawner(hitElement,matchingDimension)
if getElementType(hitElement) == "player" then
if getPedOccupiedVehicle(hitElement) == false then
local x,y,z = getElementPosition(hitElement)
local veh = createVehicle(551, x,y,z)
warpPedIntoVehicle(hitElement,veh)
end
end
end
addEventHandler("onMarkerHit",vehMark,vehicleSpawner)

See Also

Vehicle Functions