Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Louie_Raphael on Sat 08/08/2020 10:07:43

Title: Remove random item from inventory
Post by: Louie_Raphael on Sat 08/08/2020 10:07:43
Hello! As subject, Is there a way to remove 1, 2 or more RANDOM inv items from my inventory? Basically, I set up my inv as a deck of cards, and I need to remove 2 random cards If my character loose a battle. Thank you so much!
EDIT: I was thinkhing of using a simple random roll with inventory ID array. I have to test it yet, but may be a problem because it can happens often to have more than one of the same card ID in my inv. Any suggestion?
Title: Re: Remove random item from inventory
Post by: Matti on Mon 10/08/2020 01:12:52
As long as "Display multiple items multiple times" is checked, this should do the trick:

Code (ags) Select

    if (InventoryWindow.ItemCount > 0)
    {
      r = Random(InventoryWindow.ItemCount - 1);
      player.LoseInventory(InventoryWindow.ItemAtIndex[r]);
    }
    if (InventoryWindow.ItemCount > 0)
    {
      r = Random(InventoryWindow.ItemCount - 1);
      player.LoseInventory(InventoryWindow.ItemAtIndex[r]);
    }


If you have stacked cards you'd need some modifications.
Title: Re: Remove random item from inventory
Post by: Louie_Raphael on Wed 12/08/2020 10:03:10
Wow, It really seems to work! Thank you so much, and I also have learn something new about inventory properties!
not to worry because I display every items multiple times, to create the Illusion of the card deck.
Thanks a lot!