Module:Creatures: Difference between revisions

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


function cloneTable (t)        
function mwtextsplit(inputstr, sep, plain)
   local new_t = {}          
  if sep == nil then
   local i, v = next(t, nil)  
    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)      
     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]


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


     local creatureArray = mw.text.split(creatureList,"|}\n{|",true)
     local creatureArray = mwtextsplit(creatureList,")",true)
 
    local baseTable = {["name"]="",["dungeon"]="",["slayer"]="",["difficulty"]="",["goldvalue"]="",["hits"]="",["mindmg"]="",["maxdmg"]="",["wrestling"]="",["armor"]="",["magicresist"]="",["parry"]="",["attackspeed"]="",["magery"]="",["minspelldmg"]="",["maxspelldmg"]="",["poisoning"]="",["poisonresist"]="",["stealth"]="",["ai"]="",["speed"]="",["uniquescaler"]="",}


    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 = {}
     local creatureObjects = {}


     for i, creature in pairs(creatureArray) do
     for index, creature in pairs(creatureArray) do
        local creatureTable = cloneTable(baseTable)
      local creatureTable = cloneTable(baseTable)
        table.insert(creatureObjects, creatureTable)


        for index, stat in pairs(creatureTable) do
      for i, statName in pairs(statTable) do
          local data = string.match(creature,index.."= (%a+)\n")
        local data = string.match(creature,statName..'=(.-),')
          if data then
        if data then
            stat = data
          creatureTable[statName] = data
          end
        else
         end
         end
      end
      local Name = string.gsub(creatureTable.name,"%p","")
      creatureObjects[Name] = creatureTable
     end
     end


     local wikiTable = ""
     local wikiTable = ""
      
 
      if string.lower(creatureName) == "all" then
     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"
      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
       end
    elseif creatureObjects[creatureName] then
      local creature = creatureObjects[creatureName]
      local Name = string.gsub(creature.name,"%p","")
      local imageName = string.gsub(string.lower(Name),"%s","")


    for i, creature in pairs(creatureObjects) do
      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
        if string.lower(creatureName) == "all" then
          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
        elseif creature.name == creatureName then
          wikiTable = '<th colspan="9"> [[File:"..creatureName.lower()..".jpg]]<br />"..creatureName.."<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
     end
 
  return wikiTable
    return wikiTable
end
end


return p
return p

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