createVehicle | Multi Theft Auto: Wiki Skip to content

createVehicle

Client-side
Server-side
Shared

This function creates a vehicle at the specified location.

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.

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.

It's worth nothing that the position of the vehicle is the center point of the vehicle, not its base. As such, you need to ensure that the z value (vertical axis) is some height above the ground. You can find the exact height using the client side function getElementDistanceFromCentreOfMassToBaseOfModel, or you can estimate it yourself and just spawn the vehicle so it drops to the ground.

OOP Syntax Help! I don't understand this!

Syntax

vehicle|false createVehicle ( int model, float x, float y, float z, [ float rx = 0, float ry = 0, float rz = 0, string numberplate = random, boolean bDirection = false, int variant1 = random, int variant2 = random, boolean 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.
Optional Arguments

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

  • rx (default: 0): A floating point number representing the rotation about the X axis in degrees.
  • ry (default: 0): A floating point number representing the rotation about the Y axis in degrees.
  • rz (default: 0): A floating point number representing the rotation about the Z axis in degrees.
  • numberplate (default: random): A string representing the vehicle's number plate. If not specified, the vehicle will have a random number plate.
  • bDirection (default: false): (Serverside only): 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 next variant1 argument in its place.
  • variant1 (default: random): An integer for the first vehicle variant. See vehicle variants.
  • variant2 (default: random): An integer for the second vehicle variant. See vehicle variants.
  • synced (default: true): (Serverside only): A boolean value representing whether or not the vehicle will be synced. Disabling the sync might be useful for frozen or static vehicles to increase the server performance.

Returns

  • vehicle|false: theVehicle

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

server - Create Vehicle using Constructor Class
OOP Required

Creates a vehicle using the OOP syntax. This example creates a vehicle at the specified position and with the specified rotation.

function makeVehicle(model, x, y, z, rx, ry, rz)
assert(type(model)=="number", "Model must be a number")
assert(type(x)=="number", "X coordinate must be a number")
assert(type(y)=="number", "Y coordinate must be a number")
assert(type(z)=="number", "Z coordinate must be a number")
if not rx then rx = 0 end
if not ry then ry = 0 end
if not rz then rz = 0 end
assert(type(rx)=="number", "Rotation X must be a number")
assert(type(ry)=="number", "Rotation Y must be a number")
assert(type(rz)=="number", "Rotation Z must be a number")
return Vehicle(model, x, y, z, rx, ry, rz)
end

See Also

Vehicle Functions