[SOLVED] how to completely empty inventory?

Started by Monsieur OUXX, Wed 30/01/2019 14:44:15

Previous topic - Next topic

Monsieur OUXX

It's very simple but I can't find it.
how to completely empty the player's inventory? Google didn't help and F1 didn't help. Or maybe I was using the wrong search terms.

EDIT : found it

Code: ags
 int ii=0;
  while(ii<Game.InventoryItemCount){
    cleech.LoseInventory(inventory[ii]);
    ii++;
  }
 

Crimson Wizard

#1
The above should work, but there are couple of things to optimise:

1) Since 3.4.0 AGS script supports "for" loops.
2) You may have to call LoseInventory multiple times per item if there are more than 1 instance of certain items.
Instead you may directly modify "InventoryQuantity" property. The only nuance is that you should call UpdateInventory afterwards to make sure inventory window is redrawn.

Code: ags

for (int i = 1; i < Game.InventoryItemCount; i++)
    cCharacter.InventoryQuantity[i] = 0;
UpdateInventory();


LATER EDIT: fixed starting index.

Monsieur OUXX

#2
Quote from: Crimson Wizard on Wed 30/01/2019 15:46:59
The above should work, but there are couple of things to optimise:

1) Since 3.4.0 AGS script supports "for" loops.
2) You may have to call LoseInventory multiple times per item if there are more than 1 instance of certain items.
Instead you may directly modify "InventoryQuantity" property. The only nuance is that you should call UpdateInventory afterwards to make sure inventory window is redrawn.

Code: ags

for (int i = 0; i < Game.InventoryItemCount; i++)
    cCharacter.InventoryQuantity[i] = 0;
UpdateInventory();


Noted. Thanks!

EDIT: actually the code that uses .InventoryQuantity crashes if the player doesn't have any of item "i". the engine refuses to set it to 0 because the index is out of bounds. I'll stick to LoseInventory for now.
 

Khris

Code: ags
  for (int i = 1; i <= Game.InventoryItemCount; i++)

SMF spam blocked by CleanTalk