Is there any way to get the ID of an inventory item?
I want to combine two objects:
cCharacter.Loseinventory(iStuff1);
cCharacter.Loseinventory(iStuff2);
cCharacter.Addinventory(iThing);
However, if I use cCharacter.Addinventory(iThing,0) this creates it at the top of the inventory (not necessarily where original two items were) and cCharacter.Addinventory(iThing) will create it at the bottom (also inconvenient) or some random location.
How can I guarantee that if I add iThing, it will end up where iStuff1/2 were?
You probably need item's index inside inventory. Since same item may be in two or more character's inventory at the same time, this index is not attached to item itself.
The only method I could find is InvWindow.ItemAtIndex array. But it works in reverse (find item by knowing index).
So you have to search it for item:
int GetItemIndexInInventory(InvWindow* inv, InventoryItem* item)
{
for (int i = 0; i < inv.ItemCount; i++)
{
if (inv.ItemAtIndex[i] == item)
return i;
}
return -1;// not found
}
Then
int index1 = GetItemIndexInInventory(charsInvWindow, iStuff1);
int index2 = GetItemIndexInInventory(charsInvWindow, iStuff2);
... calculate your index for AddInventory
Thank you, works a treat :)