Module:NpcData/doc: Difference between revisionsGive feedback
Updated to reflect new module code |
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 | 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| | <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`. | ||
* ''' | * '''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 max health of a Medic Trooper (a simple stat): | |||
* 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 an Item from a List (`get_list_elem`) === | === Get an Item from a List (`get_list_elem`) === | ||
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''' | ||
Revision as of 15:10, 14 November 2025
This module allows you to display stats for any NPC (Non-Player Character) from the game's data files which can be found here Data:NpcData.json. For most uses, it is recommended to use the {{NpcData}} template.
How to Use
To get data from the module, you use a command that looks like {{#invoke:NpcData|...}}. You will tell it which function to use, which NPC you want, and what information you need.
The basic format is:
{{#invoke:NpcData|function_name|parameter1|parameter2|...}}
Available Functions
Get a Single or Nested Stat (`get_npc_var`)
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
{{#invoke:NpcData|get_npc_var|NPC Name|Key 1|Key 2|...|Rounding}}
Parameters
- NPC Name: The internal key for the NPC. For example, `npc_boss_tier2` or `trooper_medic`.
- Key 1, Key 2, ...: The path to the stat you want.
- 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
- To get the max health of a Medic Trooper (a simple stat):
- Code:
{{#invoke:NpcData|get_npc_var|trooper_medic|MaxHealth}} - Result: 350
- Code:
- To get the base shield absorption of the Mid-Boss (a nested stat):
- Code:
{{#invoke:NpcData|get_npc_var|npc_super_neutral|Shield|BaseAbsorptionPerSecond}} - Result: Error: Key "Shield" not found in path "npc_super_neutral".
- Code:
- To get the name of the Tier 2 Boss's first bound ability (nested in an object and an array):
- Code:
{{#invoke:NpcData|get_npc_var|npc_boss_tier2|BoundAbilities|1|Name}} - Result: Error: Key "1" not found in path "npc_boss_tier2.BoundAbilities".
- Code:
- If you misspell a stat, you will see an error:
- Code:
{{#invoke:NpcData|get_npc_var|trooper_medic|MaxHeath}} - Result: Error: Key "MaxHeath" not found in path "trooper_medic".
- Code:
Get an Item from a List (`get_list_elem`)
While `get_npc_var` can also access list items, this function is specifically for that purpose and is used by {{NpcData}} when the `index` parameter is set.
Syntax
{{#invoke:NpcData|get_list_elem|NPC Name|List Name|Position Number}}
Parameters
- NPC Name: The internal key for the NPC.
- List Name: The name of the list property, e.g., `NearbyEnemyResistanceValues`.
- Position Number: The position in the list. The first item is `1`, the second is `2`, and so on.
Example
- The Tier 2 Boss has a list of resistance values. To get the 4th value in that list:
- Code:
{{#invoke:NpcData|get_list_elem|npc_boss_tier2|NearbyEnemyResistanceValues|4}} - Result: Script error: The function "get_list_elem" does not exist.
- Code: