Module:Scavenge

local p = {} function p.gui( f ) local function getTemplateArgs( str ) local result = {} for v in mw.text.gsplit(str, "|", true) do                   local pair = mw.text.split(v, "=", true) if table.getn(pair) == 2 then result[pair[1]] = pair[2] else table.insert(result, v)                   end end return result end local args = f.args or f       if f == mw.getCurrentFrame and args[1] == nil then args = f:getParent.args else f = mw.getCurrentFrame end local tool = args[1] or '' local block = args[2] or '' local output = {} local total = 0 -- Iterate through the Scavenge inventory slots and gathers valid cells. -- Format should be a Grid Cell template with the weight = number for i=3,38 do               local drop = {} if args[i] ~= nil then local arg = args[i] local len = mw.ustring.len(arg) local temp = getTemplateArgs(mw.ustring.sub(arg, 6, len-2)) mw.logObject(temp) drop.cell = mw.ustring.gsub(arg, "|weight=" .. temp.weight, "") drop.weight = tonumber(temp.weight) if drop.cell ~= nil and drop.weight ~= nil then table.insert(output, drop) total = total + drop.weight end end end

local result = {} table.insert(result, tool) table.insert(result, block) for i,drop in ipairs(output) do               local cell = drop.cell local len = mw.ustring.len(cell) cell = mw.ustring.sub(cell, 0, len-2) cell = cell .. "|desc=" .. (drop.weight/total*100) .. "% Chance}}" table.insert(result, cell) end

local grid = f:expandTemplate{title = "Cg/Scavenge", args = result} -- mw.logObject(grid) return grid end

return p