Module:Creatures: Difference between revisions
Jump to navigation
Jump to search
TheGmaster (talk | contribs) No edit summary Tag: Manual revert |
TheGmaster (talk | contribs) No edit summary |
||
Line 19: | Line 19: | ||
local baseTable = {["name"]="",["dungeon"]="",["name"]="",["slayer"]="",["difficulty"]="",["goldvalue"]="",["hits"]="",["mindmg"]="",["maxdmg"]="",["wrestling"]="",["armor"]="",["magicresist"]="",["poisontype"]="",["poisoning"]="",["poisonresist"]="",["ai"]="",["speed"]="",["uniquescaler"]="",} | local baseTable = {["name"]="",["dungeon"]="",["name"]="",["slayer"]="",["difficulty"]="",["goldvalue"]="",["hits"]="",["mindmg"]="",["maxdmg"]="",["wrestling"]="",["armor"]="",["magicresist"]="",["poisontype"]="",["poisoning"]="",["poisonresist"]="",["ai"]="",["speed"]="",["uniquescaler"]="",} | ||
for i, creature in pairs( | for i, creature in pairs(creatureArray) do | ||
local creatureTable = cloneTable(baseTable) | local creatureTable = cloneTable(baseTable) | ||
for index, stat in pairs(creatureTable) do | for index, stat in pairs(creatureTable) do | ||
local data = string.match(creatureTable[i],index.."= (%a+)\n") | local data = string.match(creatureTable[i],index.."= (%a+)\n") | ||
if data then | |||
stat = data | |||
end | |||
end | end | ||
end | end |
Revision as of 02:16, 21 August 2024
Documentation for this module may be created at Module:Creatures/doc
local p = {} function cloneTable (t) -- t is a table local new_t = {} -- create a new table local i, v = next(t, nil) -- i is an index of t, v = t[i] while i do new_t[i] = v i, v = next(t, i) -- get next index end return new_t end function p.listCreatures( frame ) -- Parameters passed when the function is invoked local creatureList = frame.args[1] -- {|name=... local creatureName = frame.args[2] -- Sun Wyrm local creatureArray = mw.text.split(creatureList,"|}\n{|",true) local baseTable = {["name"]="",["dungeon"]="",["name"]="",["slayer"]="",["difficulty"]="",["goldvalue"]="",["hits"]="",["mindmg"]="",["maxdmg"]="",["wrestling"]="",["armor"]="",["magicresist"]="",["poisontype"]="",["poisoning"]="",["poisonresist"]="",["ai"]="",["speed"]="",["uniquescaler"]="",} for i, creature in pairs(creatureArray) do local creatureTable = cloneTable(baseTable) for index, stat in pairs(creatureTable) do local data = string.match(creatureTable[i],index.."= (%a+)\n") if data then stat = data end end end end return p