SOLVED: Checking if Player Has Inventory items with ||

Started by Slasher, Sun 04/08/2013 08:08:58

Previous topic - Next topic

Slasher

Meltdown  :-[

After Room Fade in and after previous Room checks we get:

Code: AGS

}
 if (cEgo.HasInventory(iPlates || isatellite || ipilot || ipump ||isilicon || idiode || itubes || ipower || iair))
{
 cSpaceman.Say("I think I can help fix the thrusters SAL.");
 game.speech_text_align =eAlignLeft;
 Button23.Animate(5,0, 2, eRepeat);
 cSpace.SayAt(3, 300, 200, "Hope so Captain. We must complete our mission.");
 Button23.NormalGraphic=414;
 game.speech_text_align =eAlignCentre;
}
}


Could you jog my memory regarding if HasInventory bit?

cheers


Andail

You can't use the || like that. You have to repeat the entire cEgo.HasInventory (iInv) every time. Also, mind that with your code, he will say that if he has any of those items, not all of them. Just saying, in case you wanted && instead.

Slasher

#2
Hi Andail,

What I am trying to achieve is to check if player has any of the certain inventory items (gathered from various places) and then run events if he has any of them.

Of course I only want to run these events once when the Room is entered each time.

Hope this helps in my quest.

Afterthought: Would it be better to make a function listing all inventory items needed and include events if met and then run function in After Room Fade In?

Cheers

EDIT: Using a custom function to check seems to work ok (well, so far at least)


monkey0506

#3
I get that you're wanting to do this when the player enters the room, if they have any of the relevant items, but should it do it only once per "new" item? Or just once they get one of the items, every time they enter the room?

Code: ags
  // once per room load, if player has any items
  if (player.HasInventory(iPlates) || player.HasInventory(isatellite) || player.HasInventory(ipilot) ||
      player.HasInventory(ipump) || player.HasInventory(isilicon) || player.HasInventory(idiode) ||
      player.HasInventory(itubes) || player.HasInventory(ipower) || player.HasInventory(iair))
  {
    cSpaceman.Say("I think I can help fix the thrusters SAL.");
    game.speech_text_align = eAlignLeft;
    Button23.Animate(5, 0, 2, eRepeat);
    cSpace.SayAt(3, 300, 200, "Hope so Captain. We must complete our mission.");
    Button23.NormalGraphic = 414;
    game.speech_text_align = eAlignCentre;
  }


If you only want it to go through this interaction if the player has collected a new item (since the last time they were in the room), then you could accomplish that by setting some local variables:

Code: ags
// room script
// top of script
bool hasPlates = false;
bool hasSatellite = false;
bool hasPilot = false;
bool hasPump = false;
bool hasSilicon = false;
bool hasDiode = false;
bool hasTubes = false;
bool hasPower = false;
bool hasAir = false;

  // later...inside room after fade in...
  if ((player.HasInventory(iPlates) && !hasPlates) || (player.HasInventory(isatellite) && !hasSatellite) ||
      (player.HasInventory(ipilot) && !hasPilot) || (player.HasInventory(ipump) && !hasPump) ||
      (player.HasInventory(isilicon) && !hasSilicon) || (player.HasInventory(idiode) && !hasDiode) ||
      (player.HasInventory(itubes) && !hasTubes) || (player.HasInventory(ipower) && !hasPower) ||
      (player.HasInventory(iair) && !hasAir))
  {
    cSpaceman.Say("I think I can help fix the thrusters SAL.");
    game.speech_text_align = eAlignLeft;
    Button23.Animate(5, 0, 2, eRepeat);
    cSpace.SayAt(3, 300, 200, "Hope so Captain. We must complete our mission.");
    Button23.NormalGraphic = 414;
    game.speech_text_align = eAlignCentre;
    hasPlates = player.HasInventory(iPlates);
    hasSatellite = player.HasInventory(isatellite);
    hasPilot = player.HasInventory(ipilot);
    hasPump = player.HasInventory(ipump);
    hasSilicon = player.HasInventory(isilicon);
    hasDiode = player.HasInventory(idiode);
    hasTubes = player.HasInventory(itubes);
    hasPower = player.HasInventory(ipower);
    hasAir = player.HasInventory(iair);
  }


I'm not sure if the latter is necessarily what you wanted, but it would seem like a better design choice to me, and it could serve as a helpful hint to the player that they're on the right track.

Slasher

Cheers monkey_05_06,

I'll give that a try ;)

Thanks

Slasher


SMF spam blocked by CleanTalk