Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Dusty D. on Sat 02/04/2005 20:11:12

Title: Intelligent way to *temporary* lose inventory?
Post by: Dusty D. on Sat 02/04/2005 20:11:12
I'd like to create a scene, where the player's character loses all items it carries. After leaving the scene, the items, it was carrying before, should go back into the inventory.

I can easily make a loop, that loses everything, like

i=0;
while (i<NoOfItems) {
  LoseInventory(i);
}

Also, I can use character[CHARID].inv
Title: Re: Intelligent way to *temporary* lose inventory?
Post by: Ashen on Sat 02/04/2005 20:23:12
You could create a 'dummy' character (or use an NPC if you'd rather), copy EGO's inventory to them before clearing the inventory, then restore from it when you want. Something like your loop could be used:

// to backup inv
i=0;
while (i<NoOfItems) {
  if (character[EGO].inv[i] == 1) { // if EGO has that item
    AddInventoryToCharacter (DUMMY, i); // Copy it over
    LoseInventory(i); // Then lose it
  }
  i ++; // Move on to next item
}

//to restore
i=0;
while (i<NoOfItems) {
  if (character[DUMMY].inv[i] == 1) { // if DUMMY has that item
    LoseInventoryFromCharacter (DUMMY, i); // Copy it back
    AddInventory(i); // Then lose it
  }
  i ++; // Move on to next item
}
Title: Re: Intelligent way to *temporary* lose inventory?
Post by: Dusty D. on Sun 03/04/2005 01:29:02
Quote from: Ashen on Sat 02/04/2005 20:23:12
You could create a 'dummy' character (or use an NPC if you'd rather), copy EGO's inventory to them before clearing the inventory, then restore from it when you want.

Haha! Sure!! Thank you... as always, there is an easy solution - I like this enginge!