Setting Up Multiple Inventories (FIXED)

Started by Jaffles, Mon 18/06/2012 00:01:05

Previous topic - Next topic

Jaffles

Hello everyone! In the project I'm currently working on, I'm trying to set up an interface for two different playable characters. I'm aiming for them to have different mouse icons (but the same set of commands eg walk, talk, touch. This is purely cosmetic and less important) and different inventories, but be able to trade items between their distinct inventories. Is this feasible? I was thinking that I could design two different inventory GUIs and have them switch depending on what character is active, but I could not find a parameter that checks who the current player character is. Is this the best way to go about doing this? Thanks in advance!
   

Khris

Since every character has their own inventory, this is perfectly possible.
To find out the current player character, use:
Code: ags
  if (player == cRoger) ...


To switch the inventory GUIs, just turn them on/off when the game switches the player character:

Code: ags
function SwitchPlayer() {
  if (player == cRoger) cSidekick.SetAsPlayer();
  else cRoger.SetAsPlayer();
  gRogerInv.Visible = !gRogerInv.Visible;
  gSidekickInv.Visible = !gSidekickInv.Visible;
}

monkey0506

#2
Unless the GUIs themselves actually look/function different, you could also just change the InvWindow.CharacterToUse property. Or something like that, I'm on my phone, I'll double check that later.

Code: ags
function SwitchPlayer() // based on Khris' post immediately above ;)
{
  if (player == cRoger) cSidekick.SetAsPlayer();
  else cRoger.SetAsPlayer();
  invInventory.CharacterToUse = player; // swap out which inventory is shown on the GUI, based on current player
}


You would do that when changing players, as in Khris' example.

Edit: I know this has been marked as solved (well, "FIXED" :P), but just wanted to follow up on the property, which is indeed CharacterToUse. Updated the code to a full example, based on Khris' code.

Jaffles

Awesome! Got it all working now. Thanks guys!
   

SMF spam blocked by CleanTalk