Intelligent way to *temporary* lose inventory?

Started by Dusty D., Sat 02/04/2005 20:11:12

Previous topic - Next topic

Dusty D.

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
  • to find out, whether the character is carrying an item or not, but do I really have to "reserve" as many globalInts, as the maximum possible no. of items is or is there a possibility to create a data field in AGS scripting?

Ashen

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:
Code: ags

// 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
}
I know what you're thinking ... Don't think that.

Dusty D.

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!

SMF spam blocked by CleanTalk