Skip to content
M2O Scripting APIScripting reference
Runtime classServer APIGenerated

Player

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

A connected M2O 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:97

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

Removes this player’s animation-style override.

void


clearCollectedPinups(): void

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

Forgets every pinup collectible this player has taken, putting all of them back in the world on their client.

void


clearHandModels(): void

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

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

void


emit(eventName, payloadJson?): void

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

Emits a named script event to this player’s client connection.

string

Client event name.

string

Optional JSON payload forwarded verbatim to the owning client.

void

BasePlayer.emit


getAmmo(weaponId): CarriedWeapon | null

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

Returns the reserve and loaded ammunition of one carried weapon, as last reported by this player’s client.

number

weapons.tbl row identifier.

CarriedWeapon | null

The weapon’s counts, or null when the player does not carry it.


getAnimStyle(): number

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

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

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

Returns the most recently owner-reported health value.

number

Current replicated health, including native damage.


getIP(): string

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

Returns this player’s current remote network address.

string

Address string, or an empty string when the player or peer is unavailable.

BasePlayer.getIP


getMoney(): number

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

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

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

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

One of idle, walking, running, or stopping.


getNametagColor(): number

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

Reads this player’s nametag color.

number

Packed 0xAARRGGBB color; opaque white when untinted.

BasePlayer.getNametagColor


getNametagText(): string

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

Reads this player’s nametag text override.

string

The override, or an empty string when the player’s own name is drawn.

BasePlayer.getNametagText


getTeam(): number

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

Returns the team this player belongs to.

number

The team id, or 0 when the player is on no team.


getVehicle(): Vehicle | null

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

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.


getWeapons(): CarriedWeapon[]

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

Returns every weapon this player carries with its reserve and loaded ammunition, as last reported by their client. Values are current to within one client frame, and stay readable in playerDisconnect.

CarriedWeapon[]

One entry per carried weapon; empty before the client’s first report.


giveAmmo(weaponId, amount): void

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

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

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

Checks the player’s most recently replicated crouch state.

boolean

True when the player is crouching.


isDead(): boolean

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

Checks the player’s most recently reported death state.

boolean

True when the player is dead.


isNametagHealthVisible(): boolean

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

Checks whether the health bar under this player’s nametag is shown.

boolean

True unless the health bar was hidden; false also when this game has no nametags.

BasePlayer.isNametagHealthVisible


isNametagVisible(): boolean

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

Checks whether this player’s nametag is shown to other players.

boolean

True unless the nametag was hidden; false also when this game has no nametags.

BasePlayer.isNametagVisible


isPinupCollected(pinupId): boolean

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

Checks whether this player has taken a pinup collectible.

number

Pinups.tbl collectible identifier.

boolean

True when the collectible is in this player’s collected set.


kick(reason?): void

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

Disconnects this player from the server.

string

Optional reason shown to the disconnected player; omitting it uses the generic kicked reason.

void

BasePlayer.kick


kill(): void

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

Instantly kills this player on the owning client.

void


modelToHands(enabled, leftModelId, rightModelId): void

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

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

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, useAnimSet?): boolean

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

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. If a one-shot leaves the controls locked, call stopAnim, or Controls.setEnabled(true) from a client script.

string

Engine animation clip name, at most 62 characters (e.g. “sc_eat_hot_out”, or “CC_TAUNT01-A” with useAnimSet).

boolean

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

boolean

False (default) plays the clip by its exact name; true looks it up in the ped’s current animation set, as set-member clips such as CC_TAUNT01-A require.

boolean

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


putInVehicle(vehicle, seat?): boolean

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

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

Removes all weapons from this player and switches to fists.

void


removeFromVehicle(animated?): boolean

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

Takes this player out of their current vehicle. The default is an instant warp; with animated the player climbs out normally, the car radio and in-car audio stop, and vehiclePlayerExited fires when the animation completes rather than immediately.

boolean

Play the native get-out animation instead of warping; defaults to false.

boolean

True when the player was removed, or when the animated exit was started; false when the player is not in a vehicle.


removeMoney(amount): void

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

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

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

Restores this player to full native health.

void


setAnimStyle(category, style): boolean

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

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

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

Sets this player’s health on the owning client.

number

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

void


setInvincible(enabled): void

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

Makes this player immune to every damage source: bullets, melee, explosions, fire, vehicle impacts, run-overs and falls, including while seated in a burning or exploding vehicle. Hit reactions and knockdowns still play, and kill() still kills. Resets to false on reconnect.

boolean

True to make the player immune to all damage, false to restore it.

void


setModel(modelIndex): void

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

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

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: server/api.d.ts:4323

Tints the text on this player’s nametag.

number

Packed 0xAARRGGBB color.

void

BasePlayer.setNametagColor


setNametagHealthVisible(visible): void

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

Shows or hides the health bar under this player’s nametag, leaving the name itself alone.

boolean

True to show the health bar under this player’s name, false to hide it.

void

BasePlayer.setNametagHealthVisible


setNametagText(text?): void

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

Overrides the text drawn on this player’s nametag.

string

Text to show instead of the player’s name, cut to 64 bytes; empty or omitted restores the name.

void

BasePlayer.setNametagText


setNametagVisible(visible): void

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

Shows or hides the name over this player’s head for every other player. The health bar has its own switch, and each player can still hide all nametags locally.

boolean

True to show this player’s nametag to everyone, false to hide it.

void

BasePlayer.setNametagVisible


setPinupCollected(pinupId, collected): void

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

Sets whether this player has taken a pinup collectible. The world entity is hidden or restored on this player’s client immediately, without waiting for the area to stream again.

number

Pinups.tbl collectible identifier.

boolean

True to mark the collectible taken and hide it; false to restore it to the world.

void


setRandomModel(): void

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

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

void


setTeam(team): boolean

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

Puts this player on a team, which decides who may damage them.

number

Team id from Team.create, or 0 to leave every team.

boolean

True when the team exists and was applied.


setUnlimitedAmmo(enabled): void

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

Enables or disables unlimited ammunition for this player.

boolean

Whether this player’s ammunition is infinite.

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

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

BasePlayer.setVisibleTo


setWeaponAmmo(weaponId, total, clip): void

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

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

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

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

Returns a readable representation of this player.

string

The player ID and nickname formatted for logging or debugging.

BasePlayer.toString

readonly collectedPinups: number[]

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

Pinups.tbl identifiers of every collectible this player has taken.


readonly discordId: string

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

Authenticated Discord identifier, or an empty string when unavailable.

BasePlayer.discordId


readonly epicId: string

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

Epic Games account identifier the client reported, not verified by the server, or an empty string when unavailable.

BasePlayer.epicId


readonly hardwareId: string

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

Framework hardware identifier, or an empty string when unavailable.

BasePlayer.hardwareId


readonly id: number

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

Immutable network entity identifier.

BasePlayer.id


readonly invincible: boolean

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

True while setInvincible has made this player immune to damage.


readonly ip: string

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

Current remote network address, or an empty string when unavailable.

BasePlayer.ip


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: server/api.d.ts:4245

Current round-trip latency in milliseconds, or -1 when unavailable.

BasePlayer.ping


position: Vector3

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

Authoritative world-space position; assignment forces replicated state.

BasePlayer.position


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.

BasePlayer.rotation


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.

BasePlayer.state


readonly steamId: string

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

Authenticated Steam identifier, or an empty string when unavailable.

BasePlayer.steamId


readonly virtualWorld: number

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

Current virtual-world identifier.

BasePlayer.virtualWorld