NPC
Defined in: server/api.d.ts:1887
A server-spawned combat NPC handle; npcDied fires on death.
Extends
Section titled “Extends”ServerEntity.ServerEntity
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new NPC(
id):NPC
Defined in: server/api.d.ts:1892
Wraps an NPC entity id without spawning it.
Parameters
Section titled “Parameters”number
Network id of the server entity to wrap.
Returns
Section titled “Returns”NPC
Methods
Section titled “Methods”destroy()
Section titled “destroy()”destroy():
void
Defined in: server/api.d.ts:2045
Despawns the NPC everywhere immediately, with no death anim.
Returns
Section titled “Returns”void
follow()
Section titled “follow()”follow(
target,options?):boolean
Defined in: server/api.d.ts:2173
Walks after the target with the game’s own pathfinding and locomotion until stop() or a new command, ending any running one as “replaced”. A fight it gets into holds the follow, which goes on once the NPC is calm again; pause(), aiPaused and movementFrozen hold it too. A followed player’s own client runs the NPC. npcMoveEnded “targetGone” when the target leaves. Throws on bad input.
Parameters
Section titled “Parameters”target
Section titled “target”Player | Character | Beast | NPC
Whom to follow.
options?
Section titled “options?”gait (default “walk”), speedScale (0.25 to 3), distanceCm: it rests inside this distance and walks again once the target pulls 100 cm past it (100 to 3000, default 200), teleportBeyond: metres behind the target past which the server puts it beside them (default 60, 0 never), and then: the idle it takes up where it stands once the follow ends (default “stand”).
Returns
Section titled “Returns”boolean
False when the NPC is gone or dead.
forceTarget()
Section titled “forceTarget()”forceTarget(
targetPlayerId,holdSeconds?,applyTicks?):void
Defined in: server/api.d.ts:2091
Holds a forced combat target the way the game’s taunt does: the owner pins it once, then the target outscores every other candidate and the NPC’s attack keeps it. A target out of reach of the owner’s player (55 m) moves the NPC to that player’s client until the force ends. Read targetPlayerId back to see whether it held.
Parameters
Section titled “Parameters”targetPlayerId
Section titled “targetPlayerId”number
Player network id to force this NPC onto; 0 releases it back to native selection.
holdSeconds?
Section titled “holdSeconds?”number
SetForcedPerceptionTarget window (default 3, max 60).
applyTicks?
Section titled “applyTicks?”number
Ticks the NPC may stay off the target before its owner pins it again, after a native re-pick at 30 (default 1).
Returns
Section titled “Returns”void
getRewardPolicy()
Section titled “getRewardPolicy()”getRewardPolicy(): {
experience:number;gameReward:boolean;loot:object[] |null;lootDelivery:"drop"|"inventory";lootMode:"each"|"shared";radius:number;recipients:"killer"|"damagers"|"nearby"; } |null
Defined in: server/api.d.ts:2120
What this NPC’s death will pay: its own policy over the server default. Null once it has despawned.
Returns
Section titled “Returns”{ experience: number; gameReward: boolean; loot: object[] | null; lootDelivery: "drop" | "inventory"; lootMode: "each" | "shared"; radius: number; recipients: "killer" | "damagers" | "nearby"; } | null
kill()
Section titled “kill()”kill():
void
Defined in: server/api.d.ts:2040
Runs the game’s death pipeline (death anim on every client), then despawns.
Returns
Section titled “Returns”void
launch()
Section titled “launch()”launch(
x,y?,z?,opts?):boolean
Defined in: server/api.d.ts:2054
Launches the NPC: sets its velocity in cm/s (added to the current one unless opts.overrideXY / overrideZ) and puts it in the air, on its owning client. True when sent, false on a dormant NPC. No effect while movementFrozen or before it has spawned.
Parameters
Section titled “Parameters”number | Vector3
X component, or the whole vector.
number
Y component.
number
Z component.
space (‘world’ | ‘local’), at, velocityChange, addToCurrent, overrideXY, overrideZ.
Returns
Section titled “Returns”boolean
moveAlong()
Section titled “moveAlong()”moveAlong(
waypoints,options?):boolean
Defined in: server/api.d.ts:2155
Walks the waypoints with the game’s own pathfinding and locomotion, ending any running path as “replaced”. npcWaypoint fires on each arrival (before its wait), npcMoveEnded at the end. A fight it gets into holds the path, which continues once the NPC is calm again; aiPaused and movementFrozen hold it too. Throws on bad input.
Parameters
Section titled “Parameters”waypoints
Section titled “waypoints”1 to 64 points, each a player’s origin (as player.position) with an optional wait (seconds) and the gait of the leg that arrives there.
options?
Section titled “options?”gait (default “walk”), loop (“once”, “loop” or “pingpong”), radius: how near a point counts as reached (cm, default the game’s own, about 50), speedScale: the game’s own speed scale, 0.25 to 3, which jog and sprint follow, and then: the idle after a “once” path (default “stand”).
Returns
Section titled “Returns”boolean
False when the NPC is gone or dead.
moveTo()
Section titled “moveTo()”moveTo(
x,y?,z?,options?):boolean
Defined in: server/api.d.ts:2165
moveAlong with one waypoint.
Parameters
Section titled “Parameters”number | Vector3Like
World x of a player’s origin.
number
World y.
number
World z.
options?
Section titled “options?”As moveAlong’s.
Returns
Section titled “Returns”boolean
False when the NPC is gone or dead.
pause()
Section titled “pause()”pause():
void
Defined in: server/api.d.ts:2142
Holds the running path or follow where it is; resume() walks on from there. A new command or stop() ends the hold.
Returns
Section titled “Returns”void
relationTo()
Section titled “relationTo()”relationTo(
other): {pvpReason:string|null;reason:"native"|"pvp"|"friendlyNpc";stance:"native"|"hostile"|"ally"; } |null
Defined in: server/api.d.ts:2109
How this NPC and other stand: ally (they never hurt each other), hostile (the PvP rules let them fight) or native (the game’s own attitudes decide). pvpReason is the PvP relation’s reason when both answer to players. Null when either has despawned.
Parameters
Section titled “Parameters”number | Player | NPC
A player, an NPC or either’s id.
Returns
Section titled “Returns”{ pvpReason: string | null; reason: "native" | "pvp" | "friendlyNpc"; stance: "native" | "hostile" | "ally"; } | null
resume()
Section titled “resume()”resume():
void
Defined in: server/api.d.ts:2147
Continues the path or follow pause() held.
Returns
Section titled “Returns”void
setDamageGivenMultiplier()
Section titled “setDamageGivenMultiplier()”setDamageGivenMultiplier(
multiplier):void
Defined in: server/api.d.ts:2126
Scales the damage this NPC deals to players. It multiplies with each player’s setDamageTakenMultiplier and stacks on the game’s own modifiers; every client applies it, so it holds across owner hand-off.
Parameters
Section titled “Parameters”multiplier
Section titled “multiplier”number | null
1 is native, 0 deals none; null restores 1.
Returns
Section titled “Returns”void
setDamageTakenMultiplier()
Section titled “setDamageTakenMultiplier()”setDamageTakenMultiplier(
multiplier):void
Defined in: server/api.d.ts:2132
Scales the damage players deal to this NPC. It multiplies with each player’s setDamageGivenMultiplier and stacks on the game’s own modifiers; every client applies it, so it holds across owner hand-off.
Parameters
Section titled “Parameters”multiplier
Section titled “multiplier”number | null
1 is native, 0 takes none; null restores 1.
Returns
Section titled “Returns”void
setDisposition()
Section titled “setDisposition()”setDisposition(
disposition):void
Defined in: server/api.d.ts:2023
Shorthand for its side. Friendly puts it on the players’ team (setTeam(“Player”)): it fights wild enemies and never targets a player, and no player can hurt it. Hostile clears its leader and team, back to its class’s own.
Parameters
Section titled “Parameters”disposition
Section titled “disposition”"hostile" | "friendly"
New disposition.
Returns
Section titled “Returns”void
setHealth()
Section titled “setHealth()”setHealth(
health):void
Defined in: server/api.d.ts:2035
Sets current health once. No-op on a dormant (unowned) NPC.
Parameters
Section titled “Parameters”health
Section titled “health”number
New current health; the game clamps to [0, max].
Returns
Section titled “Returns”void
setLeader()
Section titled “setLeader()”setLeader(
player):boolean
Defined in: server/api.d.ts:2097
Puts the NPC on a player’s side: it never targets that player, and to every other player it is what its leader is under the PvP rules (an enemy only to one its leader may fight). Its damage counts as its leader’s, kills and rewards included. It despawns when its leader leaves. False on a despawned NPC.
Parameters
Section titled “Parameters”player
Section titled “player”number | Player | null
The player it fights for; null for none.
Returns
Section titled “Returns”boolean
setMaxHealth()
Section titled “setMaxHealth()”setMaxHealth(
maxHealth):void
Defined in: server/api.d.ts:2029
Overrides the NPC’s max health (owner raises base health and fills current to the new max); persists across owner hand-off and level travel.
Parameters
Section titled “Parameters”maxHealth
Section titled “maxHealth”number
New max health; pass <= 0 to clear back to the pawn’s native max.
Returns
Section titled “Returns”void
setRewardPolicy()
Section titled “setRewardPolicy()”setRewardPolicy(
policy):void
Defined in: server/api.d.ts:2115
Sets what this NPC’s death pays, and to whom. Each recipient’s own client grants it, so it shows like any kill reward. A death from npc.kill() pays nobody. Throws a TypeError or RangeError for a malformed policy.
Parameters
Section titled “Parameters”policy
Section titled “policy”{ experience?: number; gameReward?: boolean; loot?: object[] | null; lootDelivery?: "drop" | "inventory"; lootMode?: "each" | "shared"; radius?: number; recipients?: "killer" | "damagers" | "nearby"; } | null
recipients: “killer” (the player whose hit finished it) or “damagers” (every player who hit it); gameReward: pay the game’s own kill reward; experience: flat XP on top. Fields left out come from NPC.setDefaultRewardPolicy; null clears them all.
Returns
Section titled “Returns”void
setScale()
Section titled “setScale()”setScale(
scale,mode?):void
Defined in: server/api.d.ts:2083
Sets the scale on every client’s copy; set it right after create so the NPC is sized before it first streams in.
Parameters
Section titled “Parameters”number
Uniform scale (1 = native size).
"full" | "visual"
“full” (default) resizes the whole actor, collision included; “visual” resizes only the body and leaves collision native.
Returns
Section titled “Returns”void
setTeam()
Section titled “setTeam()”setTeam(
team):boolean
Defined in: server/api.d.ts:2103
Sets the native team the NPC fights for, so the game’s own attitudes decide whom it attacks; “Player” makes it friendly to every player. A leader’s side takes over while it has one. False on a despawned NPC.
Parameters
Section titled “Parameters”string | null
A game team name such as “Goblin”, “Spider” or “Player”; null for its class’s own.
Returns
Section titled “Returns”boolean
setVirtualWorld()
Section titled “setVirtualWorld()”setVirtualWorld(
world,map?):void
Defined in: server/api.d.ts:2180
Moves this entity into another virtual world, within a map: there it meets the players in the same world of the same map, so world N of a dungeon is one instance of it.
Parameters
Section titled “Parameters”number
Virtual-world identifier used to partition replication and visibility.
string
The map it is in, as player.location().areaId names it; “Overland” or “” for the shared map. Left out, it stays in its current map.
Returns
Section titled “Returns”void
setVisibleTo()
Section titled “setVisibleTo()”setVisibleTo(
player):void
Defined in: shared.d.ts:82
Restricts replication to one player’s connection, within the usual range and visibility checks; null lifts it.
Parameters
Section titled “Parameters”player
Section titled “player”Entity | null
Returns
Section titled “Returns”void
stop()
Section titled “stop()”stop():
void
Defined in: server/api.d.ts:2137
Ends the running path or follow as “stopped” and leaves the NPC where it is, to its idle.
Returns
Section titled “Returns”void
toString()
Section titled “toString()”toString():
string
Defined in: server/api.d.ts:2017
Returns a debug string for this NPC.
Returns
Section titled “Returns”string
create()
Section titled “create()”
staticcreate(enemyId,opts,y?,z?,disposition?,preferredOwnerId?):NPC|undefined
Defined in: server/api.d.ts:2065
Spawns a replicated combat NPC. Throws a TypeError when opts lacks a finite x, y or z.
Parameters
Section titled “Parameters”enemyId
Section titled “enemyId”string
Catalog id or class path.
number | NpcSpawnOptions
Where it spawns and how. A number starts the deprecated positional form, create(enemyId, x, y, z, disposition?, preferredOwnerId?), which has no yaw.
number
Deprecated positional form only.
number
Deprecated positional form only.
disposition?
Section titled “disposition?”"hostile" | "friendly"
Deprecated positional form only.
preferredOwnerId?
Section titled “preferredOwnerId?”number
Deprecated positional form only.
Returns
Section titled “Returns”NPC | undefined
getDefaultRewardPolicy()
Section titled “getDefaultRewardPolicy()”
staticgetDefaultRewardPolicy():object
Defined in: server/api.d.ts:2076
The server-wide reward policy, with the built-in values filled in.
Returns
Section titled “Returns”object
experience
Section titled “experience”experience:
number
gameReward
Section titled “gameReward”gameReward:
boolean
loot:
object[] |null
lootDelivery
Section titled “lootDelivery”lootDelivery:
"drop"|"inventory"
lootMode
Section titled “lootMode”lootMode:
"each"|"shared"
radius
Section titled “radius”radius:
number
recipients
Section titled “recipients”recipients:
"killer"|"damagers"|"nearby"
setDefaultRewardPolicy()
Section titled “setDefaultRewardPolicy()”
staticsetDefaultRewardPolicy(policy):void
Defined in: server/api.d.ts:2071
Sets what an NPC’s death pays when the NPC’s own policy (setRewardPolicy, or its camp’s) leaves a field out. Built in: the killing blow earns the game’s own kill reward (Field Guide knowledge, its experience and kill-challenge progress). Throws a TypeError or RangeError for a malformed policy.
Parameters
Section titled “Parameters”policy
Section titled “policy”{ experience?: number; gameReward?: boolean; loot?: object[] | null; lootDelivery?: "drop" | "inventory"; lootMode?: "each" | "shared"; radius?: number; recipients?: "killer" | "damagers" | "nearby"; } | null
Fields left out keep the built-in default; null restores it.
Returns
Section titled “Returns”void
Properties
Section titled “Properties”aiPaused
Section titled “aiPaused”aiPaused:
boolean
Defined in: server/api.d.ts:1897
Enemies only: holds the NPC in the game’s scripted-pause state. It stops pathing and starts no new attack, dodge or patrol, and idles in place; hit reactions, Protego, death and an attack already mid-swing still play. Perception and targeting keep running.
readonlyalive:boolean
Defined in: server/api.d.ts:1942
Whether the NPC is currently alive.
animationFrozen
Section titled “animationFrozen”animationFrozen:
boolean
Defined in: server/api.d.ts:1917
Freezes the NPC’s pose on every client.
combatEnabled
Section titled “combatEnabled”combatEnabled:
boolean
Defined in: server/api.d.ts:1902
Off: the NPC stays hostile and keeps chasing its target but never starts an attack. It can still counter right after it blocks or dodges, and its Protego still deflects spells. A friendly NPC still fights wild enemies; turn this off to keep it out of fights. Enemies only.
damageGivenMultiplier
Section titled “damageGivenMultiplier”
readonlydamageGivenMultiplier:number
Defined in: server/api.d.ts:1982
The multiplier set by setDamageGivenMultiplier; 1 when native.
damageTakenMultiplier
Section titled “damageTakenMultiplier”
readonlydamageTakenMultiplier:number
Defined in: server/api.d.ts:1987
The multiplier set by setDamageTakenMultiplier; 1 when native.
disposition
Section titled “disposition”
readonlydisposition:"hostile"|"friendly"|undefined
Defined in: server/api.d.ts:1927
“friendly” when it fights for a leader or is on the players’ team, else “hostile”; undefined once the NPC has despawned.
enemyId
Section titled “enemyId”
readonlyenemyId:string
Defined in: server/api.d.ts:1922
Catalog id or class path this NPC was spawned from.
health
Section titled “health”
readonlyhealth:number
Defined in: server/api.d.ts:1972
Owner-reported actual current health (absolute game units); reads 0 until the owner client has embodied the pawn and polled it.
home:
Vector3|null
Defined in: server/api.d.ts:2007
Where the stand and wander idles keep it, a player’s origin; a “once” path that arrives moves it to the last point, and a follow that ends to where it stands. Null until one is set.
readonlyid:number
Defined in: shared.d.ts:65
Network id, stable for the entity’s lifetime.
idle:
NpcIdle
Defined in: server/api.d.ts:2002
What it does while no path or follow runs: “native” (the game’s own: it wanders where it spawned; the default), “stand” (holds at its home, walking back there after a fight) or “wander” (roams around its home). The first stand or wander makes where it stands its home.
leaderId
Section titled “leaderId”
readonlyleaderId:number
Defined in: server/api.d.ts:1932
The player it fights for (see setLeader), or 0.
maxHealth
Section titled “maxHealth”
readonlymaxHealth:number
Defined in: server/api.d.ts:1977
Owner-reported actual max health (absolute game units); reads 0 until the owner client has embodied the pawn and polled it.
movement
Section titled “movement”
readonlymovement:NpcMovementState
Defined in: server/api.d.ts:1992
The running command: mode (“idle”, “path” or “follow”), the waypoint it heads for or waits at, the path’s length, completed laps, whether pause() or aiPaused holds it, and the followed entity’s id (0 otherwise). The idle state once the NPC is gone.
movementFrozen
Section titled “movementFrozen”movementFrozen:
boolean
Defined in: server/api.d.ts:1912
Locks the NPC’s position; animation and AI decisions continue.
ownerId
Section titled “ownerId”
readonlyownerId:number
Defined in: server/api.d.ts:1947
Network id of the player whose client runs the AI (0 = server-owned/dormant).
perceptionEnabled
Section titled “perceptionEnabled”perceptionEnabled:
boolean
Defined in: server/api.d.ts:1907
Off: the NPC stops perceiving players, drops every target and returns to idle, and acquires nothing until it is turned back on. Re-applied if the game wakes it (a hit, spawn); a forced target overrides it.
position
Section titled “position”position:
Vector3
Defined in: shared.d.ts:67
World position. Read, call set(...), then assign back.
rotation
Section titled “rotation”rotation:
Vector3|Quaternion
Defined in: shared.d.ts:69
Reads as a quaternion; assignments also accept Euler angles in degrees.
readonlyscale:number
Defined in: server/api.d.ts:1962
Current uniform scale (1 = native size).
scaleMode
Section titled “scaleMode”
readonlyscaleMode:"full"|"visual"
Defined in: server/api.d.ts:1967
How the scale is applied: “full” resizes the whole actor, “visual” only the body (see setScale).
readonlystate:StateBag
Defined in: shared.d.ts:71
This entity’s key/value state: the server writes it, and every client that can see the entity receives it. See StateBag.
targetPlayerId
Section titled “targetPlayerId”
readonlytargetPlayerId:number
Defined in: server/api.d.ts:1952
Owner-reported readback: the player NPC_Component::GetTarget() actually resolves to right now, or 0. Compare against the id passed to forceTarget to see native reversion.
targetType
Section titled “targetType”
readonlytargetType:number
Defined in: server/api.d.ts:1957
Owner-reported EEnemy_TargetType readback: 0 None, 1 Attack, 2 Flee.
readonlyteam:string
Defined in: server/api.d.ts:1937
Its native team (see setTeam); “” for its class’s own.
virtualWorld
Section titled “virtualWorld”
readonlyvirtualWorld:number
Defined in: server/api.d.ts:2012
The virtual world scripts put this entity in. Outside the shared map (Overland) replication combines it with the entity’s map, as it does a player’s.
waypoints
Section titled “waypoints”
readonlywaypoints:MoveWaypoint[]
Defined in: server/api.d.ts:1997
The running path’s points as given (gait resolved from the path’s default); empty when idle or following.