Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: bx83 on Tue 18/07/2017 12:42:06

Title: How do I get the inventory of different players?
Post by: bx83 on Tue 18/07/2017 12:42:06
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?
Title: Re: How do I get the inventory of different players?
Post by: Khris on Tue 18/07/2017 13:38:43
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:
  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.)