Module:Container loot

local p = {} --p stands for package

p.items = mw.loadJsonData( "Module:Item infobox/itemData.json" ) p.lootPools = mw.loadJsonData( "Module:Item spawns/lootPoolData.json" ) p.containers = mw.loadJsonData( "Module:Item spawns/containerData.json" )

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 ) p.output = p.output .. frame:expandTemplate{title = 'Notice', args = { "The table describes the typical loot of the container. Some containers of this type might have different or unique loot in them. Those containers are not shown in this list. The spawn chances are an approximation and should not be taken as exact values." } }	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 = " '		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 p.output .. frame:callParserFunction('#tag:tabber', text) else return p.output .. p.tables[1] end 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

return p