Skip to content
M2O Scripting APIScripting reference
Runtime classServer APIGenerated

Npc

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

Replicated non-player character. Server-driven and AI-less: it holds the pose the server gives it.

  • Entity

new Npc(id): Npc

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

Creates a script wrapper for an existing NPC with this ID; use Npc.create() to create an NPC.

number

Network entity identifier.

Npc

destroy(): void

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

Destroys this replicated NPC and removes it from connected clients.

void


getNametagColor(): number

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

Returns this NPC’s nametag colour.

number

Packed 0xAARRGGBB colour.


getNametagText(): string

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

Returns this NPC’s nametag text override.

string

The override, or an empty string when the name is used.


isNametagHealthVisible(): boolean

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

Returns whether this NPC’s nametag health bar is enabled.

boolean

True when the health component is enabled.


isNametagVisible(): boolean

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

Returns whether this NPC’s nametag is enabled.

boolean

True when the name component is enabled.


kill(): void

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

Kills this NPC outright, playing a generic death on every client. Does nothing if it is already dead.

void


respawn(): void

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

Brings a dead NPC back to full health. Clients rebuild the ped, since a corpse cannot be revived in place.

void


setNametagColor(color): void

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

Sets the colour of this NPC’s nametag text.

number

Packed 0xAARRGGBB colour.

void


setNametagHealthVisible(visible): void

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

Shows or hides the health bar on this NPC’s nametag.

boolean

Whether the health bar is drawn under the name.

void


setNametagText(text): void

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

Overrides the text drawn on this NPC’s nametag.

string

Replacement label; pass an empty string to fall back to the NPC’s name.

void


setNametagVisible(visible): void

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

Shows or hides this NPC’s nametag. Hidden by default; a viewer’s own nametag switches still apply.

boolean

Whether the name is drawn above this NPC.

void


setVirtualWorld(world): void

Defined in: shared.d.ts:83

number

void


setVisibleTo(player): void

Defined in: shared.d.ts:84

Entity | null

void


toString(): string

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

Returns a readable representation of this NPC.

string

The NPC ID formatted for logging or debugging.


static create(x, y, z, model, name?, rotation?, invincible?, virtualWorld?): Npc

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

Creates and replicates a server-driven NPC.

number

Initial world-space X coordinate.

number

Initial world-space Y coordinate.

number

Initial world-space Z coordinate.

number

Character model identifier to instantiate.

string

Optional name, shown by the nametag once it is enabled.

Vector3 | Quaternion

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

boolean

Optional damage immunity; pass false to spawn a killable NPC. Defaults to true.

number

Optional virtual-world ID used for visibility filtering.

Npc

The newly created NPC handle.

readonly dead: boolean

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

Whether the NPC is dead.


direction: Vector3

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

Facing as a unit forward vector; assignment rewrites the rotation so the NPC faces that way.


health: number

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

Server-authoritative health, on the same scale as a player (200 = full). Assigning 0 or less kills the NPC; assigning above 0 to a dead one revives it.


readonly id: number

Defined in: shared.d.ts:79


invincible: boolean

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

Whether the NPC rejects all damage. Set false to make it killable. Defaults to true.


maxHealth: number

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

Health ceiling, and the denominator of the nametag health bar. Defaults to 200.


readonly model: number

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

Character model identifier this NPC was spawned with.


name: string

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

This NPC’s name, shown by its nametag unless a nametag text override is set.


position: Vector3

Defined in: shared.d.ts:81


rotation: Vector3 | Quaternion

Defined in: shared.d.ts:82


readonly virtualWorld: number

Defined in: shared.d.ts:80