HasEquippedItem doesn't work without a slot specified.
ShmooDude opened this issue ยท 2 comments
Intended functionality is if you don't specify a slot, it simply scans all of them, but this isn't currently working and since the simcraft translator won't know what slot, any scripts using this aren't going to function properly.
This is easily fixed, in conditionals.lua change the code for HasEquippedItem to as follows:
do
--- Test if the player has a particular item equipped.
-- @name HasEquippedItem
-- @paramsig boolean
-- @param item Item to be checked whether it is equipped.
-- @param yesno Optional. If yes, then return true if the item is equipped. If no, then return true if it isn't equipped.
-- Default is yes.
-- Valid values: yes, no.
-- @param ilevel Optional. Checks the item level of the equipped item. If not specified, then any item level is valid.
-- Defaults to not specified.
-- Valid values: ilevel=N, where N is any number.
-- @param slot Optional. Sets the inventory slot to check. If not specified, then all slots are checked.
-- Defaults to not specified.
-- Valid values: slot=SLOTNAME, where SLOTNAME is a valid slot name, e.g., HandSlot.
local function HasEquippedItem(positionalParams, namedParams, state, atTime)
local itemId, yesno = positionalParams[1], positionalParams[2]
local ilevel, slot = namedParams.ilevel, namedParams.slot
local boolean = false
local slotId
if type(itemId) == "number" then
if slot then
slotId = OvaleEquipment:HasEquippedItem(itemId, slot)
else
slotId = OvaleEquipment:HasEquippedItem(itemId)
end
if slotId then
if not ilevel or (ilevel and ilevel == OvaleEquipment:GetEquippedItemLevel(slotId)) then
boolean = true
end
end
elseif OvaleData.itemList[itemId] then
for _, v in pairs(OvaleData.itemList[itemId]) do
if slot then
slotId = OvaleEquipment:HasEquippedItem(v, slot)
else
slotId = OvaleEquipment:HasEquippedItem(v)
end
if slotId then
if not ilevel or (ilevel and ilevel == OvaleEquipment:GetEquippedItemLevel(slotId)) then
boolean = true
break
end
end
end
end
return TestBoolean(boolean, yesno)
end
OvaleCondition:RegisterCondition("hasequippeditem", false, HasEquippedItem)
end
The problem was being caused by the fact that if slot was nil, because the original call was OvaleEquipment:HasEquippedItem(itemId, slot), then when that function ran, N was given a value of 1, which was the nil value, so it never triggered the looping through all slots as for that to happen N had to have a value of 0.
By using the if statement and calling just OvaleEquipment:HasEquippedItem(itemId) if slot is nil it then ensures that N has a value of 0 so it loops through all slots.