Module:Resistances: Difference between revisions

From Exiled Kingdoms Wiki
mNo edit summary
mNo edit summary
Line 32: Line 32:
function p.Vuln()
function p.Vuln()
     RawRes = mw.getCurrentFrame().args[1]
     RawRes = mw.getCurrentFrame().args[1]
    RawRess = mw.text.split(RawRes,',',true)
     vto = mw.getCurrentFrame().args[2]
     vto = mw.getCurrentFrame().args[2]
     vval = mw.getCurrentFrame().args[3]
     vval = mw.getCurrentFrame().args[3]
    gtles = tostring(mw.getCurrentFrame().args[4])
    RawRess = mw.text.split(RawRes,',',true)
     if (vval == nil) then
     if (vval == nil) then
         vval = 0
         vval = 0
     end
     end
    gtles = mw.getCurrentFrame().args[4]
     if (gtles == nil) then
     if (gtles == nil) then
         gtles = '>'
         gtles = '>'
Line 65: Line 65:
         end
         end
     end
     end
     return isvuln, vval, gtles
     return isvuln, gtles
end
end


return p
return p

Revision as of 02:22, 7 June 2017

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

local function getIndex(tbl, findind)

 for k, v in pairs(tbl) do
   if v == findind then
     return k
   end
 end
 return nil -- "Value not found" or maybe call error() here

end

function p.Disp()

   todisp = 
   RawRes = mw.getCurrentFrame().args[1]
   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()

   RawRes = mw.getCurrentFrame().args[1]
   vto = mw.getCurrentFrame().args[2]
   vval = mw.getCurrentFrame().args[3]
   gtles = tostring(mw.getCurrentFrame().args[4])
   RawRess = mw.text.split(RawRes,',',true)
   if (vval == nil) then
       vval = 0
   end
   if (gtles == nil) then
       gtles = '>'
   end
   isvuln = 0
   vnum = RawRess[getIndex(resnm,vto)]
   if (gtles == '>') then
       if (tonumber(vnum) > tonumber(vval)) then
           isvuln = 1
       end
   elseif (gtles == '<') then
       if (tonumber(vnum) < tonumber(vval)) then
           isvuln = 1
       end
   elseif (gtles == '=') then
       if (tonumber(vnum) == tonumber(vval)) then
           isvuln = 1
       end
   elseif (gtles == '>=') then
       if (tonumber(vnum) >= tonumber(vval)) then
           isvuln = 1
       end
   elseif (gtles == '<=') then
       if (tonumber(vnum) <= tonumber(vval)) then
           isvuln = 1
       end
   end
   return isvuln, gtles

end

return p