enhance c_Inventory_OnRemove_ItemInfo to add index info

Justus

Member
Could you please enhance this event or add a new event which will told the listener which index this item has been removed from?
 
I just answered your question in Discord.

We could add a new event but that's not necessary and could even cause problems with things having to listen to multiple events or get called twice for one item being removed.

Only the ItemSlotCollection has a notion of index for items. The other collections have no need for items being in a particular order.

To get the index of a removed item you can use the ItemStack.

Code:
protected virtual void OnRemovedItemFromInventory(ItemInfo removedItemInfo)
{
    if (removedItemInfo.ItemCollection == m_EquipmentItemCollection) {
        var index = m_EquipmentItemCollection.GetItemSlotIndex(removedItemInfo.ItemStack);
        Unequip(removedItemInfo.Item, index);
    }
}

If you forgot what an ItemStack is make sure to read this page:

Each slot in the ItemSlotCollection is an ItemStack. Just like the normal ItemCollection the ItemStacks are pooled. So an ItemStack isn't always in the same slot. But when the remove event is executed the ItemStack hasn't been removed from the slot yet.

I hope that makes sense
 
Top