A vehicle on the client.

var car = Vehicle.create("adder", spawnPoint, 90.0, true);
car.plate = "HAXE 01";
car.setColours(12, 12);
car.lockState = Locked;

Everything here writes through to the game immediately. On a networked vehicle you don't own, those writes are reverted by the real owner within a frame or two — call requestControl() first, or make the change on the server.

Static methods

@:value({ networked : true, heading : 0.0 })staticcreate(model:Hash, position:Vector3, heading:Float = 0.0, networked:Bool = true):Vehicle

Spawns a vehicle, streaming its model in first.

Blocks the calling coroutine until the model is ready, and returns null if the model is invalid or failed to load.

Parameters:

networked

Whether other players can see it. A local vehicle is cheaper but exists on this client only.

Constructor

new(handle:Int)

Variables

bodyHealth:Float

Bodywork condition, 0 to 1000.

dirtLevel:Float

Dirt level, 0 (clean) to 15 (filthy).

read onlydisplayName:String

The in-game display name, e.g. "ADDER".

read onlydriver:Ped

The ped in the driver's seat, or null.

engineHealth:Float

Engine condition from -4000 (destroyed) to 1000 (perfect).

fuel:Float

Fuel level, 0 to 100.

The base game barely uses this — it refills whenever the vehicle is re-created and doesn't drain on its own. Fuel scripts read and write it on a timer rather than relying on the game.

read onlyisDriveable:Bool

livery:Int

read onlypassengerCount:Int

plate:String

The licence plate text.

plateStyle:Int

The plate's background style, 0–5.

read onlyseatCount:Int

How many seats the vehicle has, including the driver's.

tankHealth:Float

Fuel tank condition, 0 to 1000. Below ~750 the vehicle leaks and can explode.

read onlyvehicleClass:Int

The vehicle's class index — 0 compacts, 7 sports, 18 emergency, and so on.

Methods

@:value({ instantly : false })inlinecloseDoor(door:VehicleDoor, instantly:Bool = false):Void

colours():{secondary:Int, primary:Int}

The primary and secondary paint indices.

inlinedoorAngle(door:VehicleDoor):Float

How far open a door is, 0 (shut) to 1 (fully open).

firstFreeSeat():Null<VehicleSeat>

The lowest-numbered empty seat, or null if the vehicle is full.

inlinegetMod(modType:Int):Int

inlinehasExtra(extraId:Int):Bool

inlineisSeatFree(seat:VehicleSeat):Bool

markAsPlayerOwned():Void

Marks the vehicle as already owned so it doesn't need hotwiring and won't be reported stolen — what you want for a vehicle a player just took out of their own garage.

occupantIn(seat:VehicleSeat):Ped

The ped in seat, or null if it is empty.

occupants():Array<Ped>

Every ped currently aboard, driver included.

@:value({ instantly : false })inlineopenDoor(door:VehicleDoor, instantly:Bool = false):Void

inlineplaceOnGround():Bool

Drops the vehicle onto its wheels at its current position.

repair():Void

Repairs bodywork, engine and deformation, and restores full health.

inlinesetColours(primary:Int, secondary:Int):Void

setCustomColours(primary:Rgba, ?secondary:Rgba):Void

Paints the vehicle an arbitrary RGB colour, bypassing the game's palette.

inlinesetExtra(extraId:Int, enabled:Bool):Void

Toggles a numbered extra (roof racks, spoilers, decals — model specific).

inlinesetExtraColours(pearlescent:Int, wheel:Int):Void

@:value({ customTyres : false })setMod(modType:Int, modIndex:Int, customTyres:Bool = false):Void

Fits a modification.

The mod kit has to be selected before any mod will apply, which is what SET_VEHICLE_MOD_KIT(0) does — easy to miss, and the reason mods "silently don't work" so often. This does it for you.

Inherited Variables

Defined by Entity

alpha:Int

Opacity from 0 (invisible) to 255.

read onlyattachedTo:Entity

The entity this one is attached to, or null.

write onlycollision:Bool

read onlyexists:Bool

read onlyforwardVector:Vector3

The unit vector the entity faces.

write onlyfrozen:Bool

Whether the entity is pinned in place. Write-only — the game exposes no getter.

finalhandle:Int

The raw game handle.

read onlyhasControl:Bool

Whether this client currently owns the entity. Only the owner may modify a networked entity and have the change replicate.

heading:Float

Yaw only, in degrees — 0 faces north.

health:Int

read onlyheightAboveGround:Float

write onlyinvincible:Bool

read onlyisAttached:Bool

read onlyisDead:Bool

read onlyisNetworked:Bool

read onlymaxHealth:Int

read onlymodel:Int

The model hash this entity was created from.

read onlynetId:Int

The network ID, stable across all clients — the value to send in events. Returns 0 for a purely local entity.

write onlyoutline:Bool

Draws the game's selection outline around the entity.

rotation:Vector3

Rotation in degrees as (pitch, roll, yaw).

read onlyspeed:Float

Current speed in metres per second. Multiply by 3.6 for km/h, 2.237 for mph.

read onlystate:StateBag

The entity's replicated state bag. Reads work on any client; writes only replicate from the server.

read onlytype:EntityType

visible:Bool

Inherited Methods

Defined by Entity

@:value({ collision : false, bone : 0 })attachTo(target:Entity, offset:Vector3, rotation:Vector3, bone:Int = 0, collision:Bool = false):Void

Attaches this entity to target, offset from one of its bones.

Parameters:

bone

Bone index on the target; 0 attaches to its origin.

collision

Whether the two keep colliding with each other.

delete():Void

Deletes the entity.

Requires ownership: on a networked entity this silently does nothing unless requestControl() succeeded first.

@:value({ collision : true, keepVelocity : true })inlinedetach(keepVelocity:Bool = true, collision:Bool = true):Void

inlinedistanceTo(point:Vector3):Float

inlinedistanceToEntity(other:Entity):Float

@:value({ flags : 17 })inlinehasClearLineOfSightTo(other:Entity, flags:Int = 17):Bool

Whether nothing solid sits between this entity and other.

inlinemarkAsNoLongerNeeded():Void

Releases the entity back to the game, which may then despawn it.

inlineoffsetInWorldCoords(offset:Vector3):Vector3

Converts a position expressed in the entity's own frame into world space.

@:value({ timeoutMs : 1000 })requestControl(timeoutMs:Int = 1000):Bool

Asks the server for ownership and waits for it, returning whether it was granted before timeoutMs elapsed.

Every write to a networked entity you don't own is silently reverted by its real owner, so call this first:

if (vehicle.requestControl()) vehicle.repair();

Must be called from inside a coroutine. Ownership can be lost again at any moment, so keep the work that follows short.

@:value({ grabFromOtherScript : true })inlinesetAsMission(grabFromOtherScript:Bool = true):Void

Claims the entity for this script, so the game's population manager won't clean it up while you're using it.

teleport(position:Vector3, ?heading:Float):Void

Moves the entity without the game's usual "find a valid spot" fixups — no ground snapping, no pushing out of collision. Use it when you have already worked out exactly where the entity belongs.

toString():String

inlineworldToLocal(worldPosition:Vector3):Vector3

The inverse of offsetInWorldCoords: world space into the entity's frame.