How to lose every inventory item?

Started by Gepard, Sun 08/11/2009 14:24:26

Previous topic - Next topic

Gepard

I want my character after performing a certain action to lose every inventory item that he posses. Is it possible to do?

Thanks.
Drink up me 'arties! Yo ho!

Khris

#1
Code: ags
  int i;
  while (i < Game.InventoryItemCount) {
    player.inventory[i] = 0;
    i++;
  }


That should do it.

Edit: Yup, ignore this and look below for the correct way. I hope it served at least as a pointer in the right direction.

Ryan Timothy B

.inventory is not a public member of player/character.

monkey0506

#3
The property is .InventoryQuantity and IIRC inventory items start from 1 not 0, so:

Code: ags
  int i = 1;
  while (i <= Game.InventoryItemCount) {
    player.InventoryQuantity[i] = 0;
    i++;
  }


You may also want to call UpdateInventory() at the end of the loop.

Taking it one step further you could implement an extender method such as this:

Code: ags
function LoseAllInventory(this Character*) {
  int i = 1;
  while (i <= Game.InventoryItemCount) {
    player.InventoryQuantity[i] = 0;
    i++;
  }
  UpdateInventory();
}


And then:

Code: ags
player.LoseAllInventory();


(See Also: import keyword in the manual :P)

Ryan Timothy B

Thanks Monkey. 
Oddly enough I was searching the forums for the answer to this for myself, for my own game, and was directed to this newly created post.  Now that's luck. :P

SMF spam blocked by CleanTalk