Módulo:Npcinfo
This module is used to obtain the base statistics of each NPC.
It can calculate NPC stats for different stages/modes of the game (normal / expert pre-Hardmode / expert Hardmode / expert post-Plantera / master pre-Hardmode / master Hardmode / master post-Plantera ).
The code is synchronized with version 1.4.0.5(Versões para Computador, Console e Celular) of Terraria.
Usage
{{#invoke:Npcinfo|getInfo| id = <npcid> | prefix = <prefix for output varnames> }}
- id
NPC id. Can be -1 to -65, 1 to 662. (76/146/408 are unused)
- (optional) players
The number of active players, default is 1. For some bosses and boss-like NPCs in Expert mode, the number of players determines the health.
- (optional) prefix
The prefix for the output variable. Default is _npcinfo_. For example, the default variable name for damage is _npcinfo_damage. If you used prefix=my_, the variable name would be my_damage.
When you use this module, it sets a number of DPL variables you can retrieve by using {{#dplvar:_npcinfo_defense}}, for instance. Use {{getNpcInfo}} for easily retrieving these variables and using them in articles.
Main variables:
| dplvar (without prefix) |
Content |
|---|---|
| aiStyle | The id of the AI it uses. |
| banner | The item id of the enemy banner this enemy drops. 0 means no banner for this enemy. |
| boss | <empty> = false, 1 = true. |
| buffImmuneAll | Is it immune to all buffs? <empty> = false, 1 = true. |
| buffImmune | A comma-separated list of buffs the NPC is immune to. Only makes sense when buffImmuneAll is false. |
| friendly | Is it a friendly NPC? <empty> = false, 1 = true. |
| townNPC | Is it a town NPC? <empty> = false, 1 = true. |
| townCritter | Is it a town Critter?(by source code, NPCID.Sets.TownCritter) <empty> = false, 1 = true. |
| critter | Is it a critter? (by Critter page.)<empty> = false, 1 = true. |
| projectileNPC | Is it a projectile? <empty> = false, 1 = true. |
| playersCount | The value of the players parameter you used. |
| netID | NPC id, the value of the id parameter you used. |
| type | NPC type id. For a positive NPC id, it is equal to netID. For a negative NPC id, it is the id of the corresponding "master" variant. |
| internalName | NPC internal name. |
| HitSound | File name (without file extension, but it is usually .wav) of the sound effect that is played when this NPC takes damage (or reflects a projectile). Note that the listed sound is only the base sound; it might be played with modified pitch and volume in-game.
|
| DeathSound | File name (without file extension, but it is usually .wav) of the sound effect that is played when this NPC dies. Note that the listed sound is only the base sound; it might be played with modified pitch and volume in-game.
|
| damage damage_e damage_e_hm damage_e_pp damage_m damage_m_hm damage_m_pp |
damage / defense / knockBack / lifeMax values for normal, expert pre-Hardmode, expert Hardmode, expert post-Plantera, master pre-Hardmode, master Hardmode, and master post-Plantera, respectively. The knockBackResist values are original value, the value displayed in the NPC infobox is (1 - knockBackResist). |
| defense defense_e defense_e_hm defense_e_pp defense_m defense_m_hm defense_m_pp | |
| knockBackResist knockBackResist_e knockBackResist_e_hm knockBackResist_e_pp knockBackResist_m knockBackResist_m_hm knockBackResist_m_pp | |
| lifeMax lifeMax_e lifeMax_e_hm lifeMax_e_pp lifeMax_m lifeMax_m_hm lifeMax_m_pp | |
| value value_e value_e_hm value_e_pp value_m value_m_hm value_m_pp |
Coins dropped for normal, expert pre-Hardmode, expert Hardmode, and expert post-Plantera, respectively. Counted in Copper Coins. |
Examples
See the source code of this documentation for details.
id= -3 (Green Slime):
aiStyle: 1
boss:
buffImmune: 20
buffImmuneAll:
damage: 6
damage_e: 12
damage_e_hm: 86
damage_e_pp: 118
DeathSound: NPC_Killed_1
defense: 0
defense_e: 0
defense_e_hm: 0
defense_e_pp: 0
dontCountMe:
friendly:
HitSound: NPC_Hit_1
knockBackResist: 1.2
knockBackResist_e: 1.08
knockBackResist_e_hm: 1.08
knockBackResist_e_pp: 1.08
lifeMax: 14
lifeMax_e: 28
lifeMax_e_hm: 246
lifeMax_e_pp: 338
internalName: GreenSlime
netID: -3
npcSlots: 1
playersCount:
rarity: 0
scale: 0.9
townNPC:
townCritter:
type: 1
value: 3
value_e: 7
value_e_hm: 47
value_e_pp: 65
id=4 (Eye of Cthulhu):
aiStyle: 4
boss: 1
buffImmune: 31
buffImmuneAll:
damage: 15
damage_e: 30
damage_e_hm: 30
damage_e_pp: 30
DeathSound: NPC_Killed_1
defense: 12
defense_e: 12
defense_e_hm: 12
defense_e_pp: 12
dontCountMe:
friendly:
HitSound: NPC_Hit_1
knockBackResist: 0
knockBackResist_e: 0
knockBackResist_e_hm: 0
knockBackResist_e_pp: 0
lifeMax: 2800
lifeMax_e: 3640
lifeMax_e_hm: 3640
lifeMax_e_pp: 3640
internalName: EyeofCthulhu
netID: 4
npcSlots: 5
playersCount:
rarity: 0
scale: 1
townNPC:
townCritter:
type: 4
value: 30000
value_e: 75000
value_e_hm: 75000
value_e_pp: 75000
id=54 (Clothier, NPC):
aiStyle: 7
boss:
buffImmune: 31
buffImmuneAll:
damage: 10
damage_e: 10
damage_e_hm: 10
damage_e_pp: 10
DeathSound: NPC_Killed_1
defense: 15
defense_e: 15
defense_e_hm: 15
defense_e_pp: 15
dontCountMe:
friendly: 1
HitSound: NPC_Hit_1
knockBackResist: 0.5
knockBackResist_e: 0.5
knockBackResist_e_hm: 0.5
knockBackResist_e_pp: 0.5
lifeMax: 250
lifeMax_e: 250
lifeMax_e_hm: 250
lifeMax_e_pp: 250
internalName: Clothier
netID: 54
npcSlots: 1
playersCount:
rarity: 0
scale: 1
townNPC: 1
townCritter:
type: 54
value: 0
value_e: 0
value_e_hm: 0
value_e_pp: 0
local data = mw.loadData('Module:Npcinfo/data') -- loading data table.
local info = {
version = data['_terrariaversion'],
IDs = { -- min and max are both inclusive
min = -65,
max = 687,
}
}
info.IDs.isValid = function(id)
-- 76/146/408/547 are unused
return id ~= nil and type(id) == 'number' and id >= info.IDs.min and id ~= 0 and id <= info.IDs.max
end
local getArg = function(frame, key)
local value = frame.args[key]
if not value then
return nil
end
value = mw.text.trim(value)
if value == '' then
return nil
else
return value
end
end
local fields = {
'DeathSound',
'HitSound',
'Opacity',
'aiStyle',
'alpha',
'behindTiles',
'banner',
'boss',
'buffImmune',
'buffImmuneAll',
'buffImmuneAllNotWhips',
'catchItem',
'coldDamage',
'damage',
'damage_e',
'damage_e_hm',
'damage_e_pp',
'damage_m',
'damage_m_hm',
'damage_m_pp',
'defense',
'defense_e',
'defense_e_hm',
'defense_e_pp',
'defense_m',
'defense_m_hm',
'defense_m_pp',
'dontCountMe',
'dontTakeDamage',
'friendly',
'height',
'housingCategory',
'internalName',
'knockBackResist',
'knockBackResist_e',
'knockBackResist_e_hm',
'knockBackResist_e_pp',
'knockBackResist_m',
'knockBackResist_m_hm',
'knockBackResist_m_pp',
'lavaImmune',
'lifeMax',
'lifeMax_e',
'lifeMax_e_hm',
'lifeMax_e_pp',
'lifeMax_m',
'lifeMax_m_hm',
'lifeMax_m_pp',
'name',
'netAlways',
'netID',
'noGravity',
'noTileCollide',
'npcSlots',
'rarity',
'scale',
'timeLeft',
'townNPC',
'trapImmune',
'type',
'value',
'value_e',
'value_e_hm',
'value_e_pp',
'value_m',
'value_m_hm',
'value_m_pp',
'width',
}
local statname = {}
local clear = function(frame)
local prefix = getArg(frame, 'prefix') or '_npcinfo_'
local args = {}
for i,v in ipairs(fields) do
table.insert(args, prefix .. v)
table.insert(args, '')
end
frame:callParserFunction{ name = '#dplvar:set', args = args }
end
local p = {
-- info table for other modules
info = info,
-- info table data for templates
v = function(frame)
return info.version
end,
maxId = function(frame)
return info.IDs.max
end,
minId = function(frame)
return info.IDs.min
end,
isValidId = function(frame)
return info.IDs.isValid(tonumber(getArg(frame, 1)) or 0) and 1 or 0
end,
-- for templates: get all stats, set them in dplvars
getInfo = function(frame)
local npcid = tonumber(getArg(frame, 'id') or 0)
local prefix = getArg(frame, 'prefix') or '_npcinfo_'
local count = tonumber(getArg(frame, 'players') or 1)
if not npcid then
return
end
if not info.IDs.isValid(npcid) then
clear(frame) -- reset all dpl vars
return
end
local result
if count > 1 then
local getinfo = require('Module:Npcinfo/datagen').getInfo
result = getinfo(npcid, count)
local buffImmune = nil
for k, v in pairs(result.buffImmune) do
if v then
if buffImmune then
buffImmune = buffImmune .. ', ' .. k
else
buffImmune = k
end
end
end
result.buffImmune = buffImmune
else
result = {}
for k,v in pairs(data[0]) do
result[k] = v
end
for k,v in pairs(data[npcid]) do
result[k] = v
end
end
local args = {}
for k,v in pairs(result) do
args[#args + 1] = prefix .. k
args[#args + 1] = v
end
args[#args + 1] = prefix .. '_fields'
args[#args + 1] = table.concat(fields, ',')
args[#args + 1] = prefix
args[#args + 1] = 'InvalidNpcinfoStatName'
frame:callParserFunction{ name = '#dplvar:set', args = args }
end,
clear = clear,
-- for templates: get a specific stat of a specific NPC
getStat = function(frame)
local npcid = tonumber(getArg('id')) or tonumber(getArg(1)) or 0
local stat = getArg('stat') or getArg(2)
stat = statname[stat] or stat
if not info.IDs.isValid(npcid) then
return
end
if not stat then
return
end
return data[npcid][stat] or data[0][stat]
end,
-- for other modules: get a specific stat of a specific NPC
stat = function(npcid, stat)
stat = statname[stat] or stat
if not info.IDs.isValid(npcid) then
return
end
if not stat then
return
end
return data[npcid][stat] or data[0][stat]
end,
}
p.getinfo = p.getInfo
p.GetInfo = p.getInfo
p.getstat = p.getStat
p.GetStat = p.getStat
return p