Module:NpcData/doc: Difference between revisions

Jump to navigation Jump to search
LVL (talk | contribs)
Updated to reflect new module code
LVL (talk | contribs)
No edit summary
Line 9: Line 9:
== Available Functions ==
== Available Functions ==


=== Get a Single Stat (`get_npc_var`) ===
=== Get a Single or Nested Stat (`get_npc_var`) ===
This is the most common function. It gets a single number or piece of text for an NPC.
This is the primary function for retrieving NPC data. It can get a simple top-level stat or traverse into nested objects and arrays using additional parameters.


'''Syntax'''
'''Syntax'''
<code><nowiki>{{#invoke:NpcData|get_npc_var|NPC Name|Stat Name|Rounding}}</nowiki></code>
<code><nowiki>{{#invoke:NpcData|get_npc_var|NPC Name|Key 1|Key 2|...|Rounding}}</nowiki></code>


'''Parameters'''
'''Parameters'''
* '''NPC Name:''' The internal key for the NPC. For example, `npc_boss_tier2` or `trooper_medic`.
* '''NPC Name:''' The internal key for the NPC. For example, `npc_boss_tier2` or `trooper_medic`.
* '''Stat Name:''' The name of the stat you want to look up. For example, `MaxHealth` or `StompDamage`.
* '''Key 1, Key 2, ...:''' The path to the stat you want.
* '''Rounding:''' (Optional) A number to round the result to that many significant figures.
** For a simple stat, this is just one key (e.g., `MaxHealth`).
** For a nested stat, provide each key as a separate parameter (e.g., `Shield`, `BaseAbsorptionPerSecond`).
* '''Rounding:''' (Optional) A number to round the result to that many significant figures. This should always be the last parameter.


'''Examples'''
'''Examples'''
* To get the stomp damage of the Tier 2 Boss:
* To get the max health of a Medic Trooper (a simple stat):
** '''Code:''' <code><nowiki>{{#invoke:NpcData|get_npc_var|npc_boss_tier2|StompDamage}}</nowiki></code>
** '''Result:''' {{#invoke:NpcData|get_npc_var|npc_boss_tier2|StompDamage}}
 
* To get the max health of a Medic Trooper:
** '''Code:''' <code><nowiki>{{#invoke:NpcData|get_npc_var|trooper_medic|MaxHealth}}</nowiki></code>
** '''Code:''' <code><nowiki>{{#invoke:NpcData|get_npc_var|trooper_medic|MaxHealth}}</nowiki></code>
** '''Result:''' {{#invoke:NpcData|get_npc_var|trooper_medic|MaxHealth}}
** '''Result:''' {{#invoke:NpcData|get_npc_var|trooper_medic|MaxHealth}}
* To get the base shield absorption of the Mid-Boss (a nested stat):
** '''Code:''' <code><nowiki>{{#invoke:NpcData|get_npc_var|npc_super_neutral|Shield|BaseAbsorptionPerSecond}}</nowiki></code>
** '''Result:''' {{#invoke:NpcData|get_npc_var|npc_super_neutral|Shield|BaseAbsorptionPerSecond}}
* To get the name of the Tier 2 Boss's first bound ability (nested in an object and an array):
** '''Code:''' <code><nowiki>{{#invoke:NpcData|get_npc_var|npc_boss_tier2|BoundAbilities|1|Name}}</nowiki></code>
** '''Result:''' {{#invoke:NpcData|get_npc_var|npc_boss_tier2|BoundAbilities|1|Name}}


* If you misspell a stat, you will see an error:
* If you misspell a stat, you will see an error:
** '''Code:''' <code><nowiki>{{#invoke:NpcData|get_npc_var|trooper_medic|MaxHeath}}</nowiki></code> <!-- Note the typo -->
** '''Code:''' <code><nowiki>{{#invoke:NpcData|get_npc_var|trooper_medic|MaxHeath}}</nowiki></code> <!-- Note the typo -->
** '''Result:''' {{#invoke:NpcData|get_npc_var|trooper_medic|MaxHeath}}
** '''Result:''' {{#invoke:NpcData|get_npc_var|trooper_medic|MaxHeath}}
----
=== Get a Nested Stat (`get_nested_var`) ===
This function retrieves values inside nested objects or arrays using dot notation.
'''Syntax'''
<code><nowiki>{{#invoke:NpcData|get_nested_var|NPC Name|Path|Rounding}}</nowiki></code>
'''Parameters'''
* '''NPC Name:''' The internal key for the NPC.
* '''Path:''' Dot-separated keys, e.g., `Shield.BaseAbsorptionPerSecond` or `BoundAbilities.1.Name`.
* '''Rounding:''' (Optional) A number to round the result to that many significant figures.
'''Examples'''
* To get the base shield absorption of the Super Neutral:
** '''Code:''' <code><nowiki>{{#invoke:NpcData|get_nested_var|npc_super_neutral|Shield.BaseAbsorptionPerSecond}}</nowiki></code>
** '''Result:''' {{#invoke:NpcData|get_nested_var|npc_super_neutral|Shield.BaseAbsorptionPerSecond}}
* To get the name of the Tier 2 Boss's first bound ability:
** '''Code:''' <code><nowiki>{{#invoke:NpcData|get_nested_var|npc_boss_tier2|BoundAbilities.1.Name}}</nowiki></code>
** '''Result:''' {{#invoke:NpcData|get_nested_var|npc_boss_tier2|BoundAbilities.1.Name}}


----
----
=== Get an Item from a List (`get_list_elem`) ===
=== Get an Item from a List (`get_list_elem`) ===
Some NPCs have data stored in lists (or arrays). This function lets you get a single item from a list by its position.
While `get_npc_var` can also access list items, this function is specifically for that purpose and is used by {{tl|NpcData}} when the `index` parameter is set.


'''Syntax'''
'''Syntax'''