How do I get the inventory of different players?

Started by bx83, Tue 18/07/2017 12:42:06

Previous topic - Next topic

bx83

Or is there only one inventory?

I'm trying to do something in the game where the player character's inventory is has no items - it gets stolen - and then returned.

Should I use another character's inventory?
How do I display it in gInventory.Visible?
Should I do this, or just make another identical gInventory GUI without the inventory "window" (invCustomInv) in it?

Khris

Each Character has their own inventory. AGS stores inventory by setting an array element to the number of held items, where the index is the item's ID.
Which means when cEgo aquires iKey, AGS internally increments cEgo.InventoryQuantity[iKey.ID] by one.

Which means you can transfer a character's inventory to a dummy character like this:
Code: ags
  for (int i = 1; i <= Game.InventoryItemCount; i++) {
    cDummy.InventoryQuantity[i] = player.InventoryQuantity[i];
    player.InventoryQuantity[i] = 0;
  }
  UpdateInventory(); // we need to call this since we changed the array manually


(Like so often, this question has been asked and answered lots of times. But since the forum is hard to search, here you go.)

SMF spam blocked by CleanTalk