Terraria Wiki

  • Discussions are now available on the Terraria Wiki.
  • Miss the old Hydra Skin? Try out our Hydralize gadget! Visit the preferences page while logged in and turn on the gadget.

READ MORE

Terraria Wiki
m (+buffImmuneAllNotWhips)
m (updated counts for 1.4.2.3)
Line 109: Line 109:
   
 
-- 76/146/408 not used.
 
-- 76/146/408 not used.
if npcid < -65 or npcid > 666 then
+
if npcid < -65 or npcid > 667 then
 
clear(frame) -- reset all dpl vars
 
clear(frame) -- reset all dpl vars
 
return
 
return
Line 146: Line 146:
 
stat = statname[stat] or stat
 
stat = statname[stat] or stat
   
if npcid < -65 or npcid > 666 then
+
if npcid < -65 or npcid > 667 then
 
return
 
return
 
end
 
end
Line 162: Line 162:
 
stat = statname[stat] or stat
 
stat = statname[stat] or stat
   
if npcid < -65 or npcid > 666 then
+
if npcid < -65 or npcid > 667 then
 
return
 
return
 
end
 
end

Revision as of 13:58, 16 May 2021

Lua logo Documentation The documentation below is transcluded from Module:Npcinfo/doc. (edit | history)

This module is used to obtain the base statistics of an NPC. It should only be used in templates and the like; use {{getNpcInfo}} in article text.

It can calculate NPC stats for different stages/modes of the game (Classic / Expert pre-Hardmode / Expert Hardmode / Expert post-Plantera / Master pre-Hardmode / Master Hardmode / Master post-Plantera).

The code is synchronized with version 1.4.3.1 of Terraria.

Usage

{{#invoke:Npcinfo | getInfo | id = <npcid> | prefix = <prefix for variables> (optional) }}</nowiki>

id

NPC id. Can be -1 to -65 or 1 to 662. (76/146/408 are unused)

prefix

The prefix for the output variables. Default is _npcinfo_. For example, the default variable name for damage is _npcinfo_damage. If $prefix was set to my_, the variable name would be my_damage.

Statistics

Invoking this module sets a number of DPL variables, one for each stat. They can be retrieved via {{#dplvar:<prefix><stat>}}, e.g. {{#dplvar:_npcinfo_defense}} for the defense stat with the default $prefix. The following table contains the most important stats:

dplvar
(without prefix)
Content
aiStyle The ID of the AI that the NPC uses.
banner The item ID of the enemy banner that the NPC drops.
boss The internal flag that determines whether the NPC is considered a boss. (<empty> = false, 1 = true)
buffImmune A comma-separated list of de-/buffs the NPC is immune to.
buffImmuneAll Whether the NPC is immune to all de-/buffs. (<empty> = false, 1 = true)
buffImmuneAllNotWhips Whether the NPC is immune to all de-/buffs, except whip debuffs. (<empty> = false, 1 = true)
coldDamage Whether the NPC is affected by the Warmth buff. (<empty> = false, 1 = true)
friendly Whether the NPC is a friendly NPC (e.g. a town NPC or critter). (<empty> = false, 1 = true)
housingCategory 1 if the NPC is a town pet, 0 otherwise.
internalName Internal name of the NPC.
lavaImmune Whether the NPC takes damage from lava. (<empty> = false, 1 = true)
netID ID of the NPC, the value of the $id parameter.
noGravity Whether the NPC is unaffected by gravity. (<empty> = false, 1 = true)
noTileCollide Whether the NPC can move freely through tiles. (<empty> = false, 1 = true)
npcSlots Number of NPC slots that the NPC occupies. See NPC spawning for explanation.
rarity Rarity level of the NPC for the Lifeform Analyzer.
townNPC Whether the NPC is a town NPC. (<empty> = false, 1 = true)
trapImmune Whether the NPC is completely unaffected by all traps. (<empty> = false, 1 = true)
type "Type ID" of the NPC. For a positive NPC ID, it is equal to netID. For a negative NPC ID, it is the ID of the corresponding "master" variant (e.g. 1 (Blue Slime) for -3 (Green Slime)).
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 resistance, and maximum health values for Classic, Expert pre-Hardmode, Expert Hardmode, Expert post-Plantera, Master pre-Hardmode, Master Hardmode, and Master post-Plantera, respectively.
The knockBackResist values are the original values as in the source code, the value displayed in {{npc infobox}}es on the wiki 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 Classic, Expert pre-Hardmode, Expert Hardmode, and Expert post-Plantera, respectively. Counted in Copper Coins.

In addition, a variable named _fields is set. It contains the names of all available statistics.

Examples

Stat
{{#dplvar:_<variable name>}}
Result
{{#invoke:Npcinfo|getInfo|id=<id>|prefix=_}}
Green Slime
id = -3
Eye of Cthulhu
id = 4
Clothier
id = 54
aiStyle147
alpha17500
banner292800
behindTiles
boss1
buffImmune203131
buffImmuneAll
buffImmuneAllNotWhips
catchItem000
coldDamage
damage61510
damage_e123010
damage_e_hm863010
damage_e_pp1183010
damage_m184510
damage_m_hm1294510
damage_m_pp1774510
DeathSoundNPC_Killed_1NPC_Killed_1NPC_Killed_1
defense01215
defense_e01215
defense_e_hm01215
defense_e_pp01215
defense_m01215
defense_m_hm01215
defense_m_pp01215
dontCountMe
dontTakeDamage
friendly1
height1711040
HitSoundNPC_Hit_1NPC_Hit_1NPC_Hit_1
housingCategory000
internalNameGreenSlimeEyeofCthulhuClothier
knockBackResist1.200.5
knockBackResist_e1.0800.5
knockBackResist_e_hm1.0800.5
knockBackResist_e_pp1.0800.5
knockBackResist_m0.9600.5
knockBackResist_m_hm0.9600.5
knockBackResist_m_pp0.9600.5
lavaImmune
lifeMax142800250
lifeMax_e283640250
lifeMax_e_hm2463640250
lifeMax_e_pp3383640250
lifeMax_m424641250
lifeMax_m_hm3694641250
lifeMax_m_pp5074641250
nameGreen SlimeEye of CthulhuClothier
netAlways
netID-3454
noGravity1
noTileCollide1
npcSlots151
Opacity
rarity000
scale0.911
timeLeft75022500750
townNPC1
trapImmune
type1454
value3300000
value_e7750000
value_e_hm47750000
value_e_pp65750000
value_m7750000
value_m_hm47750000
value_m_pp65750000
width2110018

local data = mw.loadData( 'Module:npcinfo/data' ) -- loading data table.

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 = {
	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

		-- 76/146/408 not used.
		if npcid < -65 or npcid > 667 then
			clear(frame) -- reset all dpl vars
			return
		end

		local 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
		
		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,


	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 npcid < -65 or npcid > 667 then
			return 
		end

		if not stat then
			return
		end

		return data[npcid][stat] or data[0][stat]

	end,

	-- for module.
	stat = function(npcid, stat)
		stat = statname[stat] or stat

		if npcid < -65 or npcid > 667 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