Anonymous

Module:Items: Difference between revisions

From Melvor Idle
Add function to grab item value (sellsfor) based on item name or item object
(added code to quickly find all lifesteal weapons. Not used anywhere, but I'm saving it in case it's useful later)
(Add function to grab item value (sellsfor) based on item name or item object)
(2 intermediate revisions by 2 users not shown)
Line 112: Line 112:
if result == nil and ZeroIfNil then result = 0 end
if result == nil and ZeroIfNil then result = 0 end
return result
return result
end
function p.getItemValue(item)
function isGP(itemName)
return itemName == 'GP' or itemName == 'Gold Pieces'
end
if type(item) == 'string' then
if isGP(item:upper()) then
return 1
end
item = p.getItem(item)
end
if item then
return item.sellsFor
end
return nil
end
end


Line 167: Line 187:


function p.hasCombatStats(item)
function p.hasCombatStats(item)
-- Checks if the combat stat is a valid, non-zero combat stat
-- Ensure that, only in the case where the item is a Familar AND
-- the checked stat is summoningMaxhit, the result is ignored.
function isNonZeroStat(statName, statVal)
if statName == 'summoningMaxhit' and (p._canItemUseSlot(item, 'Summon1') or p._canItemUseSlot(item, 'Summon2')) then
return false
end
return statVal ~= 0
end
if item.equipmentStats ~= nil then
if item.equipmentStats ~= nil then
-- Ensure at least one stat has a non-zero value
-- Ensure at least one stat has a non-zero value
for statName, statVal in pairs(item.equipmentStats) do
for statName, statVal in pairs(item.equipmentStats) do
if statVal ~= 0 then
if isNonZeroStat(statName, statVal) then
return true
return true
end
end
end
end
end
end
return false
return false
end
end
914

edits