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
From Super Fantasy Kingdom Official Wiki
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 formatalign: Optional, valid values areleft,centerorright. It will display the stats in a simple column with the stated alignment.hp: Healthma: Manash: Shieldpd: Physical Defensemd: Magical Defensedm: Damagecr: Critical Chancera: Rangecd: Cooldownar: Areakb: Knockbacksp: Speeddu: Durationrg: Ragegr: Greedrr: Rerollba: Banishcu: Curse
Examples
{{stats|hp=33|dm=8|sh=4|cr=2%|pd=20%|md=10%}}
Lua error at line 6: attempt to call global 'create' (a nil value).
{{stats|hp=20.5|ra=8.33 m|cd=1.2 s|cr=2%}}
Lua error at line 6: attempt to call global 'create' (a nil value).
{{stats|hp=33|dm=8|sh=4|cr=2%|pd=20%|md=10%|inline=1}}
Lua error at line 6: attempt to call global 'create' (a nil value).
{{stats|hp=33|dm=8|sh=4|cr=2%|pd=20%|md=10%|align=center}}
Lua error at line 6: attempt to call global 'create' (a nil value).
{{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
}}
Lua error at line 6: attempt to call global 'create' (a nil value).
local p = {}
local statNames = require ('Module:Stats/StatNames')
function p.stats(f)
return create(f:getParent().args)
end
local function create(args)
local usedStats = {}
local useInline = args.inline ~= nil
local useGain = args.first ~= nil and args.second ~= nil
for _, statNames in ipairs(statNames) do
local statAbbreviation = statNames[1]
local statValue = args[statAbbreviation]
if statValue ~= nil and statValue ~= '' then
local statName = statNames[2]
local secondValue = ''
local gain = ''
if useGain then
secondValue = args[statAbbreviation..'2']
gain = args[statAbbreviation..'Gain']
table.insert(usedStats, statEntryFormatGain(statName, statValue, secondValue, gain))
else
table.insert(usedStats, statEntryFormat(statName, statValue, useInline, true))
end
end
end
if #usedStats == 0 then
return ''
end
if useInline then
-- one line, separated by bullet points
return table.concat(usedStats, ' • ')
end
-- table format
if useGain then
return '<table class="plainTable" style="text-align:left; display:inline-block; border-spacing: 0; border: 2px solid gray; padding: 1em">'..
'<tr><td></td><td colspan=3 style="text-align: center; font-weight: bold">'..args.first..'</td><td></td><td colspan=3 style="text-align: center; font-weight: bold">'..args.second..'</td></tr>'..
'<tr>'..table.concat(usedStats, '</tr><tr>')..'</tr></table>'
end
return '<table class="plainTable" style="text-align:left; display:inline-block; border-spacing: 0"><tr>'..table.concat(usedStats, '</tr><tr>')..'</tr></table>'
end
local function statEntryFormat(name, val, inline, withIcon)
if inline then
return '[[File:'..name..'.png|link='..name..'|16x16px]] '..val
else
local wholeNumberPart, decimalPart, unit = string.match(val, '^(%d*)(%.?%d*) ?(.*)$')
local iconColumn = ''
if withIcon then
iconColumn = '<td style="padding-right: 0.3em;">[[File:'..name..'.png|link='..name..'|16x16px]]</td>'
end
return iconColumn..'<td style="text-align: right; padding: 0">'..
wholeNumberPart..'</td><td style="padding: 0">'..decimalPart..'</td><td style="padding-left: 0.2em">'..unit..'</td>'
end
end
local function statEntryFormatGain(name, val, secondVal, gain)
local gainCell = ''
gain = tonumber(gain)
if gain ~= nil and gain >= 0 then
gainCell = '<td style="padding: 0 1em;">[[File:StatGain'..gain..'.png|12px]]</td>'
end
return statEntryFormat(name, val, false, true)..
gainCell..
statEntryFormat('', secondVal, false, false)
end
return p


