Skip to content
M2O Scripting APIScripting reference
Runtime classServer APIGenerated

Npc

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

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

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

Destroys this replicated NPC and removes it from connected clients.

void


getNametagColor(): number

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

Returns this NPC’s nametag colour.

number

Packed 0xAARRGGBB colour.


getNametagText(): string

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

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

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

Returns whether this NPC’s nametag is enabled.

boolean

True when the name component is enabled.


kill(): void

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

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

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

Sets the colour of this NPC’s nametag text.

number

Packed 0xAARRGGBB colour.

void


setNametagHealthVisible(visible): void

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

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

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

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

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

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

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

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

Whether the NPC is dead.


direction: Vector3

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

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


frozen: boolean

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

Whether the NPC is locked in place: players and vehicles collide with it but cannot push it. Defaults to false.


health: number

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

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

Immutable network entity identifier.

Entity.id


invincible: boolean

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

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


maxHealth: number

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

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


readonly model: number

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

Character model identifier this NPC was spawned with.


name: string

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

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


position: Vector3

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

Authoritative world-space position; assignment forces replicated state.

Entity.position


rotation: Vector3 | Quaternion

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

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

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

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

Current virtual-world identifier.

Entity.virtualWorld