A vehicle on the server.

var car = Vehicle.create("adder", spawnPoint, 90.0);
car.plate = "HX 001";
car.state.set("ownerLicense", license);
player.ped.warpIntoVehicle(car);

Creating a vehicle server-side is the right default for anything persistent: it exists whether or not any particular client is nearby, it survives that client disconnecting, and it can't be spoofed by a modified client.

Static methods

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

Spawns a vehicle.

Blocks the calling coroutine until the vehicle is networked, because a server-created entity is orphaned until a client comes into scope and has no network ID before then. Returns null if that never happens within the timeout — which in practice means nobody was near the spawn point, or the model was not a vehicle.

@:value({ heading : 0.0 })staticcreateWithSetter(model:Hash, vehicleType:String, position:Vector3, heading:Float = 0.0):Vehicle

Spawns a vehicle using the server setter, which creates the entity without needing a client nearby to own it.

Parameters:

vehicleType

The category: "automobile", "bike", "boat", "heli", "plane", "submarine", "trailer", "train". Getting this wrong produces a vehicle that never spawns properly, so it must match the model.

Constructor

new(handle:Int)

Variables

write onlyalarm:Bool

dirtLevel:Float

read onlydriver:Ped

The ped currently driving, or null.

read onlyengineHealth:Float

Engine condition, -4000 to 1000.

Read-only: FXServer exposes no engine-health setter, because engine damage is simulated by the client that owns the vehicle. To repair one, tell that client (Net.emitClient(..., vehicle.owner, ...)) and have it call repair() on its own fivem.client.core.Vehicle.

read onlyengineRunning:Bool

plate:String

read onlysirenOn:Bool

read onlyvehicleType:String

The vehicle's category as a string: "automobile", "heli", "boat", ...

Methods

lastOccupantIn(seat:Int):Ped

The last ped to occupy seat, even after they got out.

occupantIn(seat:Int):Ped

The ped in seat (-1 is the driver), or null.

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

Inherited Variables

Defined by Entity

read onlyattachedTo:Entity

The entity this one is attached to, or null.

read onlycreatorResource:String

The resource that created the entity, if any.

read onlyexists:Bool

frozen:Bool

finalhandle:Int

The server-side entity handle.

heading:Float

read onlyhealth:Int

Current health. Read-only on the server — health is simulated by the owning client, so setting it means sending that client an event.

read onlymaxHealth:Int

read onlymodel:Int

read onlynetId:Int

The network ID — the entity reference to send to clients — or 0 if the entity has none yet.

Guarded, because the underlying native raises rather than returning a sentinel:

script error in native ...: Tried to access invalid entity: 131333

An entity the server just created is orphaned until a client comes into scope for it: it has a handle, but no network ID and no owner. A stale handle behaves the same way. Both cases read as 0 here instead of taking down the handler that asked.

The existence check alone is not sufficient — the native has been reported to raise even when DoesEntityExist says otherwise — so the call itself is also caught.

read onlyowner:Int

The server ID of the client that currently owns this entity, or -1 when nobody does.

Ownership decides which client simulates the entity, and therefore who must be told to change its health, tasks or physics.

rotation:Vector3

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

routingBucket:Int

The routing bucket this entity lives in.

Buckets are the server's instancing mechanism: entities and players in different buckets can't see or interact with each other at all. Bucket 0 is the default world.

read onlyspeed:Float

Speed in metres per second.

read onlystate:StateBag

The entity's replicated state bag.

read onlytype:EntityType

Inherited Methods

Defined by Entity

delete():Void

Deletes the entity. Unlike on the client this always works — the server is authoritative and doesn't need to negotiate ownership first.

inlinedistanceTo(point:Vector3):Float

inlinedistanceToEntity(other:Entity):Float

toString():String

@:value({ timeoutMs : 5000 })waitUntilNetworked(timeoutMs:Int = 5000):Bool

Blocks until the entity is registered on the server and has a network ID, returning whether it got one before timeoutMs elapsed.

Server-created entities do not exist immediately — they stay orphaned until a client is in scope. Anything that needs the network ID (sending it to a client, writing a state bag) has to wait for this first, which is what the create helpers do for you.

Returns false if no client ever comes into scope, or if the model was not valid for the entity type.