Skip to content
M2O Scripting APIScripting reference
Runtime classServer APIGenerated

Player

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

A connected M2O player.

  • Player

new Player(id): Player

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

Creates a script wrapper for an existing connected player with this ID; it does not create a player.

number

Network entity identifier.

Player

addMoney(amount): void

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

Adds cash to this player’s native inventory and HUD counter.

number

Cash amount in dollars to add.

void


clearAnimStyle(): void

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

Removes this player’s animation-style override.

void


clearHandModels(): void

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

Clears this player’s left-hand, right-hand, and mouth prop models.

void


emit(eventName, payloadJson?): void

Defined in: shared.d.ts:96

string

string

void


getAnimStyle(): number

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

Returns the most recently replicated animation-set identifier.

number

The applied animation-set ID, or zero when no override is active.


getCurrentWeapon(): number

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

Returns the most recently replicated held-weapon identifier.

number

The current weapons.tbl row ID; 1 represents fists.


getHealth(): number

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

Returns the most recently owner-reported health value.

number

Current replicated health, including native damage.


getIP(): string

Defined in: shared.d.ts:97

string


getMoney(): number

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

Returns the most recently owner-reported cash balance.

number

Current balance in dollars, including native in-game spending.


getMovementState(): "idle" | "walking" | "running" | "stopping"

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

Returns the player’s current replicated on-foot gait.

"idle" | "walking" | "running" | "stopping"

One of idle, walking, running, or stopping.


getNametagColor(): number

Defined in: shared.d.ts:105

number


getNametagText(): string

Defined in: shared.d.ts:103

string


getVehicle(): Vehicle | null

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

Returns the vehicle currently occupied by this player in any seat.

Vehicle | null

The current vehicle handle, or null when the player is not in a vehicle.


giveAmmo(weaponId, amount): void

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

Changes reserve ammunition for one of this player’s weapons.

number

weapons.tbl row identifier.

number

Reserve ammunition delta; negative values remove ammunition.

void


giveWeapon(weaponId, ammo, equip): void

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

Adds a valid weapon to this player’s native inventory.

number

weapons.tbl row identifier.

number

Initial reserve ammunition amount.

boolean

Whether the weapon should become the current weapon immediately.

void


isCrouching(): boolean

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

Checks the player’s most recently replicated crouch state.

boolean

True when the player is crouching.


isDead(): boolean

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

Checks the player’s most recently reported death state.

boolean

True when the player is dead.


isNametagHealthVisible(): boolean

Defined in: shared.d.ts:101

boolean


isNametagVisible(): boolean

Defined in: shared.d.ts:99

boolean


kick(reason?): void

Defined in: shared.d.ts:95

string

void


kill(): void

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

Instantly kills this player on the owning client.

void


modelToHands(enabled, leftModelId, rightModelId): void

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

Shows or clears visual prop models in this player’s hands. Hand slots are shared with the equipped weapon.

boolean

False clears both hand slots; true applies the supplied models.

number

weapons.tbl prop-row ID for the left hand; an unknown ID clears the slot.

number

weapons.tbl prop-row ID for the right hand; an unknown ID clears the slot.

void


modelToMouth(modelId): void

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

Shows a visual prop model in this player’s mouth.

number

weapons.tbl prop-row ID; an unknown ID clears the mouth slot.

void


playAnim(name, loop): boolean

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

Plays a named animation clip on this player’s ped on every client. The owning client’s controls lock automatically while the animation holds the body; end a looping clip with stopAnim, and re-enable controls after a one-shot with stopAnim or setControlsEnabled(true).

string

Bare engine clip name from a streamed animation set, at most 62 characters.

boolean

True to repeat the clip until stopAnim is called; false to play it once.

boolean

True when the request was broadcast; false when the clip name is empty or longer than 16 characters.


putInVehicle(vehicle, seat?): boolean

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

Instantly warps this player into a vehicle seat without the enter animation, leaving any current vehicle first.

number | Vehicle

Vehicle handle or network entity ID.

number

Seat index where 0 is the driver seat; defaults to 0.

boolean

True when the player was seated; false when the vehicle is unknown or destroyed, the seat is out of range or held by another player, or the player is dead.


removeAllWeapons(): void

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

Removes all weapons from this player and switches to fists.

void


removeFromVehicle(): boolean

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

Instantly warps this player out of their current vehicle without the exit animation.

boolean

True when the player was removed; false when the player is not in a vehicle.


removeMoney(amount): void

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

Removes cash from this player’s native inventory.

number

Cash amount in dollars to remove; removal is clamped to the available balance.

void


removeWeapon(weaponId): void

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

Removes one weapon from this player’s inventory and switches to fists when necessary.

number

weapons.tbl row identifier to remove.

void


restoreHealth(): void

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

Restores this player to full native health.

void


setAnimStyle(category, style): boolean

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

Overrides this player’s walk and idle animation style.

"common" | "weapon" | "panic" | "melee"

Animation-style registry category.

string

Registered style name within the selected category.

boolean

True when the category and style were found and applied.


setCurrentWeapon(weaponId): void

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

Equips one of this player’s owned weapons.

number

Owned weapons.tbl row identifier to equip.

void


setHealth(health): void

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

Sets this player’s health on the owning client.

number

Target health value, clamped to the pedestrian’s native maximum.

void


setModel(modelIndex): void

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

Changes this player’s body model and replicates the new skin.

number

Index in the shared player-model registry.

void


setModelColor(colorId): void

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

Recolors this player’s current outfit without reloading the model; unsupported variants are ignored.

number

Per-model palette variant; -1 restores the default.

void


setNametagColor(color): void

Defined in: shared.d.ts:104

number

void


setNametagHealthVisible(visible): void

Defined in: shared.d.ts:100

boolean

void


setNametagText(text?): void

Defined in: shared.d.ts:102

string

void


setNametagVisible(visible): void

Defined in: shared.d.ts:98

boolean

void


setRandomModel(): void

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

Selects and applies a random model from the Mafia II player model directory.

void


setUnlimitedAmmo(enabled): void

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

Enables or disables unlimited ammunition for this player.

boolean

Whether this player’s ammunition is infinite.

void


setVirtualWorld(world): void

Defined in: shared.d.ts:83

number

void


setVisibleTo(player): void

Defined in: shared.d.ts:84

Entity | null

void


setWeaponAmmo(weaponId, total, clip): void

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

Sets absolute ammunition counts for one of this player’s weapons.

number

weapons.tbl row identifier.

number

Absolute reserve ammunition amount.

number

Absolute loaded-clip amount; a negative value preserves the current clip.

void


spawn(x, y, z): void

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

Respawns this player at a world-space position.

number

Respawn world-space X coordinate.

number

Respawn world-space Y coordinate.

number

Respawn world-space Z coordinate.

void


stopAnim(): void

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

Stops this player’s scripted animation on every client and re-enables the owning client’s controls.

void


toString(): string

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

Returns a readable representation of this player.

string

The player ID and nickname formatted for logging or debugging.

readonly discordId: string

Defined in: shared.d.ts:91


readonly hardwareId: string

Defined in: shared.d.ts:92


readonly id: number

Defined in: shared.d.ts:79


readonly ip: string

Defined in: shared.d.ts:94


readonly model: number

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

Current shared player-model registry index, or -1 when unset or unknown.


readonly modelColor: number

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

Current per-model palette variant, or -1 for the default.


readonly nickname: string

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

Current connected-player nickname.


readonly ping: number

Defined in: shared.d.ts:93


position: Vector3

Defined in: shared.d.ts:81


rotation: Vector3 | Quaternion

Defined in: shared.d.ts:82


readonly steamId: string

Defined in: shared.d.ts:90


readonly virtualWorld: number

Defined in: shared.d.ts:80