The problem is caused by the method GetQueuedItemAttachmentSlotIndex in inventoryslot.lua.
According to the comments on the function, it should return nil if it is called on an inventory slot that is not attached, but instead it will return slotIndex in that case.
This becomes a problem when the slotIndex is between 1 and 6.
For example when we have two items A and B with a slotIndex of 1 and 42 respectively, the following happens:
Code:
No attachments:
ItemA: GetQueuedItemAttachmentSlotIndex returns itemA.slotIndex (=1)
ItemB: GetQueuedItemAttachmentSlotIndex returns itemB.slotIndex (=42)
ItemA is attached:
ItemA: GetQueuedItemAttachmentSlotIndex returns i (=1)
ItemB: GetQueuedItemAttachmentSlotIndex returns itemB.slotIndex (=42)
ItemB is attached:
ItemA: GetQueuedItemAttachmentSlotIndex returns itemA.slotIndex (=1)
ItemB: GetQueuedItemAttachmentSlotIndex returns i (=1)
It should actually return this:
Code:
No attachments:
ItemA: GetQueuedItemAttachmentSlotIndex returns nil
ItemB: GetQueuedItemAttachmentSlotIndex returns nil
ItemA is attached:
ItemA: GetQueuedItemAttachmentSlotIndex returns i (=1)
ItemB: GetQueuedItemAttachmentSlotIndex returns nil
ItemB is attached:
ItemA: GetQueuedItemAttachmentSlotIndex returns nil
ItemB: GetQueuedItemAttachmentSlotIndex returns i (=1)
The original code:
Lua Code:
local function GetQueuedItemAttachmentSlotIndex(inventorySlot)
local bag, attachmentIndex = ZO_Inventory_GetBagAndIndex(inventorySlot)
if (bag) then
for i = 1, MAIL_MAX_ATTACHED_ITEMS do
local bagId, slotIndex = GetQueuedItemAttachmentInfo(i)
if bagId == bag and attachmentIndex == slotIndex then
attachmentIndex = i
break
end
end
end
return attachmentIndex
end
What it should be:
Lua Code:
local function GetQueuedItemAttachmentSlotIndex(inventorySlot)
local bag, attachmentIndex = ZO_Inventory_GetBagAndIndex(inventorySlot)
if (bag) then
for i = 1, MAIL_MAX_ATTACHED_ITEMS do
local bagId, slotIndex = GetQueuedItemAttachmentInfo(i)
if bagId == bag and attachmentIndex == slotIndex then
return i
end
end
end
return nil
end
RemoveQueuedAttachment also needs to be adjusted, otherwise it would remove the item in the first attachment slot when nil is returned.