Module:ListOfNPCs

local i18n = { Id = 'ID', Image = 'Image', Name = 'Name', Health = 'Max Health', Damage = 'Damage', Defense = 'Defense', Kbresist = 'Knockback Resistance', AI = 'AI', Money = 'Money Dropped', Environment = 'Environment', Type = 'Type', Deprecated = '(Deprecated)',

type_townNPC = 'Town NPC', type_projectileNPC = 'projectile', type_critter = 'Critter', type_friendly = 'friendly', type_default = 'Enemy',

} local trim = mw.text.trim

local id_start, id_end = -65, 662 -- as in 1.4.0.5

local data={} local unused = require('Module:Npcinfo/idSets').getIdSet('Unused') local npcstat = require('Module:Npcinfo').stat

local last = id_start local output = mw.html.create('table'):addClass('terraria sortable lined aligncenter') local currentFrame local na

local function v(value) if value and trim(value) ~= '' then return value else return na	end end

function typeof(npcid) if npcstat(npcid, 'townNPC') then return i18n.type_townNPC elseif npcstat(npcid, 'projectileNPC') then return i18n.type_projectileNPC elseif npcstat(npcid, 'critter') then return i18n.type_critter elseif npcstat(npcid, 'friendly') then return i18n.type_friendly else return i18n.type_default end end

function printNoCargoRow(id) local tr = output:tag('tr') tr:tag('td'):wikitext(id) if unused[id] then tr:tag('td'):attr('colspan', 10):tag('i'):addClass('note-text'):wikitext(i18n.Deprecated) else tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') end

end

function printRow(row) local npcid = tonumber(row.npcid) if npcid == 0 then return end

if npcid > last + 1 then for id = last+1, npcid-1 do			printNoCargoRow(id) end end

local tr = output:tag('tr') tr:tag('td'):wikitext(npcid) tr:tag('td'):wikitext(v(row.image)) tr:tag('td'):wikitext(v(row.name)) tr:tag('td'):wikitext(v(row.life)) tr:tag('td'):wikitext(v(row.damage)) tr:tag('td'):wikitext(v(row.defense)) tr:tag('td'):wikitext(v(row.knockback)) tr:tag('td'):wikitext(v(row.ai)) tr:tag('td'):wikitext(v(row.money)) tr:tag('td'):wikitext(v(currentFrame:callParserFunction('#lstmaptemp',row.environment, 'npc_infobox/environment', '/', '&#32;/&#32;'))) tr:tag('td'):wikitext(typeof(npcid)) last = npcid end

return { main=function(frame) currentFrame = frame na = frame:expandTemplate{title = 'na', args = {'-'}} local header = output:tag('tr') header:tag('th'):wikitext(i18n.Id) header:tag('th'):wikitext(i18n.Image) header:tag('th'):wikitext(i18n.Name) header:tag('th'):wikitext(i18n.Health) header:tag('th'):wikitext(i18n.Damage) header:tag('th'):wikitext(i18n.Defense) header:tag('th'):wikitext(i18n.Kbresist) header:tag('th'):wikitext(i18n.AI) header:tag('th'):wikitext(i18n.Money) header:tag('th'):wikitext(i18n.Environment) header:tag('th'):wikitext(i18n.Type)

local result = mw.ext.cargo.query(		'NPCs',		'npcid,name,image,life,damage,defense,knockback,ai,money,environment',		{			groupBy = 'npcid',			orderBy = 'npcid',			where = 'npcid IS NOT NULL and npcid < 1000',			limit = 1000		}	) for _, row in ipairs(result) do		printRow(row) end

-- tails for id = last+1, id_end do		local tr = output:tag('tr') tr:tag('td'):wikitext(id) if unused[id] then tr:tag('td'):attr('colspan', 2):tag('i'):addClass('note-text'):wikitext(i18n.Deprecated) else tr:tag('td'):wikitext('???') end end

return output end, }