Remove random item from inventory

Started by Louie_Raphael, Sat 08/08/2020 10:07:43

Previous topic - Next topic

Louie_Raphael

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?

Matti

#1
As long as "Display multiple items multiple times" is checked, this should do the trick:

Code: ags

    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.

Louie_Raphael

#2
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!

SMF spam blocked by CleanTalk