Module:Resistances: Difference between revisions

From Exiled Kingdoms Wiki
mNo edit summary
mNo edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local Comp = require( "Module:ValComp" )
resnm = {'Fire', 'Cold', 'Shock', 'Death', 'Toxic', 'Spirit'}
resnm = {'Fire', 'Cold', 'Shock', 'Death', 'Toxic', 'Spirit'}


local function getIndex(tbl, findind)
RawRes = mw.getCurrentFrame().args[1]
  for k, v in pairs(tbl) do
    if v == findind then
      return k
    end
  end
  return nil
end


function p.Disp()
function p.Disp()
     todisp = ''
     todisp = ''
    RawRes = mw.getCurrentFrame().args[1]
     RawRess = mw.text.split(RawRes,',',true)
     RawRess = mw.text.split(RawRes,',',true)
     for key,value in ipairs(RawRess)  
     for key,value in ipairs(RawRess)  
Line 31: Line 26:


function p.Vuln()
function p.Vuln()
    RawRes = mw.getCurrentFrame().args[1]
     vto = mw.getCurrentFrame().args[2]
     vto = mw.getCurrentFrame().args[2]
     vval = mw.getCurrentFrame().args[3]
     vval = mw.getCurrentFrame().args[3]
Line 39: Line 33:
         vval = 0
         vval = 0
     end
     end
     if (gtles == nil) then
     if (gtles == nil or gtles == '') then
         gtles = '>'
         gtles = 'gt'
     end
     end
     isvuln = 0
     isvuln = 0
     vnum = RawRess[getIndex(resnm,vto)]
     vnum = RawRess[Comp.getIndex(resnm,vto)]
     if (gtles == '>') then
     if (Comp.Compare(vnum, gtles, vval) == true) then
        if (tonumber(vnum) > tonumber(vval)) then
         isvuln = 1
            isvuln = 1
        end
    elseif (gtles == '<') then
        if (tonumber(vnum) < tonumber(vval)) then
            isvuln = 1
        end
    elseif (gtles == "'='") then -- '&#61;') then
        if (tonumber(vnum) == tonumber(vval)) then
            isvuln = 1
        end
    elseif (gtles == '&ge;') then
         if (tonumber(vnum) >= tonumber(vval)) then
            isvuln = 1
        end
    elseif (gtles == '&le;') then
        if (tonumber(vnum) <= tonumber(vval)) then
            isvuln = 1
        end
     end
     end
     return isvuln, gtles
     return isvuln
end
end


return p
return p

Latest revision as of 22:10, 7 June 2017

local p = {}

local Comp = require( "Module:ValComp" )

resnm = {'Fire', 'Cold', 'Shock', 'Death', 'Toxic', 'Spirit'}

RawRes = mw.getCurrentFrame().args[1]

function p.Disp()

   todisp = 
   RawRess = mw.text.split(RawRes,',',true)
   for key,value in ipairs(RawRess) 
   do
       if (tonumber(value) > 0) then
           if (todisp == ) then
               todisp = string.format("File:%s.png %s ",

resnm[key], resnm[key], value)

           else
               todisp = string.format("%s File:%s.png %s ", todisp,

resnm[key], resnm[key], value)

           end
       end
   end
   return todisp

end

function p.Vuln()

   vto = mw.getCurrentFrame().args[2]
   vval = mw.getCurrentFrame().args[3]
   gtles = mw.getCurrentFrame().args[4]
   RawRess = mw.text.split(RawRes,',',true)
   if (vval == nil) then
       vval = 0
   end
   if (gtles == nil or gtles == ) then
       gtles = 'gt'
   end
   isvuln = 0
   vnum = RawRess[Comp.getIndex(resnm,vto)]
   if (Comp.Compare(vnum, gtles, vval) == true) then
       isvuln = 1
   end
   return isvuln

end

return p