Attention Mobile version Mobile Users! Registration for Mobile 1.3 Beta Testing is live! Register here!

Module:Iteminfo

From Terraria Wiki
Jump to: navigation, search

This module is used to obtain some base statistics of each item.

The code is synchronized with version 1.3.5.3Desktop Version of Terraria.

Usage[edit source]

Get all stats at a time: {{#invoke:iteminfo|getInfo| id = <itemid> | prefix = <prefix for output varnames> }} or {{#invoke:iteminfo|getInfo| <itemid> | <prefix for output varnames> }}

id

item id. 1 to 3929, and please note there are also some deprecated IDs in the range (2772 to 2775, 2777 to 2780, 2782 to 2785, 2881, 3273, 3340 to 3346, 3462 to 3465, 3750, 3847 to 3851, 3861, 3862).

(optional) prefix

The prefix for the output variable. Default is _iteminfo_. For example, the default variable name for value is _iteminfo_value. If you used prefix=my_, the variable name would be my_value. When you use this method, it sets a number of DPL variables, then you can retrieve them by using {{#dplvar:_iteminfo_value}}, for instance. This is because retrieve from dplvar is much faster then lua script.


Get single stat: {{#invoke:iteminfo|getStat| id = <itemid> | stat = <statname> }} or {{#invoke:iteminfo|getStat| <itemid> | <statname> }}

id

item id. 1 to 3929, and please note there are also some deprecated IDs in the range (2772 to 2775, 2777 to 2780, 2782 to 2785, 2881, 3273, 3340 to 3346, 3462 to 3465, 3750, 3847 to 3851, 3861, 3862).

(optional) stat

Stat name. See the table below.


Use {{getItemInfo}} for easily retrieving these variables and using them in articles.

If you are not sure if the ID you specified is valid, please check {{#dplvar:_iteminfo_type}}, it will be the ID when it's valid, and blank when the ID is invalid.

All return fields are listed below. Please note not all of them are used, see note info of each row. And please also refer to these tModLoader and tConfig documentations.

Note: You can get the item name from the Item ID by using {{ItemNameFromId}}.

dplvar
(without prefix)
Default Value Example
(take ID = 757 for example)
note
type 757 item ID. If the ID specified as argument is valid, this value will be that number. Or this value will be blank.
internalName TerraBlade Internal name of the item.
name Terra Blade Name of the item.
DD2Summon if set, means this item is a item relatived to Old One's Army, and the buy price will be calculated using Defender Medal instead of gold coins. 1 gold coin equal to 1 Defender Medal.
ToolTip Currently always empty. reserved for future.
material Currently always empty. reserved for future.
accessory If set, this is an accessory item.
ammo 0 0 AmmoID (used in field useAmmo) not only, e.g. 353, 154
autoReuse 1 if set, means this item can auto-fire/auto-swing/auto-use.
axe 0 0 Axe Power. 1 means 5%. e.g. axe = 23 means Axe Power of this item is 115%.
bait 0 0 Bait power, in %. e.g 50 means 50% bait power.
buffTime 0 0 Time the buff this item grants will be in effect in ticks (1 tick = 1/60 second and 1/3600 minute). I.e. if buffTime=14400, it means that the buff will be in effect for 240 seconds (14400/60 = 240) which is equal to 4 minutes (14400/3600 = 4).
buffType 0 0 Buff ID of the buff this item grants.
cartTrack Is set for Minecart Tracks.
channel If set, means that the item can/needs be used continuously ("channeling cast!",different from autoswing, though!) Is set for Flails and Yoyos, Chainsaws and Drills, Magic Missile and its upgrades, Dirt Rod, Piranha Gun, Chlorophyte Jackhammer, Laser Machinegun, Charged Blaster Cannon, Flying Knife, Medusa Head, Arkhalis, Portal Gun, Vortex Beater, Phantasm, The Grand Design, Last Prism, Sleepy Octopod, Ghastly Glaive, Phantom Phoenix, Sky Dragon's Fury. and it also be set on certain Pet/Light Pet/Mount summoning items, since they will continuously effect.
consumable Is set for items that are consumables (which means all items in Category:Consumable items). Note that this is distinct from the ingame concept "Consumable"! See Category:Consumable items for clarification. If this attribute is set to True, then one item from the stack is removed each time the item is used.
createTile -1 -1 Tile ID of the tile this item produces when placed.placeStyle is Tile sub ID.
placeStyle 0 0
createWall -1 -1 Wall ID of the wall this item produces when placed.
crit 0 0 Critical strike chance in % that is added to the base 4%, e.g. if this is 2, it means the item has a crit chance of 6%. if this is 4, actual crit is 8%.
damage -1 95 Base damage of the item.
defense 0 0 Defense of the item.
dye 0 0 if it's non-zero, means this is a dye item.
expert When it's set, this item will be displayed as Rainbow Rarity.
fishingPole 0 0 Fishing Power of the item in %, e.g. if fishingPole = 27, it means the item has a 27% fishing power.
flame Set for each kind of Torch and for Water, Peace, Platinum, and regular Candle. Interestingly, it is also set for Brand of the Inferno.
hairDye -1 -1 0 for Hair Dye Remover and positive number for other Hair Dyes.
hammer 0 0 Hammer power, in %. e.g. hammer = 90 means 90% hammer power.
healLife 0 0 Amount of Health Points this item restores when used.
healMana 0 0 Amount of Mana this item restores when used.
holdStyle 0 0 Can only be a value between 0 and 3. Is set to 1 for each kind of Torch and Water, Peace, Platinum, and regular Candle, Sticky, Bouncy, Spelunker and regular Glowstick, Ale, Unicorn on a Stick, Flare Gun, Marshmallow on a Stick, Nebula Arcanum. Is set to 2 for Breathing Reed, Umbrella. Is set to 3 for Magical Harp.
knockBack 0 6.5 Knockback value of the item.
lifeRegen 0 0 Can only be 0 or 1. Is set to 1 for Band of Regeneration and Charm of Myths.
makeNPC 0 0 when it's not zero, means that it will spawn NPC when used. The value is the NPC ID of the spawn NPC.
mana 0 0 Amount of Mana this item uses.
maxStack 1 1 max stack limit.
mech If set, this is a mechanism item. Whether this item shows wires when held.
melee 1 If set, this item deals melee damage.
magic If set, this item deals magic damage.
ranged If set, this item deals ranged damage.
summon If set, this item deals summon damage.
thrown If set, this item deals thrown damage.
mountType -1 -1 Mount ID of the mount this item summons when used.
noMelee Whether this item is allowed to deal damage with its sprite. Typically set to true for a ranged weapon, which would rely on its projectiles to deal damage, instead.
noUseGraphic Whether this item's sprite is drawn while it is in use. Thrown weapons like Dynamite uses this, because it is immediately tossed to the ground to create the illusion of being used.
noWet If set, the item cannot be held/placed underwater: Unicorn on a Stick, every kind of Candle and every kind of Torch (without Cursed and Ichor Torch). However, is also set for Timers which can be placed underwater.
notAmmo Is only set for Coins, Ale, Wire. Aside from Wire, these share the trait of not being able to be put in the ammo slot of the inventory, even though there are used as ammunition. Wire can be placed in that slot, though.
paint 0 0 If not 0, it means the item is Paint. The value is some sort of internal "Paint ID", ranging from 1 (Red Paint) to 30 (Negative Paint).
pick 0 0 pickpower, in %. e.g. pick =150 means 150% Pickaxe power.
potion If set to true, you may not use any other items with this attribute until the cooldown elapses. This applies to healing items and mushrooms.
rare 0 8 Rarity of the item. Not valid if expert is set, as that makes the item have the Rarity level: Rainbow rarity.
reuseDelay 0 0 The time in frames before this item may be used again, commonly called "Use Delay". There are 60 frames in one second. Currently only set for Clockwork Assault Rifle, Medusa Head, Last Prism, Sky Fracture, and Betsy's Wrath.
sentry If set, this item is a sentry summon item.
shoot 0 132 If it's not zero, it's the Projectile ID of the Projectile fired by the item.
shootSpeed 0 12 Velocity of the projectile fired by the item.
stringColor the color type of Strings, only for String items.
tileBoost 0 0 range bonus, e.g. tileBoost=4 means +4 range
tileWand -1 -1 Item ID of the block this Block-placing wand places.
questItem Is only set for Quest Fish.
uniqueStack Is only set for Quest Fish. See Fishing#Fishing Quests for details regarding the special quality of these items.
useAmmo 0 0 Type of ammunition this item uses. 23 for Gel, 40 for Arrow, 71 for Coin, 75 for FallenStar, 97 for Bullet, 169 for Sand, 283 for Dart, 771 for Rocket, 780 for Solution, 931 for Flare, 949 for Snowball, 1261 for Stynger Bolt, 1783 for Candy Corn, 1785 for Jack 'O Lantern, 1836 for Stake, 3108 for Nail.
useAnimation 100 16 How long it takes the animation to play for the item, in frames. An interesting quirk is that if the useTime is lower than the useAnimation, it will be activated one or more times per use (e.g. Golden Shower). If the item is an auto-swinging sword, Use time of the item (that is displayed in the game and on the wiki) is useAnimation - 1.
useStyle 0 1 1= General Swinging/Throwing, 2=Eating/Using , 3=Stabbing, 4=Holding up,5= Holding Out. see the list
useTime 100 16 Tool speed for tools, (internal) use time for others. How long it takes to use the item, in frames. While the item is in use, you cannot take other actions.
useTurn Whether the player will turn to face the direction the player is moving when the item is used. For example, a sword would make you face left or right, but a spear would not. Set this to false to prevent the player from switching directions while swinging a weapon.
value 0 1000000 Buy value, in copper coins. sell value = buy value / 5. If DD2Summon = 1, will be converted according to 1 gold coin equal to 1 Defender Medal. Template:Coin helps formatting this value in order to display it properly.
vanity If set, this item is a vanity item.

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

local trim = mw.text.trim

-- cache
local currentFrame

-- helper function
local getArg = function(key)
	local value = currentFrame.args[key]
	if not value then
		return nil
	end
	value = trim(value)
	if value == '' then
		return nil
	else
		return value
	end
end

---------------------------

local p = {
	-- for other module, get all stats, return as a table.
	getItemInfo = function(itemid)
		if itemid >= 3930 or itemid <= 0 then
			itemid = 0
		end
		local d = data[itemid]
		local result = {}
		for k,v in pairs(data[0]) do
			if d[k] ~= nil and d[k] ~= v then
				result[k] = d[k]
			else
				result[k] = v
			end
		end
		return result
	end,

	-- for template, get all stats, setting in dplvars.
	getInfo = function(frame)
		currentFrame = frame -- cache

		local itemid = tonumber(getArg('id')) or tonumber(getArg(1)) or 0
		local prefix = getArg('prefix') or getArg(2) or '_iteminfo_'

		if itemid >= 3930 or itemid <= 0 then
			itemid = 0
		end
		
		local result = data[itemid]
		local args = {}
		for k,v in pairs(data[0]) do
			table.insert(args, prefix .. k)
			if result[k] ~= nil and result[k] ~= v then
				table.insert(args, result[k])
			else
				table.insert(args, v)
			end
		end

		frame:callParserFunction{ name = '#dplvar:set', args = args }
	end,

	-- for other module, get single stat, return this stat directly
	getItemStat = function(itemid, stat)
		if itemid >= 3930 or itemid <= 0 then
			itemid = 0
		end
		return data[itemid][stat] or data[0][stat]
	end,

	-- for template, get single stat, return directly
	getStat = function(frame)
		currentFrame = frame -- cache

		local itemid = tonumber(getArg('id')) or tonumber(getArg(1)) or 0
		local stat = getArg('stat') or getArg(2)

		if not stat then
			return
		end

		if itemid >= 3930 or itemid <= 0 then
			itemid = 0
		end
		
		return data[itemid][stat] or data[0][stat] or nil -- "or nil" will convert "false" to "nil"
		
	end,
}

--alias
p.getinfo = p.getInfo
p.GetInfo = p.getInfo
p.getstat = p.getStat
p.GetStat = p.getStat

return p