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.
Extends
Section titled “Extends”Entity
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”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.
Parameters
Section titled “Parameters”number
Network entity identifier.
Returns
Section titled “Returns”Npc
Methods
Section titled “Methods”destroy()
Section titled “destroy()”destroy():
void
Defined in: server/api.d.ts:1108
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:1166
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:1154
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:1142
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:1130
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:1113
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:1118
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:1160
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:1136
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:1148
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:1124
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: shared.d.ts:83
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
setVisibleTo()
Section titled “setVisibleTo()”setVisibleTo(
player):void
Defined in: shared.d.ts:84
Parameters
Section titled “Parameters”player
Section titled “player”Entity | null
Returns
Section titled “Returns”void
toString()
Section titled “toString()”toString():
string
Defined in: server/api.d.ts:1103
Returns a readable representation of this NPC.
Returns
Section titled “Returns”string
The NPC ID formatted for logging or debugging.
create()
Section titled “create()”
staticcreate(x,y,z,model,name?,rotation?,invincible?,virtualWorld?):Npc
Defined in: server/api.d.ts:1180
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 radians.
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:1092
Whether the NPC is dead.
direction
Section titled “direction”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
Section titled “health”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.
readonlyid:number
Defined in: shared.d.ts:79
invincible
Section titled “invincible”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
Section titled “maxHealth”maxHealth:
number
Defined in: server/api.d.ts:1082
Health ceiling, and the denominator of the nametag health bar. Defaults to 200.
readonlymodel: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
Section titled “position”position:
Vector3
Defined in: shared.d.ts:81
rotation
Section titled “rotation”rotation:
Vector3|Quaternion
Defined in: shared.d.ts:82
virtualWorld
Section titled “virtualWorld”
readonlyvirtualWorld:number
Defined in: shared.d.ts:80
