Module:Pets: Difference between revisions

getPetBySkill getPetTableBySkill
m (TODOs)
(getPetBySkill getPetTableBySkill)
Line 1: Line 1:
--This module contains all sorts of functions for getting data on pets
--This module contains all sorts of functions for getting data on pets
--[[ TODOs
    Add getPetBySkill function
        acquiredBy field will work for all skills but Slayer
        May need to do skill look up by ID
            Ty has skill ID of 0, which is Woodcutting, for some reason
        Or maybe just take the first word
    Use the getPetBySkill function to build pet info table
        Similar to {{SkillCapeInfo}}
--]]


local p = {}
local p = {}
Line 17: Line 7:
local Shared = require( "Module:Shared" )
local Shared = require( "Module:Shared" )
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Skills = require('Module:Skills')




Line 35: Line 26:
     local PetName = string.gsub(pet.name, '#', '')
     local PetName = string.gsub(pet.name, '#', '')
     if(name == PetName) then
     if(name == PetName) then
      result = Shared.clone(pet)
      --Make sure every pet has an id, and account for Lua being 1-index
      result.id = i - 1
      break
    end
  end
  return result
end
function p.getPetBySkill(skillName)
  local result = nil
  skillName = string.gsub(skillName, "%%27", "'")
  skillName = string.gsub(skillName, "'", "'")
  skillName = string.gsub(skillName, "'", "'")
  for i, pet in pairs(PetData.Pets) do
    if(Skills.getSkillID(skillName) == pet.skill) then
       result = Shared.clone(pet)
       result = Shared.clone(pet)
       --Make sure every pet has an id, and account for Lua being 1-index
       --Make sure every pet has an id, and account for Lua being 1-index
Line 53: Line 60:
   result = result..'||[['..pet.name..']]||'..pet.description
   result = result..'||[['..pet.name..']]||'..pet.description
   result = result..'\r\n|}'
   result = result..'\r\n|}'
  return result
end
function p.getPetTableBySkill(frame)
  local result = nil
  local skillName = frame.args ~= nil and frame.args[1] or frame
  skillName = string.gsub(skillName, "%%27", "'")
  skillName = string.gsub(skillName, "'", "'")
  skillName = string.gsub(skillName, "'", "'")
  local pet = p.getPetBySkill(skillName)
  result = p.getPetTable(pet.name)
   return result
   return result
end
end
285

edits