Anonymous

Module:Constants: Difference between revisions

From Melvor Idle
Correct Slayer function issues
mNo edit summary
(Correct Slayer function issues)
Line 420: Line 420:
slayerLevel = 99 -- this might upgrade to 120 in some update
slayerLevel = 99 -- this might upgrade to 120 in some update
end
end
if not type(tierID) == 'number' then
if type(tierID) ~= 'number' then
return nil
return nil
elseif ConstantData.Slayer.Tiers[tierID + 1] == nil then
elseif ConstantData.Slayer.Tiers[tierID + 1] == nil then
Line 430: Line 430:
result.maxQuantity = 10*(tierID+1) + 4*slayerLevel
result.maxQuantity = 10*(tierID+1) + 4*slayerLevel
return result
return result
end
end
function p.getSlayerTier(name)
local tierID = ConstantData.slayerTier[name]
if tierID == nil then
return nil
else
return p.getSlayerTierByID(tierID)
end
end
end
end
Line 439: Line 448:
for i, tier in ipairs(ConstantData.Slayer.Tiers) do
for i, tier in ipairs(ConstantData.Slayer.Tiers) do
if tier.minLevel <= level then
if tier.minLevel <= level and (tier.maxLevel == nil) or (tier.maxLevel >= level) then
-- is tier.maxLevel == nil really necessary?
return p.getSlayerTierByID(i - 1)
if (tier.maxLevel == nil) or (tier.maxLevel >= level) then
return p.getSlayerTierByID(i - 1)
end
end
end
end
end
function p.getSlayerTierByName(name) -- returns a full table
local tierID = ConstantData.slayerTier[name]
if tierID == nil then
return nil
else
return p.getSlayerTierByID(tierID)
end
end
end
end
Line 461: Line 458:
--
--


function p.getSlayerTierName(tier, fallback)
function p.getSlayerTierName(tierID, fallback)
local tier = p.getSlayerTierByID(tier).display
return type(tierID) == 'number' and ConstantData.slayerTier[tierID] or "ERROR: Invalid Slayer tier[[Category:Pages with script errors]]"
if tier ~= nil then
return tier.display
else
return fallback or "ERROR: Invalid Slayer tier [[Category:Pages with script errors]]"
end
end
end


function p.getSlayerTierNameByLevel(lvl, fallback)
function p.getSlayerTierNameByLevel(lvl, fallback)
local tier = p.getSlayerTierByLevel(lvl)
local tier = p.getSlayerTierByLevel(lvl)
if tier ~= nil then
if type(tier) == 'table' then
return tier.display
return tier.display
else
else
return fallback or "ERROR: Invalid Slayer tier [[Category:Pages with script errors]]"
return fallback or "ERROR: Invalid Slayer tier[[Category:Pages with script errors]]"
end
end
end
function p.getSlayerTierIdByName(name)
return p.getSlayerTierByName(name).id
end
function p.getSlayerTier(name) -- consider removing this function (may break other pages)
return p.getSlayerTierIdByName(name)
end
end