Vehicle (tm.vehicle)
Client side only. Seat, door, tire and bone queries, plus a spawn helper. Positions can be vectors or plain { x, y, z } tables.
Seats
| Call | Returns |
|---|---|
getSeatPedIsIn(ped, vehicle?) | The seat index the ped sits in (-1 driver, 0 front passenger, 1 and up rear), or nil when it is not in a vehicle. Pass vehicle to check a specific one. |
getSeatBoneIndex(vehicle, seat) | The bone index of a seat, falling back to the generic seat_f and seat_r bones bikes use. nil when none exists. |
findFirstFreeVehicleSeat(vehicle) | The first empty seat index (driver first), or nil when full. |
isVehicleOccupied(vehicle) | true when any seat has an occupant. |
getClosestSeat(coords, vehicle, mustBeEmpty?) | Closest seat index and its distance. With mustBeEmpty, seats with a living occupant are skipped. |
Nearby vehicles
| Call | Returns |
|---|---|
getFacingVehicle(ped, maxDist?, ignoreLos?) | The vehicle in front of the ped within maxDist (default 5.0), plus the hit position and distance. Three rays fan out along the ped's facing direction and the nearest hit wins. Walls block the rays unless ignoreLos is true. Returns nothing while the ped is in a vehicle. |
getNearestVehicle(coords, maxDist?, filter?) | The nearest vehicle and its distance. filter is a vehicle handle to exclude, or a function that returns false for vehicles to skip. |
Doors and tires
| Call | Returns |
|---|---|
getClosestDoor(coords, vehicle, enterable?, handles?) | The closest door bone name (for example 'door_dside_f'), the distance and the bone position. enterable limits it to the four passenger doors. handles measures to the door handle bones where the model has them. |
isVehicleDoorOpen(vehicle, doorIndex) | true when the door is open, broken off or does not exist. |
getNearestTire(coords, vehicle) | The closest wheel index and its distance. |
Bones and engine
| Call | Returns |
|---|---|
doesVehicleHaveBone(vehicle, boneName) | true when the model has the bone. |
doesVehicleHaveEngine(vehicle) | true when the model has an engine, engine_l or engine_r bone. |
getVehicleEngineDoor(vehicle) | 'bonnet' for a front engine, 'boot' for a rear one, nil when unknown. |
isVehicleEngineVisible(vehicle) | true when the door over the engine is open far enough, plus that door's bone name. |
Spawning
create(model, x, y, z, heading, isNetwork?, isMissionEntity?, thisScriptCheck?) spawns a vehicle and returns its handle, or false when the model is unknown or not a vehicle, does not load within 10 seconds, or the game refuses to create it. The vehicle is unlocked. Mission entities stay until deleted, others are released to the game. model is a name or a hash. It yields, so call it from a thread.
lua
local vehicle = tm.vehicle.create('adder', 100.0, 200.0, 30.0, 90.0, true, true)Properties
getProperties(vehicle, opts?) and setProperties(vehicle, props, opts?) forward to tm.vehicleprops.get and tm.vehicleprops.set, which load on first use.
Data tables
| Table | Contents |
|---|---|
tm.vehicle.seatNames | Seat index to label (-1 is 'Driver'). |
tm.vehicle.seats | Seat bone name to seat index. |
tm.vehicle.doors | Door bone name to door index (bonnet is 4, boot is 5). |
tm.vehicle.tires | Wheel bone name to wheel index. |