Hotspot enabled based on location

Started by Massek, Fri 12/03/2021 19:17:30

Previous topic - Next topic

Massek

Hi y'all.  :smiley:

Nowadays i am making my first game, it is a story based 2D classic point and click.
So yes, i am a newbie. And there is something i do not know how to make work.

The first room has different walkable areas.
How to code it so that from a specific location of a character, when y location is smaller than 95, or bigger than 195, the hotspots only action would be for the character to say, for example, "Out of my reach".
If the character will be inside of the location, the hotspots events will work as prescribed.

Thank you!

arj0n

Not sure how the 'different walkable areas' are connected to your question,
and if I understood your question correctly, but why not just use this check
in your event of the clicked hotspot:

Code: ags

if (Hotspot.GetAtRoomXY(player.x, player.y) != hYourHotspotName)  //player is not standing on clicked hotspot
{
  Display("Out of my reach");
}
else //player is standing on clicked hotspot
{
  //your event code here
}

Laura Hunt

I think the question doesn't have to do with whether the character is standing on the hotspot or not, but whether the hotspot is too far away from the character to be interacted with ("too far away" being determined by the character being within a certain y coord range). In that case, it would be something like:

Code: ags
function hHotspot_Interact()
{
  if (cCharacter.y < 95 || cCharacter.y > 195) cCharacter.Say("Out of my reach");

  else // normal hotspot events here
}


I don't see either what this has to do with the room having different walkable areas, though.

Massek

What Laura Hunt wrote was the right code. Thank you very much!  :smiley: :smiley:

Why to make it like this and have more walkable areas:
I have 4 walkable areas, 1 are the stairs up and down.  The room is a ship with upper level, middle level, and lower level.
Goind up or down between each of the levels the character is going throuh a walkbehind =  the floor of the rooms. When he gets to the desired level, the part of the floor should not be a walkbehind.
I made the stairs as an interaction with a hotspot, where upon using the hotspot the walkable area of the stairs is activated, and also the walkbehind. The char can go up/down,  he walks behind the floor to the other level.
After reaching the level the walkbehind is disabled, also with the stairs walkable area, so he can walk on the level without being affected by the walkbehind where the stairs are ort accidentally walk down the stairs when the char needed to go to the other side of the ship.
If he wants to go down, the same proces. Use the stairs, go behind the floor, walk down, disable the walkable area of the stairs.

Khris

Note that instead of hard-coding coordinates, you can simply check the walkable area instead.

Code: ags
  // in hotspot interaction
  // is player on lower deck?
  if (GetWalkableAreaAtRoom(player.x, player.y) == 2) {
    // ...
  }
  else Display("It is out of reach.");


If you were to use this a lot, there's options to reduce duplicate code though. For instance you can keep a room variable pointing to the current deck which is set after the player has interacted with the stairs. The stair logic is already aware of the deck the player has stepped on, so you could simply declare
Code: ags
int deck = 1;

function OutOfReach() {
  // display message
}

at the top of the room script, then change  deck  accordingly.

Now all you have to check is
Code: ags
  if (deck == 2) {
    // stuff happens
  }
  else OutOfReach();

Massek


SMF spam blocked by CleanTalk