Module:ListTrapRecipes
Jump to navigation
Jump to search
Module used to list traps.
Can optionally supply a basetrap
argument to filter traps to Tripwire Trap or Pressure Plate Trap.
Usage
{{#invoke:ListTrapRecipes|main|basetrap=}}
The above documentation is transcluded from Module:ListTrapRecipes/doc. (edit | history)
local p = {}
function p.main(frame)
if frame == mw.getCurrentFrame() then
args = require('Module:ProcessArgs').merge(true)
else
frame = mw.getCurrentFrame()
end
local cargoWhere = ''
if (args.basetrap) then
cargoWhere = 'baseTrap = "' .. args.basetrap .. '"'
end
local result = mw.ext.cargo.query('TrapRecipes',
'_pageName,ingredients,basetrap,effects',
{
where = cargoWhere,
orderBy = '_pageName',
limit = 5000
}
)
if not result or #result < 1 then return 'No traps found' end
local out = '{| class="wikitable sortable"\n|-\n'
out = out .. '! Trap !! '
if not args.basetrap then
out = out .. 'Trap type !! '
end
out = out .. 'Armed With !! Effects\n'
for i,row in ipairs(result) do
out = out .. '|-\n'
out = out .. '| [[' .. row._pageName .. ']]'
if not args.basetrap then
out = out .. '|| [[' .. row.basetrap .. ']] '
end
out = out .. '|| '
local ings = p.split(row.ingredients, ',')
for _,ing in ipairs(ings) do
out = out .. '[[' .. ing .. ']]<br>'
end
out = out .. ' || ' .. row.effects
out = out .. '\n'
end
out = out .. '|}'
return frame:preprocess(out)
end
-- splits the input string into a table by the provided seperator
function p.split(inputstr, sep)
local t={}
for str in string.gmatch(inputstr .. ',', "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
return p