GetNpcData: Difference between revisions
Document G1R:MP 0.1.2 navigation collision API |
Document new NPC/player-mode API and events available from 0.1.5 |
||
| (One intermediate revision by the same user not shown) | |||
| Line 41: | Line 41: | ||
[[Category:World Functions]] | [[Category:World Functions]] | ||
[[Category:NPC Functions]] | [[Category:NPC Functions]] | ||
<!-- npc015:start --> | |||
== Additional fields since 0.1.5 == | |||
The existing table additionally returns weaponMode (string), animation (active alias or empty string), health, maxHealth, invulnerable, attackDamage and combatTarget (player ID, or 0). Use [[getNpcCombatMovement]], [[getNpcCombatConfig]] and [[getNpcCombatState]] for pursuit/projectile data. See [[NPC scripting]]. | |||
<!-- npc015:end --> | |||
<!-- npc-appearance015:start --> | |||
== Appearance API since 0.1.5 == | |||
Additional fields from 0.1.5: identity (string, default initially), identityExplicit (boolean, false until setNpcIdentity is called). Use [[getNpcSkinColor]] and [[getNpcTattoo]] for independent override values. Identity default with identityExplicit=false preserves legacy skin behaviour. | |||
<!-- npc-appearance015:end --> | |||
Latest revision as of 17:37, 25 September 2026
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 id, ownerResource, name, skin, armor, weapon, x, y, z, yaw, speed, routeIndex, routeCount, routeLoop, routeActive, paused, nameplateIdVisible, obstacleBehavior, navigationMode, and navigationCollisionMode; 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.
obstacleBehavioris"wait"or"avoid",navigationModeis"builtin"or"scripted", andnavigationCollisionModeis"combined","builtin", or"custom".- Mutating functions accept only NPCs owned by the calling resource.
Additional fields since 0.1.5
The existing table additionally returns weaponMode (string), animation (active alias or empty string), health, maxHealth, invulnerable, attackDamage and combatTarget (player ID, or 0). Use getNpcCombatMovement, getNpcCombatConfig and getNpcCombatState for pursuit/projectile data. See NPC scripting.
Appearance API since 0.1.5
Additional fields from 0.1.5: identity (string, default initially), identityExplicit (boolean, false until setNpcIdentity is called). Use getNpcSkinColor and getNpcTattoo for independent override values. Identity default with identityExplicit=false preserves legacy skin behaviour.