Keep Inventory items collected [SOLVED]

Started by Gabarts, Wed 04/06/2014 23:57:54

Previous topic - Next topic

Gabarts

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 :)

Khris

#1
You can do this:
Code: ags
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.

Gabarts

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
cEgo.Changeroom(7, 490, 108);


This at the end of Room_6 (a cutscene)

in Room_LOAD of Room_7 I use:

Code: ags
cIndy.SetAsPlayer();


Khris

This goes into the global script, while this goes into the global header:
Code: ags
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.

Gabarts

Ok, thanks a lot!
I will include this and let you know if it's working


Gabarts

#5
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 :)


Khris

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.

SMF spam blocked by CleanTalk