Module:NPC

--[=[ LUA script to get NPC Detail

Parameters: 1: NPC = NPC name 2: Include Name/Text Link (Optional) N = NPC Name D = Descriptive/Display Name (Text Only) T = Text Only NPC Name A = Alternate Text (Parameter 3) 3: Alternate Text (Optional) 4: Size in pixels (Optional) default 25 5: Event Version (Optional)

-- The list of available NPCs is kept in the module data -- Unknown is returned if NPC is not in data. --]=]

local p = {}

local npcData = mw.loadData( 'Module:NPC/data' )

function p.getNPC(frame)

local tArgs

if frame == mw.getCurrentFrame then fParent = frame:getParent tArgs = fParent.args

if (fParent.args[1]) then tArgs = fParent.args else tArgs = frame.args end else tArgs = frame end

local npcName = tArgs[1] or "" local inclName = tArgs[2] or "" local altText = tArgs[3] or "" local size    = tArgs[4] or "" local version = string.lower(tArgs[5] or "")

local keyName = string.lower(npcName)

if inclName ~= "" then if not inclName:match("^[NATD]$") then inclName = "N" end end

if size == "" then size = "25" end

local outText = "" local tFile = "work_in_progress" local tSize = ".png|x" .. size .. "px|" local tDisp = npcName local tLink = "Work In Progress"

if npcData[keyName] then local npcItem = npcData[keyName]

if npcItem["A"] and npcItem["A"][1] and npcData[npcItem["A"][1]] then if not version or version == "" then version = npcItem["A"][2] or "" end npcItem = npcData[npcItem["A"][1]] end if npcItem["N"] then tLink = npcItem["N"] tDisp = tLink end

if npcItem["D"] then tDisp = npcItem["D"] end

if npcItem["I"] then tFile = npcItem["I"] end

if version ~= "" and npcItem["E"] and npcItem["E"][version] then local text = "" text = npcItem["E"][version][1] if text and text ~= "" then tDisp = string.gsub(text, "%%(%d)",                       function(v)                            return npcItem["V"..v] or ""                        end                    ) end

text = npcItem["E"][version][2] if text and text ~= "" then tFile = string.gsub(text, "%%(%d)",                       function(v)                            return npcItem["V"..v] or ""                        end                    ) end

text = npcItem["E"][version][3] if text and text ~= "" then tLink = string.gsub(text, "%%(%d)",                       function(v)                            return npcItem["V"..v] or ""                        end                    ) end end end

local nameLink = "" local bracket = ""

if inclName == "N" then nameLink = "" .. tLink .. " ("       bracket = ")" elseif inclName == "A" then nameLink = "" .. altText       end        nameLink = nameLink .. " ("        bracket = ")" elseif inclName == "T" then nameLink = tLink .. " ("       bracket = ")" elseif inclName == "D" then nameLink = tDisp .. " ("       bracket = ")" end

return nameLink .. ""       .. tFile .. tSize .. tDisp        .. "" .. bracket end

return p

-- --