Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: barefoot on Tue 01/12/2009 19:31:22

Title: check for multiple inventory items
Post by: barefoot on Tue 01/12/2009 19:31:22
Hi

I would like script to check for multiple inv items to allow character to go to another room
from a region.

The player has to have 4 keys in his inventory to allow go to another room when on region.

I have this script enquires if player has an inventory item

if (player.ActiveInventory ==chair) {
  player.Say("Perfect Match");
Title: Re: check for multiple inventory items
Post by: monkey0506 on Tue 01/12/2009 19:48:54
Look up Character.HasInventoryItem and Character.InventoryQuantity instead.
Title: Re: check for multiple inventory items
Post by: barefoot on Tue 01/12/2009 20:00:16
thanks monkey

but each key is a different inv item not 4 of the same item

barefoot
Title: Re: check for multiple inventory items
Post by: Divon on Tue 01/12/2009 20:07:07
Theres probably a cleaner way to do this, but something as simple as this would work:

if(player.HasInventory(iKey1) && player.HasInventory(iKey2) && player.HasInventory(iKey3) && player.HasInventory(iKey4))
{
  Display("You insert all 4 keys into their various locks and you hear the door unlock!");
  player.ChangeRoom(3);
}
Title: Thanks for everyones help.....Re: check for multiple inventory items
Post by: barefoot on Tue 01/12/2009 22:18:00
Thanks Divon

that was a big help...

so far i have this and it works fine......


// room script file

function ochair_Interact()
{
object[2].Visible = true;

cRedpants.AddInventory(chair);
object[2].Visible = false;

}

function bird_Interact()
{
object[1].Visible = true;

cRedpants.AddInventory(obird);
object[1].Visible = false;
}

function wheel_Interact()
{
object[0].Visible = true;

cRedpants.AddInventory(owheel);
object[0].Visible = false;

}

function star_Interact()
{
object[3].Visible = true;

cRedpants.AddInventory(ostar);
object[7].Visible = false;
}

function room_Load()
{
  object[0].Visible = true;
   object[1].Visible = true;
 object[2].Visible = true;
  object[3].Visible = true;
   object[4].Visible = true;
object[5].Visible = true;
object[6].Visible = true;
 object[7].Visible = true;
}

function chair2_UseInv()
{
if (player.ActiveInventory ==chair) {
 player.Say("Perfect Match");
 cRedpants.AddInventory(Key);
 cRedpants.LoseInventory(chair);
 
 }
 else {
   player.Say("Does not match.");
 }
}

function obird2_UseInv()
{
if (player.ActiveInventory ==obird) {
 player.Say("Perfect Match");
 cRedpants.AddInventory(redkey);
   cRedpants.LoseInventory(obird);
   
 }
 else {
   player.Say("Does not match.");
 
}
}

function owheel2_UseInv()
{
if (player.ActiveInventory ==owheel) {
 player.Say("Perfect Match");
 cRedpants.AddInventory(bluekey);
 cRedpants.LoseInventory(owheel);
 }
 else {
   player.Say("Does not match.");
 
}

 player.Say("Perfect Match");
}

function ostar2_UseInv()
{
 
if (player.ActiveInventory ==ostar) {
 player.Say("Perfect Match");
 cRedpants.AddInventory(greenkey);
cRedpants.LoseInventory(ostar);
 }
 else {
   player.Say("Does not match.");
 }

}

function region1_WalksOnto()
{
 
 if(player.HasInventory(Key) && player.HasInventory(redkey) && player.HasInventory(bluekey) && player.HasInventory(greenkey))
{
 Display("You have solved all the math puzzles and have collected all 4 Keys. Now you must return to Yolander the Mermaid for the Amulet!");
 player.ChangeRoom(20, 417, 283);
}
 
 }

function region1_Standing()
{

game.skip_display = 0;

 if(player.HasInventory(Key) && player.HasInventory(redkey) && player.HasInventory(bluekey) && player.HasInventory(greenkey))
{
 Display("You have solved all the math puzzles and have collected all 4 Keys. Now you must return to Yolander the Mermaid for the Amulet!");
 player.ChangeRoom(20, 417, 283);
}
}


Thanks to everyones help...

barefoot












Title: Re: check for multiple inventory items
Post by: Divon on Wed 02/12/2009 01:29:11
happy to be of service :)