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

This page is incomplete! Help wanted!

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.

Syntax

createVehicle ( )

Code Examples

server

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