Module:Spawn table

local p = {}

local spawnData = {} -- contains mob spawn info local groupArgs = {'creature', 'ambient', 'monster', 'water'}

local function parseInput(args) for _, argName in ipairs(groupArgs) do		local groupArg = args[argName] if groupArg then spawnData[argName] = {} local currentGroup = {} local totalWeight = 0 currentGroup.mobs = {} groupArg = groupArg .. '\n' -- allow last line to be matched like the rest -- parse input of group parameter for line in mw.ustring.gmatch(groupArg, '[^\r\n]+[\r\n]') do -- split on newline local parsedLine = {} for key, value in mw.ustring.gmatch(line, '([%a]+)%s*:%s*(.-)%s*[,\r\n]') do					if value ~= '' then parsedLine[key:lower] = value end end if parsedLine.mob then currentGroup.mobs[mob] = {} end -- convert weight to number; becomes nil if conversion fails if parsedLine.weight then weightNum = tonumber(parsedLine.weight) -- if converted to number successfully if weightNum then currentGroup.mobs.mob.weight = weightNum totalWeight = totalWeight + weightNum end end if parsedLine.count then currentGroup.mobs.mob.count = parsedLine.count end end spawnData[argName] = currentGroup end end end

local function createTableBody local outputTable = {} for key, value in pairs(spawnData) do	end return table.concat(outputTable, '\n|-\n') end

function p.mobSpawnTable(frame) local args = frame if frame == mw.getCurrentFrame then args = require('Module:ProcessArgs').merge( true ) else frame = mw.getCurrentFrame end local outputTable = {}	-- list of strings to be concatenated into final output local columns = {'Mob', 'Weight', 'Group size'} local title = 'Mob spawn list' -- create final output table.insert(outputTable, '{| class = "wikitable"') table.insert(outputTable, '! colspan = ' .. #columns .. ' | ' .. title) local columnsStr = '! '	for index, value in pairs(columns) do		if index ~= 1 then columnsStr = columnsStr .. ' !! '		end columnsStr = columnsStr .. ' ' .. value end table.insert(outputTable, columnsStr) table.insert(outputTable, createTableBody) table.insert(outputTable, '|}') return table.concat(outputTable, '\n|-\n') end

return p