Used inventory item causing a character to appear in different room.

Started by DoctorDan, Mon 02/06/2014 17:30:47

Previous topic - Next topic

DoctorDan

I need to make a character in Room 2 appear when an inventory item is used on an object in Room 1.

I'm struggling as I don't want the character to appear when the inventory item is in the player's possession but rather after he has used it. Also the character is to appear in a different room to the object on which the inventory item is used.


Khris

Go to the Global variables pane, add a bool variable, give it a useful name like "jam_applied_to_cactus" and set its initial value to true.

In room one, do this:
Code: ags
function oCactus_Useinv() {
  if (player.ActiveInventory != iJam) {
    player.Say("Nope.");
  }
  else {
    player.LoseInventory(iJam);
    ...
    jam_applied_to_cactus = true;  // this is the important part
  }
}


In room two, use the "enters room before fadein event":
Code: ags
function room_Load() {
  if (jam_applied_to_cactus && cGuy.Room == -1) {
    cGuy.ChangeRoom(2, 234, 123);
  }
}

DoctorDan

Thanks,

I managed to sovle it (I hope) in the mean time with a global variable (named raisedflag) and the following in the first room:


Code: ags
function oemtpypole_UseInv()
{
  if (cDoctor.ActiveInventory == iFlag) {
    cDoctor.Walk(548, 728);
    oemtpypole.Visible = false;
    oflagpole.Visible = true;
    cDoctor.LoseInventory(iFlag);
    raisedflag = 1;
}
}



And then this in the room with the character

Code: ags
 function room_Load()
{
  if (raisedflag == 1)
{
  cbarricademan.Clickable= true;
  cbarricademan.Transparency=0;
}
else
{
  cbarricademan.Clickable= false;
  cbarricademan.Transparency=100;
}
}


Seems to work, or will it cause me problems later?

johanvepa

Instead of making the character invisible and non-clickable, you'll probably have better results and simpler coding with the solution provided by Khris.

SMF spam blocked by CleanTalk