GetNpcData
getNpcData
Returns the complete authoritative state of a scripted NPC.
Syntax
table|false getNpcData(int npcId)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
npcId |
int |
yes | The server-assigned NPC identifier returned by spawnNpc or getNpcs.
|
Returns
Returns a table containing identity, owner resource, skin, armor, weapon, position, yaw, speed, route progress and pause state; otherwise returns false.
Examples
Read the current route state:
local npc = getNpcData(npcId)
if npc then
outputDebugString(("Route %d/%d"):format(npc.routeIndex, npc.routeCount))
end
Notes
- Available only in server-side resource scripts.
- Position and speed values use metres and metres per second; yaw uses degrees.
- Mutating functions accept only NPCs owned by the calling resource.