Please note that some information on this wiki is still based on the demo version.
If you notice any errors, feel free to correct them.

Module:Stats: Difference between revisions

From Super Fantasy Kingdom Official Wiki
wgg>Cadaei
format
wgg>Cadaei
added stats, table format
Line 5: Line 5:
-- argument name and full name (also used for icon name)
-- argument name and full name (also used for icon name)
local possibleStats = {{"hp", "Health Points"},
local possibleStats = {{"hp", "Health"},
  {"shield", "Shield"},
  {"sh", "Shield"},
  {"pdef", "Physical Defense"},
  {"pd", "Physical Defense"},
  {"mdef", "Magical Defense"},
  {"md", "Magical Defense"},
  {"dmg", "Damage"},
  {"dm", "Damage"},
  {"crit", "Critical Chance"},
  {"cr", "Critical Chance"},
  {"range", "Range"},
  {"ra", "Range"},
  {"cd", "Cooldown"},
  {"cd", "Cooldown"},
  {"aoe", "Area of Effect"}
  {"ar", "Area"},
  {"kb", "Knockback"},
  {"sp", "Speed"},
  {"du", "Duration"},
  {"gr", "Greed"},
  {"rr", "Reroll"},
  {"ba", "Banish"},
  {"cu", "Curse"}
  }
  }
local usedStats = {}
local usedStats = {}
local useInline = args.inline ~= nil
for i, s in ipairs(possibleStats) do
for a, v in pairs(args) do
if args[s[1]] then
local statName = possibleStats[a]
table.insert(usedStats, args[s[1]]..' [[File:'..s[2]..'.png|link='..s[2]..']]')
if v ~= '' and statName ~= nil and statName ~= '' then
table.insert(usedStats, p.StatEntryFormat(statName, v, useInline) )
end
end
end
end
Line 28: Line 37:
end
end
if args.inline ~= nil then
if useInline then
  -- one line, separated by bullet points
  -- one line, separated by bullet points
  return table.concat(usedStats, ' • ')
  return table.concat(usedStats, ' • ')
end
end
-- table
-- table format
return '<div style="text-align:right;display:inline-block">'..table.concat(usedStats, '<br/>')..'</div>'
return '<table style="text-align:right;display:inline-block">'..table.concat(usedStats, '')..'</table>'
end
 
function p.StatEntryFormat(name, val, inline)
if inline then
return '[[File:'..name..'.png|link='..name..']]&nbsp;'..val
else
return '<tr><td>[[File:'..name..'.png|link='..name..']]</td><td>'..val..'</td></tr>'
end
end
end


return p
return p

Revision as of 14:16, 15 July 2023

Displays stats for units. Call with Template:Stats, code is in Module:Stats.

Parameters

  • inline: If not empty stats will be shown in one line, else in a table format
  • align: Optional, valid values are left, center or right. It will display the stats in a simple column with the stated alignment.
  • hp: Health
  • ma: Mana
  • sh: Shield
  • pd: Physical Defense
  • md: Magical Defense
  • dm: Damage
  • cr: Critical Chance
  • ra: Range
  • cd: Cooldown
  • ar: Area
  • kb: Knockback
  • sp: Speed
  • du: Duration
  • rg: Rage
  • gr: Greed
  • rr: Reroll
  • ba: Banish
  • cu: Curse

Examples

{{stats|hp=33|dm=8|sh=4|cr=2%|pd=20%|md=10%}}


{{stats|hp=20.5|ra=8.33 m|cd=1.2 s|cr=2%}}


{{stats|hp=33|dm=8|sh=4|cr=2%|pd=20%|md=10%|inline=1}}


{{stats|hp=33|dm=8|sh=4|cr=2%|pd=20%|md=10%|align=center}}


{{stats
| first = Base stats
| second = Maxed<br/>Base stats
| dm = 5
| dm2 = 6.25
| dmGain = 1
| hp = 11
| hp2 = 14.3
| hpGain = 1
| sh = 13 m
| sh2 = 16.9 m
| shGain = 2
| cr = 5%
| cr2 = 5.63%
| crGain = 1
| pd = 0%
| pd2 = 15%
| pdGain = 3
| md = 0%
| md2 = 15%
| mdGain = 3
}}

local p = {}

function p.stats(f)
	local args = f:getParent().args
	
	-- argument name and full name (also used for icon name)
	local possibleStats = {{"hp", "Health"},
						   {"sh", "Shield"},
						   {"pd", "Physical Defense"},
						   {"md", "Magical Defense"},
						   {"dm", "Damage"},
						   {"cr", "Critical Chance"},
						   {"ra", "Range"},
						   {"cd", "Cooldown"},
						   {"ar", "Area"},
						   {"kb", "Knockback"},
						   {"sp", "Speed"},
						   {"du", "Duration"},
						   {"gr", "Greed"},
						   {"rr", "Reroll"},
						   {"ba", "Banish"},
						   {"cu", "Curse"}
						   }
	
	local usedStats = {}
	local useInline = args.inline ~= nil
	
	for a, v in pairs(args) do
		local statName = possibleStats[a]
		if v ~= '' and statName ~= nil and statName ~= '' then
			table.insert(usedStats, p.StatEntryFormat(statName, v, useInline) )
		end
	end
	
	if #usedStats == 0 then
	  return ''
	end
	
	if useInline then
	  -- one line, separated by bullet points
	  return table.concat(usedStats, ' &bull; ')
	end
		
	-- table format
	return '<table style="text-align:right;display:inline-block">'..table.concat(usedStats, '')..'</table>'
end

function p.StatEntryFormat(name, val, inline)
	if inline then
		return '[[File:'..name..'.png|link='..name..']]&nbsp;'..val
	else
		return '<tr><td>[[File:'..name..'.png|link='..name..']]</td><td>'..val..'</td></tr>'
	end
end

return p