Skip to content
M2O Scripting APIScripting reference
Runtime classServer APIGenerated

Vehicle

Defined in: server/api.d.ts:310

Replicated M2O vehicle handle.

new Vehicle(id): Vehicle

Defined in: server/api.d.ts:315

Creates a script wrapper for an existing vehicle with this ID; use Vehicle.spawn() to spawn a vehicle.

number

Network entity identifier.

Vehicle

Entity.constructor

attachPart(index): void

Defined in: server/api.d.ts:826

Puts a previously torn-off deform part back on the body on every client.

number

Model-specific deform-part index from 0 through 63.

void


breakLight(index): void

Defined in: server/api.d.ts:845

Smashes one headlight on every client.

number

Headlight index from 0 through 31.

void


clearRadio(): void

Defined in: server/api.d.ts:898

Turns off this vehicle’s in-car radio.

void


clearWantedLevel(): void

Defined in: server/api.d.ts:760

Clears the vehicle wanted icon for its current driver.

void


destroy(): void

Defined in: server/api.d.ts:476

Destroys this replicated vehicle after emitting vehicleDestroy.

void


detachPart(index): void

Defined in: server/api.d.ts:820

Tears one deform part off the body on every client. Silent: no debris, sound or impulse.

number

Model-specific deform-part index from 0 through 63.

void


explode(): void

Defined in: server/api.d.ts:749

Blows the vehicle up on every client with the native explosion, killing its occupants, and marks it destroyed until repair(). Emits vehicleExplode with a null attacker.

void


getBeacon(): boolean

Defined in: server/api.d.ts:585

Checks the replicated emergency-beacon state.

boolean

True when the beacon is active.


getColor(): number

Defined in: server/api.d.ts:632

Returns the stored primary paint color.

number

Packed 0x00RRGGBB, or -1 when the model default is used.


getColorSecondary(): number

Defined in: server/api.d.ts:646

Returns the stored secondary paint color.

number

Packed 0x00RRGGBB, or -1 when the model default is used.


getControl(control): boolean

Defined in: server/api.d.ts:490

Reads an accessory from the current replicated control flags.

number

Vehicle accessory control identifier.

boolean

True when the selected accessory is active.


getDirt(): number

Defined in: server/api.d.ts:675

Returns the stored dirt level.

number

A value from 0 through 100.


getEngine(): boolean

Defined in: server/api.d.ts:507

Checks the server-held engine state.

boolean

True when the engine is commanded on.


getEngineHealth(): number

Defined in: server/api.d.ts:887

Returns the most recently driver-reported engine health.

number

Health from 0 through 100, or -1 before the first report.


getEngineLocked(): boolean

Defined in: server/api.d.ts:519

Checks whether the engine is locked.

boolean

True when the engine is locked.


getFuel(): number

Defined in: server/api.d.ts:869

Returns the most recently driver-reported fuel amount.

number

Current fuel, or -1 before the first report.


getFuelCapacity(): number

Defined in: server/api.d.ts:875

Returns the driver-reported fuel tank max capacity.

number

Tank capacity, or -1 before the first report.


getHazard(): boolean

Defined in: server/api.d.ts:563

Checks the replicated hazard-light state.

boolean

True when both turn indicators are active.


getHood(): boolean

Defined in: server/api.d.ts:607

Checks the replicated hood state.

boolean

True when the hood is open.


getHorn(): boolean

Defined in: server/api.d.ts:596

Checks the replicated horn state.

boolean

True while the horn is active.


getLeftIndicator(): boolean

Defined in: server/api.d.ts:541

Checks the replicated left-indicator state.

boolean

True when the left indicator is active.


getLightCount(): number

Defined in: server/api.d.ts:832

Returns how many headlights this vehicle model has.

number

The light count, or 0 until a client has reported the model’s part table.


getLights(): boolean

Defined in: server/api.d.ts:530

Checks the replicated headlight state.

boolean

True when either low or high beams are active.


getPart(index): boolean

Defined in: server/api.d.ts:780

Checks the stored visibility state of one vehicle part.

number

Model-specific deform-part index from 0 through 63.

boolean

True when the part is visible.


getPartCount(): number

Defined in: server/api.d.ts:786

Returns how many deform parts this vehicle model has.

number

The part count, or 0 until a client has reported the model’s part table.


getPartsOfType(type): number[]

Defined in: server/api.d.ts:800

Lists the deform-part indices of one part type on this vehicle model.

number

A VehiclePartType value, such as VehiclePartType.Wheel.

number[]

Matching part indices, empty when the model’s part table is unknown.


getPartStage(index): number

Defined in: server/api.d.ts:814

Returns the driver-reported damage stage of one deform part.

number

Model-specific deform-part index from 0 through 63.

number

The damage stage from 0 for undamaged through 3.


getPartType(index): number

Defined in: server/api.d.ts:793

Returns the VehiclePartType of one deform part.

number

Model-specific deform-part index.

number

A numeric VehiclePartType value, or -1 when the index or the model is unknown.


getRightIndicator(): boolean

Defined in: server/api.d.ts:552

Checks the replicated right-indicator state.

boolean

True when the right indicator is active.


getSiren(): boolean

Defined in: server/api.d.ts:574

Checks the replicated siren state.

boolean

True when the siren is active.


getTrunk(): boolean

Defined in: server/api.d.ts:618

Checks the replicated trunk state.

boolean

True when the trunk is open.


getWheelModel(index): string

Defined in: server/api.d.ts:713

Returns the stored model name for one wheel group.

number

Wheel group: 0 front, 1 rear, or 2 spare.

string

The wheel model name, or an empty string when the default is used.


getWheelState(index): number

Defined in: server/api.d.ts:727

Returns the damage state of one wheel: the driver’s live report while the vehicle is occupied, otherwise the last value reported or set.

number

Vehicle wheel index.

number

A numeric VehicleWheelState value.


getWipers(): boolean

Defined in: server/api.d.ts:693

Checks the stored windshield-wiper state.

boolean

True when the wipers are active.


isLightBroken(index): boolean

Defined in: server/api.d.ts:839

Checks whether one headlight is smashed.

number

Headlight index from 0 through 31.

boolean

True when the headlight is broken.


isPartDropped(index): boolean

Defined in: server/api.d.ts:807

Checks whether one deform part has been torn off the body.

number

Model-specific deform-part index from 0 through 63.

boolean

True when the part is missing.


repair(): void

Defined in: server/api.d.ts:744

Fully repairs native deformation, mechanical and part damage, wheels, paint, and tuning, then stops the vehicle without moving it. Also restores a destroyed (exploded) vehicle.

void


repairLight(index): void

Defined in: server/api.d.ts:851

Restores one smashed headlight. It re-breaks while body deformation still displaces the lamp.

number

Headlight index from 0 through 31.

void


resetColor(): void

Defined in: server/api.d.ts:651

Restores the model’s factory primary paint and broadcasts it to all clients.

void


resetColorSecondary(): void

Defined in: server/api.d.ts:656

Restores the model’s factory secondary paint and broadcasts it to all clients.

void


setColor(r, g, b): void

Defined in: server/api.d.ts:626

Sets the server-authoritative primary paint color and broadcasts it to all clients.

number

Primary red component from 0 through 255.

number

Primary green component from 0 through 255.

number

Primary blue component from 0 through 255.

void


setColorSecondary(r, g, b): void

Defined in: server/api.d.ts:640

Sets the server-authoritative secondary paint color and broadcasts it to all clients.

number

Secondary red component from 0 through 255.

number

Secondary green component from 0 through 255.

number

Secondary blue component from 0 through 255.

void


setControl(control, action): void

Defined in: server/api.d.ts:483

Changes an accessory control. A driver applies the command natively; otherwise the server updates replicated state directly. The engine control behaves like setEngine.

number

Vehicle accessory control identifier.

0 | 1 | 2

Action: 0 turns the control off, 1 turns it on, and 2 toggles it.

void


setDirt(level): void

Defined in: server/api.d.ts:669

Sets and replicates the vehicle’s dirt level.

number

Dirt amount from 0 for clean to 100 for fully dirty.

void


setEngine(enabled): void

Defined in: server/api.d.ts:501

Sets the server-held engine state and applies it on the driver’s client, which has no way to start the engine itself. Starting is ignored while the engine is locked.

boolean

True to start the engine; false to stop it.

void


setEngineHealth(health): void

Defined in: server/api.d.ts:881

Broadcasts a one-shot native engine-health update to every live copy of this vehicle.

number

Engine health from 0 for destroyed to 100 for perfect.

void


setEngineLocked(locked): void

Defined in: server/api.d.ts:513

Locks or unlocks the engine, for car keys and immobilisers. Locking stops the engine and keeps it off; setEngine(true) and toggleEngine are ignored until it is unlocked. Unlocking does not start the engine.

boolean

True to immobilise the vehicle; false to release it.

void


setFuel(fuel): void

Defined in: server/api.d.ts:863

Broadcasts a one-shot fuel update to every live copy of this vehicle.

number

Target native fuel amount; each client clamps it to the vehicle tank.

void


setLocked(locked): void

Defined in: server/api.d.ts:857

Convenience method that sets the entry lock to fully locked or unlocked.

boolean

True for fully locked; false for unlocked.

void


setLockState(state): void

Defined in: server/api.d.ts:766

Sets the server-authoritative vehicle entry lock state.

number

Entry lock state: 0 unlocked, 1 breakable, or 2 fully locked.

void


setModel(modelId): boolean

Defined in: server/api.d.ts:663

Swaps the vehicle’s model while keeping its id, position, cosmetics and fuel. Every client rebuilds the car in place: damage resets and occupants are re-seated where the new model has their seat.

number

Mafia II vehicle model identifier.

boolean

True when the model was applied; false for an unknown model or a destroyed vehicle.


setPart(index, enabled): void

Defined in: server/api.d.ts:773

Shows or hides one model-specific vehicle part on all clients.

number

Model-specific deform-part index from 0 through 63.

boolean

Whether the selected part is visible.

void


setPlate(text): void

Defined in: server/api.d.ts:699

Sets and replicates the vehicle’s license-plate text.

string

License-plate text, limited to six characters by the game.

void


setRadioLocked(locked): void

Defined in: server/api.d.ts:904

Locks or unlocks driver-controlled radio station changes.

boolean

Whether the driver is prevented from changing station.

void


setRadioStation(station): void

Defined in: server/api.d.ts:893

Sets the in-car radio station for this vehicle’s driver.

number

Native radio station identifier; a negative value turns the radio off.

void


setSpeedLimiter(enabled): void

Defined in: server/api.d.ts:733

Enables or disables the vehicle speed limiter on all clients.

boolean

Whether the native server-controlled speed limiter is active.

void


setSpeedLimiterSpeed(kmh): void

Defined in: server/api.d.ts:739

Sets and replicates the vehicle speed-limiter threshold.

number

Maximum speed in kilometres per hour; a negative value restores the model default.

void


setTuning(level): void

Defined in: server/api.d.ts:681

Sets and replicates the vehicle’s visual tuning level.

number

Tuning level from 0 for stock through 3.

void


setVirtualWorld(world): void

Defined in: server/api.d.ts:4154

Moves this entity into another virtual world.

number

Virtual-world identifier used to partition replication and visibility.

void

Entity.setVirtualWorld


setVisibleTo(player): void

Defined in: server/api.d.ts:4160

Restricts replication of this entity to one owning connection while preserving normal range and visibility checks.

Entity | null

Player-owned entity whose connection should exclusively receive this entity, or null to clear the restriction.

void

Entity.setVisibleTo


setWantedLevel(level): void

Defined in: server/api.d.ts:755

Sets the vehicle wanted icon shown to its current driver.

number

Non-zero native vehicle wanted-icon level; zero hides the icon.

void


setWheelModel(index, name): void

Defined in: server/api.d.ts:706

Sets and replicates the model used by one wheel group.

number

Wheel group: 0 front, 1 rear, or 2 spare.

string

Wheel model name; an empty string restores the vehicle model default.

void


setWheelState(index, state): void

Defined in: server/api.d.ts:720

Sets and replicates the damage state of one wheel.

number

Vehicle wheel index.

number

Damage state from VehicleWheelState: Normal, Deflated, or BlownOut.

void


setWipers(enabled): void

Defined in: server/api.d.ts:687

Sets and replicates the vehicle’s windshield wipers.

boolean

Whether the windshield wipers are active.

void


toggleBeacon(): void

Defined in: server/api.d.ts:579

Toggles the vehicle emergency beacon.

void


toggleEngine(): void

Defined in: server/api.d.ts:495

Toggles the server-held engine state. Ignored while the engine is locked.

void


toggleHazard(): void

Defined in: server/api.d.ts:557

Toggles both turn indicators as hazard lights.

void


toggleHood(): void

Defined in: server/api.d.ts:601

Toggles the vehicle hood between open and closed.

void


toggleHorn(): void

Defined in: server/api.d.ts:590

Toggles the vehicle horn.

void


toggleLeftIndicator(): void

Defined in: server/api.d.ts:535

Toggles the left turn indicator.

void


toggleLights(): void

Defined in: server/api.d.ts:524

Toggles the vehicle headlights.

void


toggleRightIndicator(): void

Defined in: server/api.d.ts:546

Toggles the right turn indicator.

void


toggleSiren(): void

Defined in: server/api.d.ts:568

Toggles the vehicle siren.

void


toggleTrunk(): void

Defined in: server/api.d.ts:612

Toggles the vehicle trunk between open and closed.

void


toString(): string

Defined in: server/api.d.ts:471

Returns a readable representation of this vehicle.

string

The vehicle ID and model formatted for logging or debugging.

Entity.toString


static spawn(model, position?, rotation?): Vehicle

Defined in: server/api.d.ts:913

Spawns and replicates a new vehicle.

string | number

A vehicle model id, or a model name: a stock car, or the file name of a car .sds a resource ships in stream/sds/cars/.

Partial<Vector3>

Optional initial world-space position; omitted components default to zero.

Vector3 | Quaternion

Optional initial orientation: a Quaternion, or a Vector3 of Euler angles in degrees.

Vehicle

The newly spawned vehicle handle.

readonly beacon: boolean

Defined in: server/api.d.ts:450

Whether the replicated emergency beacon is on.


readonly brokenLights: number[]

Defined in: server/api.d.ts:375

Headlight indices that are currently smashed.


readonly color: number

Defined in: server/api.d.ts:330

Packed primary paint color 0x00RRGGBB, or -1 for the model default.


readonly colorSecondary: number

Defined in: server/api.d.ts:335

Packed secondary paint color 0x00RRGGBB, or -1 for the model default.


readonly destroyed: boolean

Defined in: server/api.d.ts:410

Whether the vehicle has been blown up and not repaired since.


readonly dirt: number

Defined in: server/api.d.ts:345

Stored dirt level from 0 through 100.


readonly droppedParts: number[]

Defined in: server/api.d.ts:370

Deform-part indices that have been torn off this vehicle.


readonly engine: boolean

Defined in: server/api.d.ts:415

Whether the server-held engine state is on.


readonly engineHealth: number

Defined in: server/api.d.ts:405

Most recently driver-reported engine health from 0 through 100, or -1 before the first report.


readonly engineLocked: boolean

Defined in: server/api.d.ts:420

Whether the engine is locked (immobilised).


readonly fuel: number

Defined in: server/api.d.ts:395

Most recently driver-reported fuel amount, or -1 before the first report.


readonly fuelCapacity: number

Defined in: server/api.d.ts:400

Driver-reported fuel tank max capacity, or -1 before the first report.


readonly hasCustomColor: boolean

Defined in: server/api.d.ts:340

Whether a script paint overrides the primary or secondary factory color.


readonly hazard: boolean

Defined in: server/api.d.ts:440

Whether both replicated turn indicators are on as hazard lights.


readonly hood: boolean

Defined in: server/api.d.ts:460

Whether the replicated hood is open.


readonly horn: boolean

Defined in: server/api.d.ts:455

Whether the replicated horn is active.


readonly id: number

Defined in: server/api.d.ts:4122

Immutable network entity identifier.

Entity.id


readonly leftIndicator: boolean

Defined in: server/api.d.ts:430

Whether the replicated left turn indicator is on.


readonly lights: boolean

Defined in: server/api.d.ts:425

Whether either replicated headlight beam is on.


readonly lockState: number

Defined in: server/api.d.ts:325

Entry lock state: 0 unlocked, 1 breakable, or 2 fully locked.


readonly model: number

Defined in: server/api.d.ts:320

Mafia II vehicle model identifier; changed with setModel.


position: Vector3

Defined in: server/api.d.ts:4132

Authoritative world-space position; assignment forces replicated state.

Entity.position


readonly radioStation: number

Defined in: server/api.d.ts:390

Stored native radio station ID; 255 represents unset or off.


readonly rightIndicator: boolean

Defined in: server/api.d.ts:435

Whether the replicated right turn indicator is on.


rotation: Vector3 | Quaternion

Defined in: server/api.d.ts:4137

Authoritative rotation; reads return a quaternion and assignments accept a quaternion or Euler angles in degrees.

Entity.rotation


readonly siren: boolean

Defined in: server/api.d.ts:445

Whether the replicated siren is on.


readonly speedLimiter: boolean

Defined in: server/api.d.ts:380

Whether the server-controlled native speed limiter is enabled.


readonly speedLimiterSpeed: number

Defined in: server/api.d.ts:385

Speed-limiter threshold in kilometres per hour, or a negative model-default value.


readonly state: StateBag

Defined in: server/api.d.ts:4142

Arbitrary key/value state carried by this entity. The server writes it and every client that can see the entity receives it; see StateBag.

Entity.state


readonly trunk: boolean

Defined in: server/api.d.ts:465

Whether the replicated trunk is open.


readonly tuning: number

Defined in: server/api.d.ts:350

Stored tuning level from 0 for stock through 3.


readonly virtualWorld: number

Defined in: server/api.d.ts:4127

Current virtual-world identifier.

Entity.virtualWorld


readonly wheelModels: string[]

Defined in: server/api.d.ts:360

Stored model names for the front, rear, and spare wheel groups.


readonly wheelStates: number[]

Defined in: server/api.d.ts:365

VehicleWheelState value for every wheel, reported live by the driver while the vehicle is occupied.


readonly wipers: boolean

Defined in: server/api.d.ts:355

Whether the windshield wipers are active.