Skip to content
M2O Scripting APIScripting reference
Runtime classServer APIGenerated

Npc

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

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

new Npc(id): Npc

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

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

number

Network entity identifier.

Npc

Entity.constructor

destroy(): void

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

Destroys this replicated NPC and removes it from connected clients.

void


getNametagColor(): number

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

Returns this NPC’s nametag colour.

number

Packed 0xAARRGGBB colour.


getNametagText(): string

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

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

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

Returns whether this NPC’s nametag is enabled.

boolean

True when the name component is enabled.


kill(): void

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

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

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

Sets the colour of this NPC’s nametag text.

number

Packed 0xAARRGGBB colour.

void


setNametagHealthVisible(visible): void

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

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

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

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

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

Entity.setVisibleTo


toString(): string

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

Returns a readable representation of this NPC.

string

The NPC ID formatted for logging or debugging.

Entity.toString


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

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

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

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

Whether the NPC is dead.


direction: Vector3

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

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


health: number

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

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

Immutable network entity identifier.

Entity.id


invincible: boolean

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

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


maxHealth: number

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

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


readonly model: number

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

Character model identifier this NPC was spawned with.


name: string

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

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


position: Vector3

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

Authoritative world-space position; assignment forces replicated state.

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

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

Entity.state


team: number

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

Team this NPC belongs to, from Team.create; 0 for no team. Decides who may damage it, on the same table players use.


readonly virtualWorld: number

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

Current virtual-world identifier.

Entity.virtualWorld