Module:Creatures: Difference between revisions

From UO Outlands Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(21 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


function cloneTable (t)           -- t is a table
function mwtextsplit(inputstr, sep, plain)
   local new_t = {}           -- create a new table
  if sep == nil then
   local i, v = next(t, nil) -- i is an index of t, v = t[i]
    sep = "%s"
  end
  local t = {}
  for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
    table.insert(t, str)
  end
  return t
end
 
function cloneTable (t)        
   local new_t = {}      
   local i, v = next(t, nil)
   while i do
   while i do
     new_t[i] = v
     new_t[i] = v
     i, v = next(t, i)       -- get next index
     i, v = next(t, i)      
   end
   end
   return new_t
   return new_t
end
end


function p.listCreatures( frame )
function p.listCreatures(frame)
     -- Parameters passed when the function is invoked
     -- Parameters passed when the function is invoked
     local creatureList = frame.args[1] -- {|name=...
     local creatureList = frame.args[1]
    local creatureName = frame.args[2] -- Sun Wyrm


     local creatureArray = mw.text.split(creatureList,"|}\n{|",true)
    -- Parameters from the template passed to the function
     local baseTable = {["name"]="",["dungeon"]="",["name"]="",["slayer"]="",["difficulty"]="",["goldvalue"]="",["hits"]="",["mindmg"]="",["maxdmg"]="",["wrestling"]="",["armor"]="",["magicresist"]="",["poisontype"]="",["poisoning"]="",["poisonresist"]="",["ai"]="",["speed"]="",["uniquescaler"]="",}
     local creatureName = frame.args[2]
     --local imageOverride = frame.args[3] -- sunwyrm.png


     for i, creature in pairs(creatureArray) do
     local creatureArray = mwtextsplit(creatureList,")",true)
        local creatureTable = cloneTable(baseTable)


        for index, stat in pairs(creatureTable) do
    local baseTable = {["name"]="",["dungeon"]="",["slayer"]="",["difficulty"]="",["goldvalue"]="",["hits"]="",["mindmg"]="",["maxdmg"]="",["wrestling"]="",["armor"]="",["magicresist"]="",["parry"]="",["attackspeed"]="",["magery"]="",["minspelldmg"]="",["maxspelldmg"]="",["poisontype"]="",["poisoning"]="",["poisonresist"]="",["stealth"]="",["ai"]="",["speed"]="",["uniquescaler"]="",}
          local data = string.match(creatureTable[i],index.."= (%a+)\n")
    local statTable = {"name","dungeon","slayer","difficulty","goldvalue","hits","mindmg","maxdmg","wrestling","armor","magicresist","parry","attackspeed","magery","minspelldmg","maxspelldmg","poisontype","poisoning","poisonresist","stealth","ai","speed","uniquescaler",}
          if data then
 
            stat = data
    local creatureObjects = {}
          end
 
    for index, creature in pairs(creatureArray) do
      local creatureTable = cloneTable(baseTable)
 
      for i, statName in pairs(statTable) do
        local data = string.match(creature,statName..'=(.-),')
        if data then
          creatureTable[statName] = data
        else
         end
         end
      end
      local Name = string.gsub(creatureTable.name,"%p","")
      creatureObjects[Name] = creatureTable
    end
    local wikiTable = ""
    if creatureName and string.lower(creatureName) == "all" then
      wikiTable = "<th>Name<th>Dungeon<th>Slayer<th>Difficulty<th>GoldValue<th>Hits<th>MinDmg<th>MaxDmg<th>Wrestling<th>Armor<th>Resist<th>Parry<th>AtkSpd<th>Magery<th>MinSpellDmg<th>MaxSpellDmg<th>Poison<th>Poisoning<th>PoisonResist<th>Stealth<th>AI<th>Speed<th>UniqueScalar"
      for i, creature in pairs(creatureObjects) do
        wikiTable = wikiTable.."<tr><td>"..creature.name.."<td>"..creature.dungeon.."<td>"..creature.slayer.."<td>"..creature.difficulty.."<td>"..creature.goldvalue.."<td>"..creature.hits.."<td>"..creature.mindmg.."<td>"..creature.maxdmg.."<td>"..creature.wrestling.."<td>"..creature.armor.."<td>"..creature.magicresist.."<td>"..creature.parry.."<td>"..creature.attackspeed.."<td>"..creature.magery.."<td>"..creature.minspelldmg.."<td>"..creature.maxspelldmg.."<td>"..creature.poisontype.."<td>"..creature.poisoning.."<td>"..creature.poisonresist.."<td>"..creature.stealth.."<td>"..creature.ai.."<td>"..creature.speed.."<td>"..creature.uniquescaler
      end
    elseif creatureObjects[creatureName] then
      local creature = creatureObjects[creatureName]
      local Name = string.gsub(creature.name,"%p","")
      local imageName = string.gsub(string.lower(Name),"%s","")
      wikiTable = '<th colspan="9"> [[File:'..imageName..".jpg]]<br />"..creature.name.."<tr><th>Slayer<th>Difficulty<th>GoldValue<th>Hits<th>MinDmg<th>MaxDmg<th>Wrestling<th>Armor<th>Resist<tr><td>"..creature.slayer.."<td>"..creature.difficulty.."<td>"..creature.goldvalue.."<td>"..creature.hits.."<td>"..creature.mindmg.."<td>"..creature.maxdmg.."<td>"..creature.wrestling.."<td>"..creature.armor.."<td>"..creature.magicresist.."<tr><th>Parry<th>AtkSpd<th>Magery<th>MinSpellDmg<th>MaxSpellDmg<th>Poison<th>PoisonResist<th>Stealth<th>AI<tr><td>"..creature.parry.."<td>"..creature.attackspeed.."<td>"..creature.magery.."<td>"..creature.minspelldmg.."<td>"..creature.maxspelldmg,"<td>"..creature.poisontype.."<td>"..creature.poisonresist.."<td>"..creature.stealth.."<td>"..creature.ai
     end
     end
  return wikiTable
end
end


return p
return p

Latest revision as of 23:24, 9 September 2024

Documentation for this module may be created at Module:Creatures/doc

local p = {}

function mwtextsplit(inputstr, sep, plain)
  if sep == nil then
    sep = "%s"
  end
  local t = {}
  for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
    table.insert(t, str)
  end
  return t
end

function cloneTable (t)          
  local new_t = {}       
  local i, v = next(t, nil)
  while i do
    new_t[i] = v
    i, v = next(t, i)       
  end
  return new_t
end

function p.listCreatures(frame)
    -- Parameters passed when the function is invoked
    local creatureList = frame.args[1]

    -- Parameters from the template passed to the function
    local creatureName = frame.args[2]
    --local imageOverride = frame.args[3] -- sunwyrm.png

    local creatureArray = mwtextsplit(creatureList,")",true)

    local baseTable = {["name"]="",["dungeon"]="",["slayer"]="",["difficulty"]="",["goldvalue"]="",["hits"]="",["mindmg"]="",["maxdmg"]="",["wrestling"]="",["armor"]="",["magicresist"]="",["parry"]="",["attackspeed"]="",["magery"]="",["minspelldmg"]="",["maxspelldmg"]="",["poisontype"]="",["poisoning"]="",["poisonresist"]="",["stealth"]="",["ai"]="",["speed"]="",["uniquescaler"]="",}
    local statTable = {"name","dungeon","slayer","difficulty","goldvalue","hits","mindmg","maxdmg","wrestling","armor","magicresist","parry","attackspeed","magery","minspelldmg","maxspelldmg","poisontype","poisoning","poisonresist","stealth","ai","speed","uniquescaler",}
  
    local creatureObjects = {}

    for index, creature in pairs(creatureArray) do
      local creatureTable = cloneTable(baseTable)

      for i, statName in pairs(statTable) do
        local data = string.match(creature,statName..'=(.-),')
        if data then
          creatureTable[statName] = data
        else 
        end
      end

      local Name = string.gsub(creatureTable.name,"%p","")

      creatureObjects[Name] = creatureTable
    end

    local wikiTable = ""

    if creatureName and string.lower(creatureName) == "all" then
      wikiTable = "<th>Name<th>Dungeon<th>Slayer<th>Difficulty<th>GoldValue<th>Hits<th>MinDmg<th>MaxDmg<th>Wrestling<th>Armor<th>Resist<th>Parry<th>AtkSpd<th>Magery<th>MinSpellDmg<th>MaxSpellDmg<th>Poison<th>Poisoning<th>PoisonResist<th>Stealth<th>AI<th>Speed<th>UniqueScalar"

      for i, creature in pairs(creatureObjects) do
        wikiTable = wikiTable.."<tr><td>"..creature.name.."<td>"..creature.dungeon.."<td>"..creature.slayer.."<td>"..creature.difficulty.."<td>"..creature.goldvalue.."<td>"..creature.hits.."<td>"..creature.mindmg.."<td>"..creature.maxdmg.."<td>"..creature.wrestling.."<td>"..creature.armor.."<td>"..creature.magicresist.."<td>"..creature.parry.."<td>"..creature.attackspeed.."<td>"..creature.magery.."<td>"..creature.minspelldmg.."<td>"..creature.maxspelldmg.."<td>"..creature.poisontype.."<td>"..creature.poisoning.."<td>"..creature.poisonresist.."<td>"..creature.stealth.."<td>"..creature.ai.."<td>"..creature.speed.."<td>"..creature.uniquescaler
      end
    elseif creatureObjects[creatureName] then
      local creature = creatureObjects[creatureName]
      local Name = string.gsub(creature.name,"%p","")
      local imageName = string.gsub(string.lower(Name),"%s","")

      wikiTable = '<th colspan="9"> [[File:'..imageName..".jpg]]<br />"..creature.name.."<tr><th>Slayer<th>Difficulty<th>GoldValue<th>Hits<th>MinDmg<th>MaxDmg<th>Wrestling<th>Armor<th>Resist<tr><td>"..creature.slayer.."<td>"..creature.difficulty.."<td>"..creature.goldvalue.."<td>"..creature.hits.."<td>"..creature.mindmg.."<td>"..creature.maxdmg.."<td>"..creature.wrestling.."<td>"..creature.armor.."<td>"..creature.magicresist.."<tr><th>Parry<th>AtkSpd<th>Magery<th>MinSpellDmg<th>MaxSpellDmg<th>Poison<th>PoisonResist<th>Stealth<th>AI<tr><td>"..creature.parry.."<td>"..creature.attackspeed.."<td>"..creature.magery.."<td>"..creature.minspelldmg.."<td>"..creature.maxspelldmg,"<td>"..creature.poisontype.."<td>"..creature.poisonresist.."<td>"..creature.stealth.."<td>"..creature.ai
    end
   return wikiTable
end

return p