This module spits out the loot of a specific container. If it has multiple tiers the output will be tabbed. The output is not sorted - this is not possible.
Parameters
Must always call the main function. The second argument must be name of a container that is found in [[Module:Item spawns/containerData.json]
Example
{{#invoke:Container loot|main|Ammo Box}}
local p = {} --p stands for package
p.items = mw.loadJsonData( "User:VeryGreatFrog/sandbox2" )
p.lootPools = mw.loadJsonData( "User:VeryGreatFrog/sandbox3" )
p.containers = mw.loadJsonData( "User:VeryGreatFrog/sandbox4" )
local args = mw.getCurrentFrame().args
for k, v in pairs(p.containers) do
if args[1] == k then
p.container = k
p.spawns = v
break
end
end
p.output = ''
p.tables = {}
function p.main ( frame)
local isTabbed = false
if tablelength(p.spawns) > 1 then
isTabbed = true
end
for k, v in pairs(p.spawns) do
local spawns = p.lootPools[v]
local spawnOutput = "<table class=\"wikitable sortable\"><caption>Items in this container</caption><tr><th>Item</th><th>Max spawn chance</th></tr>"
local s = spawns['items']
for c, d in pairs(s) do
-- get the name of the item, using Icon link if possible
local name = c
if p.items[c] ~= nil then
local n = p.items[c]['inGameName']
n = string.gsub(n, 'ammo', 'Ammo')
name = frame:expandTemplate{ title = 'Icon link', args = { n } }
else
name = '[[' .. name .. ']]'
end
-- add it to our output
spawnOutput = spawnOutput .. "<tr><td>" .. name .. "</td><td>" .. round(d['chance'], 2) .. "% </td></tr>"
end
spawnOutput = spawnOutput .. '</table>'
p.tables[k] = spawnOutput
end
if isTabbed then
local text = ''
for k, v in pairs(p.spawns) do
text = text .. '|-|Tier ' .. tonumber(p.lootPools[v]["tier"]) .. '='
text = text .. p.tables[k]
end
return frame:callParserFunction('#tag:tabber', text)
-- frame:callParserFunction('#tag:tabber', '\nTest Text=\nTabber contents\n|-|Test text two=\nTest content yeye')
else
return p.tables[1]
end
return p.tables[1]
-- return p.output
end
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
-- thanks http://lua-users.org/wiki/SimpleRound
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
function sortFunction(a, b)
return a > b
end
return p