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:848

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:867

Smashes one headlight on every client.

number

Headlight index from 0 through 31.

void


clearRadio(): void

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

Turns off this vehicle’s in-car radio.

void


clearWantedLevel(): void

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

Clears the vehicle wanted icon for its current driver.

void


destroy(): void

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

Destroys this replicated vehicle after emitting vehicleDestroy.

void


detachPart(index): void

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

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:771

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:590

Checks the replicated emergency-beacon state.

boolean

True when the beacon is active.


getColor(): number

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

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:651

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:495

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:680

Returns the stored dirt level.

number

A value from 0 through 100.


getEngine(): boolean

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

Checks the server-held engine state.

boolean

True when the engine is commanded on.


getEngineHealth(): number

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

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:524

Checks whether the engine is locked.

boolean

True when the engine is locked.


getFuel(): number

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

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:897

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:568

Checks the replicated hazard-light state.

boolean

True when both turn indicators are active.


getHood(): boolean

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

Checks the replicated hood state.

boolean

True when the hood is open.


getHorn(): boolean

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

Checks the replicated horn state.

boolean

True while the horn is active.


getLeftIndicator(): boolean

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

Checks the replicated left-indicator state.

boolean

True when the left indicator is active.


getLightCount(): number

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

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:535

Checks the replicated headlight state.

boolean

True when either low or high beams are active.


getPart(index): boolean

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

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:808

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:822

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:836

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:815

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:557

Checks the replicated right-indicator state.

boolean

True when the right indicator is active.


getSiren(): boolean

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

Checks the replicated siren state.

boolean

True when the siren is active.


getTrunk(): boolean

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

Checks the replicated trunk state.

boolean

True when the trunk is open.


getTuningVisuals(): boolean

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

Checks whether the tuning kit is shown, from the override or the native rule.

boolean

True when the tuning kit is visible.


getWheelModel(index): string

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

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:749

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:715

Checks the stored windshield-wiper state.

boolean

True when the wipers are active.


isLightBroken(index): boolean

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

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:829

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:766

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:873

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:656

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

void


resetColorSecondary(): void

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

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

void


resetTuningVisuals(): void

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

Returns the tuning kit to the native rule: shown at tuning level 3 only.

void


setColor(r, g, b): void

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

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:645

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:488

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:674

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:506

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:903

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:518

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:885

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:879

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:788

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:668

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:795

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:721

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:926

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:915

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:755

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:761

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:686

Sets and replicates the vehicle’s performance tuning level. Only level 3 shows the tuning kit (blower, exhaust) unless overridden with setTuningVisuals.

number

Tuning level from 0 for stock through 3.

void


setTuningVisuals(enabled): void

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

Shows or hides the tuning kit independently of the performance tuning level, and replicates it.

boolean

Whether the tuning kit (blower, tuned exhaust, body panels) is shown.

void


setVirtualWorld(world): void

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

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:4377

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:777

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:728

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:742

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:709

Sets and replicates the vehicle’s windshield wipers.

boolean

Whether the windshield wipers are active.

void


toggleBeacon(): void

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

Toggles the vehicle emergency beacon.

void


toggleEngine(): void

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

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

void


toggleHazard(): void

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

Toggles both turn indicators as hazard lights.

void


toggleHood(): void

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

Toggles the vehicle hood between open and closed.

void


toggleHorn(): void

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

Toggles the vehicle horn.

void


toggleLeftIndicator(): void

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

Toggles the left turn indicator.

void


toggleLights(): void

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

Toggles the vehicle headlights.

void


toggleRightIndicator(): void

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

Toggles the right turn indicator.

void


toggleSiren(): void

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

Toggles the vehicle siren.

void


toggleTrunk(): void

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

Toggles the vehicle trunk between open and closed.

void


toString(): string

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

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:935

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:455

Whether the replicated emergency beacon is on.


readonly brokenLights: number[]

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

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:415

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:375

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


readonly engine: boolean

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

Whether the server-held engine state is on.


readonly engineHealth: number

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

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:425

Whether the engine is locked (immobilised).


readonly fuel: number

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

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


readonly fuelCapacity: number

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

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:445

Whether both replicated turn indicators are on as hazard lights.


readonly hood: boolean

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

Whether the replicated hood is open.


readonly horn: boolean

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

Whether the replicated horn is active.


readonly id: number

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

Immutable network entity identifier.

Entity.id


readonly leftIndicator: boolean

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

Whether the replicated left turn indicator is on.


readonly lights: boolean

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

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:4349

Authoritative world-space position; assignment forces replicated state.

Entity.position


readonly radioStation: number

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

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


readonly rightIndicator: boolean

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

Whether the replicated right turn indicator is on.


rotation: Vector3 | Quaternion

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

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:450

Whether the replicated siren is on.


readonly speedLimiter: boolean

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

Whether the server-controlled native speed limiter is enabled.


readonly speedLimiterSpeed: number

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

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


readonly state: StateBag

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

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:470

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 tuningVisuals: boolean

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

Whether the tuning kit (blower, tuned exhaust) is shown.


readonly virtualWorld: number

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

Current virtual-world identifier.

Entity.virtualWorld


readonly wheelModels: string[]

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

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


readonly wheelStates: number[]

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

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


readonly wipers: boolean

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

Whether the windshield wipers are active.