Preventing actions when player cannot reach on walkable areas

Started by Bobsy, Sun 11/07/2010 11:30:37

Previous topic - Next topic

Bobsy

Really should have considered this BEFORE otherwise completing this large, complicated room. Never mind.

So there are lots of places on-screen in a particular room that, at the start, cannot reach. The upper floors only become available after solving a certain puzzle, and by default, the walkable areas do not allow access to these hotspots, objects and so forth.

But of course when faced with this cEgo just decides to stop where he is and perform the action as if he was there already, bypassing any walk commands. I'd like this to stop.

Is it possible to add a line or two to the global script that will automatically sense if an object or hotspot or character is out of reach and nip that in the bud? Or do I have to add a great big if condition to EVERY SINGLE interaction in the room? Please say the former, please say the former, please say the former.

barefoot

Hi

To my knowledge :

You can add Conditions for a Room in the Global script, then they would be executed whenever that Condition occurs in the Room... by region, hotspot or object etc...

As I said, to my knowledge..

You may wish to consider looking at your Room script to see if you can do a workaround from there.

If you post the script for the Room we may be able to help more..possibly..

-barefoot-


I May Not Be Perfect but I Have A Big Heart ..

Bobsy

Well, I'm not very keen on posting the entire room script, as it's over a thousand lines long and, well, you know... spoilers... ;D.

But, to clarify the problem, here's the room:



And here's the code pertaining to hBed:

Code: ags

function hBed_Look()
{
  player.Walk(247, 96, eBlock);
  player.FaceLocation(249, 0, eBlock);
  cNarr.Say("The bed was warm and inviting. Blowford's prided itself on providing emergency accommodation for all its members.");
  cNarr.Say("It was especially useful whenever a man needed a place of refuge away from home in times of crisis...");
  cNarr.Say("For example if his wife or staff were rebelling, if London had caught fire or in case the Vikings invaded again.");
}

function hBed_Interact()
{
  player.Walk(247, 96, eBlock);
  player.FaceLocation(249, 0, eBlock);
  if (player.HasInventory(iSheets))
  {
    cNarr.Say("I already had all the misappropriated bedding I would probably need.");
    cNarr.Say("And while I usually had no problem with general vandalism, this was MY room, after all.");
    cNarr.Say("I may yet require it. For napping.");
  }
  else if (player.HasInventory(iCane_wrap))
  {
    cNarr.Say("I already had all the misappropriated bedding I would probably need.");
    cNarr.Say("And while I usually had no problem with general vandalism, this was MY room, after all.");
    cNarr.Say("I may yet require it. For napping.");
  }
  else if (player.HasInventory(iCane_torch))
  {
    cNarr.Say("I already had all the misappropriated bedding I would probably need.");
    cNarr.Say("And while I usually had no problem with general vandalism, this was MY room, after all.");
    cNarr.Say("I may yet require it. For napping.");
  }
  else
  {
    player.Say("Bedsheets, your country needs you!");
    player.Animate(19, 4, eOnce, eBlock);
    player.AddInventory(iSheets);
  }
}

function hBed_Talk()
{
  player.Walk(247, 96, eBlock);
  player.FaceLocation(249, 0, eBlock);
  cNarr.Say("I don't talk to beds. What if they were to talk back?");
}

function hBed_UseInv()
{
  player.Walk(247, 96, eBlock);
  player.FaceLocation(249, 0, eBlock);
  cNarr.Say("As a boy, I had indeed enjoyed many hours of Hide The Thingy. But now was not the time!");
}


While the doors on either side of the player are closed, their walkable areas are turned off. So hBed should not be accessible until the player opened the doors and linked the walkable areas to create a path*. Currently, if the player tries to interact with hBed, all the interactions take place, even though they cannot walk to it. So the player is tearing off bedsheets from two floors down. Not good.

Now, to the solution: What I'm after is, if the player tries to interact with something out of reach like hBed, I want a generic reaction to the tune of the player whining "I can't reach it!" or shrugging in that irritating way from Beneath a Steel Sky**. I'm sure it's possible to put a great big whopping if condition around each of the functions there, but... well, I've got a LOT of objects and hotspots in the room. And this is only the first room of many. I'm not trying to be lazy, but I'd rather find a single, elegant solution to put into the global script that will automatically fire for ANY object, hotspot or character that the player cannot reach via currently-active walkable areas. To me, having an if condition for EVERY interaction of EVERY object is a rather ungainly way of doing things. Am I dreaming? Or is there a simple way to solve this?

*It's not that simple, but it's not worth going into any more detail. Also, haha, spoilers.
** great game, but man that shrug of his drove me crazy.

Sslaxx

Unrelated, but I'd do some condensing:

Code: ags
  if (player.HasInventory(iSheets) || player.HasInventory(iCane_wrap) || player.HasInventory(iCane_torch))
  {
    cNarr.Say("I already had all the misappropriated bedding I would probably need.");
    cNarr.Say("And while I usually had no problem with general vandalism, this was MY room, after all.");
    cNarr.Say("I may yet require it. For napping.");
  }
  else
  {
    player.Say("Bedsheets, your country needs you!");
    player.Animate(19, 4, eOnce, eBlock);
    player.AddInventory(iSheets);
  }
Stuart "Sslaxx" Moore.

Khris

One way is to keep track of the walkable area the player is on and disable hotspots / make objects unclickable he can't reach. (Or use regions.)

The other way is to check the player's coordinates, e.g. by using my module.

SMF spam blocked by CleanTalk