M2O Scripting APIScripting reference
    Preparing search index…
    ClassServer API

    Vehicle

    Replicated M2O vehicle handle.

    Hierarchy

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

      Parameters

      • id: number

        Network entity identifier.

      Returns Vehicle

    • 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.

      Returns void

    • Checks the replicated emergency-beacon state.

      Returns boolean

      True when the beacon is active.

    • Returns the stored primary paint color.

      Returns number

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

    • Returns the stored secondary paint color.

      Returns number

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

    • Reads an accessory from the current replicated control flags.

      Parameters

      • control: number

        Vehicle accessory control identifier.

      Returns boolean

      True when the selected accessory is active.

    • Checks the replicated engine state.

      Returns boolean

      True when the engine is running.

    • Returns the most recently driver-reported engine health.

      Returns number

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

    • Returns the most recently driver-reported fuel amount.

      Returns number

      Current fuel, or -1 before the first report.

    • Returns the driver-reported fuel tank max capacity.

      Returns number

      Tank capacity, or -1 before the first report.

    • Checks the replicated hazard-light state.

      Returns boolean

      True when both turn indicators are active.

    • Checks the replicated left-indicator state.

      Returns boolean

      True when the left indicator is active.

    • Checks the replicated headlight state.

      Returns boolean

      True when either low or high beams are active.

    • Checks the stored visibility state of one vehicle part.

      Parameters

      • index: number

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

      Returns boolean

      True when the part is visible.

    • Checks the replicated right-indicator state.

      Returns boolean

      True when the right indicator is active.

    • Returns the stored model name for one wheel group.

      Parameters

      • index: number

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

      Returns string

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

    • Returns the stored damage state of one wheel.

      Parameters

      • index: number

        Vehicle wheel index.

      Returns number

      A numeric VehicleWheelState value.

    • Checks the stored windshield-wiper state.

      Returns boolean

      True when the wipers are active.

    • 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.

      Returns void

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

      Parameters

      • r: number

        Primary red component from 0 through 255.

      • g: number

        Primary green component from 0 through 255.

      • b: number

        Primary blue component from 0 through 255.

      Returns void

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

      Parameters

      • r: number

        Secondary red component from 0 through 255.

      • g: number

        Secondary green component from 0 through 255.

      • b: number

        Secondary blue component from 0 through 255.

      Returns void

    • Changes an accessory control. A driver applies the command natively; otherwise the server updates replicated state directly.

      Parameters

      • control: number

        Vehicle accessory control identifier.

      • action: 0 | 1 | 2

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

      Returns void

    • Sets and replicates the vehicle's dirt level.

      Parameters

      • level: number

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

      Returns void

    • Sets the vehicle engine state.

      Parameters

      • enabled: boolean

        True to start the engine; false to stop it.

      Returns void

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

      Parameters

      • health: number

        Engine health from 0 for destroyed to 100 for perfect.

      Returns void

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

      Parameters

      • fuel: number

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

      Returns void

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

      Parameters

      • locked: boolean

        True for fully locked; false for unlocked.

      Returns void

    • Sets the server-authoritative vehicle entry lock state.

      Parameters

      • state: number

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

      Returns void

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

      Parameters

      • index: number

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

      • enabled: boolean

        Whether the selected part is visible.

      Returns void

    • Sets and replicates the vehicle's license-plate text.

      Parameters

      • text: string

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

      Returns void

    • Locks or unlocks driver-controlled radio station changes.

      Parameters

      • locked: boolean

        Whether the driver is prevented from changing station.

      Returns void

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

      Parameters

      • station: number

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

      Returns void

    • Enables or disables the vehicle speed limiter on all clients.

      Parameters

      • enabled: boolean

        Whether the native server-controlled speed limiter is active.

      Returns void

    • Sets and replicates the vehicle speed-limiter threshold.

      Parameters

      • kmh: number

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

      Returns void

    • Sets and replicates the vehicle's visual tuning level.

      Parameters

      • level: number

        Tuning level from 0 for stock through 3.

      Returns void

    • Parameters

      • world: number

      Returns void

    • Parameters

      • player: Entity | null

      Returns void

    • Sets the vehicle wanted icon shown to its current driver.

      Parameters

      • level: number

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

      Returns void

    • Sets and replicates the model used by one wheel group.

      Parameters

      • index: number

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

      • name: string

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

      Returns void

    • Sets and replicates the damage state of one wheel.

      Parameters

      • index: number

        Vehicle wheel index.

      • state: number

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

      Returns void

    • Sets and replicates the vehicle's windshield wipers.

      Parameters

      • enabled: boolean

        Whether the windshield wipers are active.

      Returns void

    • Returns a readable representation of this vehicle.

      Returns string

      The vehicle ID and model formatted for logging or debugging.

    • Spawns and replicates a new vehicle.

      Parameters

      • modelId: number

        Mafia II vehicle model identifier.

      • Optionalposition: Partial<Vector3>

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

      • Optionalrotation: Vector3 | Quaternion

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

      Returns Vehicle

      The newly spawned vehicle handle.

    beacon: boolean

    Whether the replicated emergency beacon is on.

    color: number

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

    colorSecondary: number

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

    destroyed: boolean

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

    dirt: number

    Stored dirt level from 0 through 100.

    engine: boolean

    Whether the replicated engine state is on.

    engineHealth: number

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

    fuel: number

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

    fuelCapacity: number

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

    hazard: boolean

    Whether both replicated turn indicators are on as hazard lights.

    hood: boolean

    Whether the replicated hood is open.

    horn: boolean

    Whether the replicated horn is active.

    id: number
    leftIndicator: boolean

    Whether the replicated left turn indicator is on.

    lights: boolean

    Whether either replicated headlight beam is on.

    lockState: number

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

    model: number

    Mafia II vehicle model identifier used when this vehicle was spawned.

    position: Vector3
    radioStation: number

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

    rightIndicator: boolean

    Whether the replicated right turn indicator is on.

    rotation: Vector3 | Quaternion
    siren: boolean

    Whether the replicated siren is on.

    speedLimiter: boolean

    Whether the server-controlled native speed limiter is enabled.

    speedLimiterSpeed: number

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

    trunk: boolean

    Whether the replicated trunk is open.

    tuning: number

    Stored tuning level from 0 for stock through 3.

    virtualWorld: number
    wheelModels: string[]

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

    wheelStates: number[]

    Stored VehicleWheelState value for every wheel.

    wipers: boolean

    Whether the windshield wipers are active.