Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gabarts on Wed 04/06/2014 23:57:54

Title: Keep Inventory items collected [SOLVED]
Post by: Gabarts on Wed 04/06/2014 23:57:54
Hello,

I've switched the player of my adventure for the first time. I've set a new character and made him the main character, loading him at the start of my Room_7

The problem is that the other guy (main character from Room_1 to Room_6) can collect items and the new character starts with empty inventory in Room_7

How to keep tracking the items collected with the other main character and give them to the new one?

Thanks :)
Title: Re: Keep Inventory items collected
Post by: Khris on Thu 05/06/2014 00:30:17
You can do this:
Code (ags) Select
function SetAsPlayerInv(this Character*) {
  int i;
  while (i < Game.InventoryItemCount) {
    this.InventoryQuantity[i] = player.InventoryQuantity[i];
    player.InventoryQuantity[i] = 0;
    i++;
  }
  // invCustomInv.CharacterToUse = this;
  UpdateInventory();
  this.SetAsPlayer();
}


Now call cOtherGuy.SetAsPlayerInv(); to switch the playable character.
Title: Re: Keep Inventory items collected
Post by: Gabarts on Thu 05/06/2014 09:08:22
Thanks as usual Khris :)

Precisely, this script goes into Global script or in the Room_LOAD section

I will post something this evening, because at the moment I use:

Code (ags) Select
cEgo.Changeroom(7, 490, 108);

This at the end of Room_6 (a cutscene)

in Room_LOAD of Room_7 I use:

Code (ags) Select
cIndy.SetAsPlayer();
Title: Re: Keep Inventory items collected
Post by: Khris on Thu 05/06/2014 10:13:28
This goes into the global script, while this goes into the global header:
Code (ags) Select
import function SetAsPlayerInv(this Character*);

To use it, like I said, call it instead of cWhoever.SetAsPlayer(). What you do before that doesn't matter. The function calls SetAsPlayer, but in addition transfers all items from the current to the next player character. It is not concerned with room changes or where/when it is called.
Title: Re: Keep Inventory items collected
Post by: Gabarts on Thu 05/06/2014 11:17:33
Ok, thanks a lot!
I will include this and let you know if it's working

Title: Re: Keep Inventory items collected
Post by: Gabarts on Thu 05/06/2014 17:32:14
Khris, is giving me this Error into the Global script:

Undefined token 'invCustomInv'

EDIT
----

Luckily I can still use some logic...

I've solved in another way, I just needed 2 items, so I used if/else and told the game to check if the previous character had or not a certain item in his inventory. Then I simply added the items I needed to the new character. A long way but do the trick :)

Title: Re: Keep Inventory items collected [SOLVED]
Post by: Khris on Thu 05/06/2014 18:49:05
invCustomInv is the name of the InventoryWindow in a default game.
I just remembered that it will by default show the inventory of the current player character anyway, so you can simply remove that line.