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.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”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.
Parameters
Section titled “Parameters”number
Network entity identifier.
Returns
Section titled “Returns”Npc
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”destroy()
Section titled “destroy()”destroy():
void
Defined in: server/api.d.ts:1423
Destroys this replicated NPC and removes it from connected clients.
Returns
Section titled “Returns”void
getNametagColor()
Section titled “getNametagColor()”getNametagColor():
number
Defined in: server/api.d.ts:1481
Returns this NPC’s nametag colour.
Returns
Section titled “Returns”number
Packed 0xAARRGGBB colour.
getNametagText()
Section titled “getNametagText()”getNametagText():
string
Defined in: server/api.d.ts:1469
Returns this NPC’s nametag text override.
Returns
Section titled “Returns”string
The override, or an empty string when the name is used.
isNametagHealthVisible()
Section titled “isNametagHealthVisible()”isNametagHealthVisible():
boolean
Defined in: server/api.d.ts:1457
Returns whether this NPC’s nametag health bar is enabled.
Returns
Section titled “Returns”boolean
True when the health component is enabled.
isNametagVisible()
Section titled “isNametagVisible()”isNametagVisible():
boolean
Defined in: server/api.d.ts:1445
Returns whether this NPC’s nametag is enabled.
Returns
Section titled “Returns”boolean
True when the name component is enabled.
kill()
Section titled “kill()”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.
Returns
Section titled “Returns”void
respawn()
Section titled “respawn()”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.
Returns
Section titled “Returns”void
setNametagColor()
Section titled “setNametagColor()”setNametagColor(
color):void
Defined in: server/api.d.ts:1475
Sets the colour of this NPC’s nametag text.
Parameters
Section titled “Parameters”number
Packed 0xAARRGGBB colour.
Returns
Section titled “Returns”void
setNametagHealthVisible()
Section titled “setNametagHealthVisible()”setNametagHealthVisible(
visible):void
Defined in: server/api.d.ts:1451
Shows or hides the health bar on this NPC’s nametag.
Parameters
Section titled “Parameters”visible
Section titled “visible”boolean
Whether the health bar is drawn under the name.
Returns
Section titled “Returns”void
setNametagText()
Section titled “setNametagText()”setNametagText(
text):void
Defined in: server/api.d.ts:1463
Overrides the text drawn on this NPC’s nametag.
Parameters
Section titled “Parameters”string
Replacement label; pass an empty string to fall back to the NPC’s name.
Returns
Section titled “Returns”void
setNametagVisible()
Section titled “setNametagVisible()”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.
Parameters
Section titled “Parameters”visible
Section titled “visible”boolean
Whether the name is drawn above this NPC.
Returns
Section titled “Returns”void
setVirtualWorld()
Section titled “setVirtualWorld()”setVirtualWorld(
world):void
Defined in: server/api.d.ts:4154
Moves this entity into another virtual world.
Parameters
Section titled “Parameters”number
Virtual-world identifier used to partition replication and visibility.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”setVisibleTo()
Section titled “setVisibleTo()”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.
Parameters
Section titled “Parameters”player
Section titled “player”Entity | null
Player-owned entity whose connection should exclusively receive this entity, or null to clear the restriction.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”toString()
Section titled “toString()”toString():
string
Defined in: server/api.d.ts:1418
Returns a readable representation of this NPC.
Returns
Section titled “Returns”string
The NPC ID formatted for logging or debugging.
Inherited from
Section titled “Inherited from”create()
Section titled “create()”
staticcreate(x,y,z,model,name?,rotation?,invincible?,virtualWorld?):Npc
Defined in: server/api.d.ts:1495
Creates and replicates a server-driven NPC.
Parameters
Section titled “Parameters”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.
rotation?
Section titled “rotation?”Optional orientation: a Quaternion, or a Vector3 of Euler angles in degrees.
invincible?
Section titled “invincible?”boolean
Optional damage immunity; pass false to spawn a killable NPC. Defaults to true.
virtualWorld?
Section titled “virtualWorld?”number
Optional virtual-world ID used for visibility filtering.
Returns
Section titled “Returns”Npc
The newly created NPC handle.
Properties
Section titled “Properties”
readonlydead:boolean
Defined in: server/api.d.ts:1407
Whether the NPC is dead.
direction
Section titled “direction”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
Section titled “health”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.
readonlyid:number
Defined in: server/api.d.ts:4122
Immutable network entity identifier.
Inherited from
Section titled “Inherited from”invincible
Section titled “invincible”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
Section titled “maxHealth”maxHealth:
number
Defined in: server/api.d.ts:1397
Health ceiling, and the denominator of the nametag health bar. Defaults to 200.
readonlymodel: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
Section titled “position”position:
Vector3
Defined in: server/api.d.ts:4132
Authoritative world-space position; assignment forces replicated state.
Inherited from
Section titled “Inherited from”rotation
Section titled “rotation”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.
Inherited from
Section titled “Inherited from”
readonlystate: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.
Inherited from
Section titled “Inherited from”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.
virtualWorld
Section titled “virtualWorld”
readonlyvirtualWorld:number
Defined in: server/api.d.ts:4127
Current virtual-world identifier.
