Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Egmundo Huevoz on Mon 15/01/2018 12:17:19

Title: [SOLVED] Run htspt inter. only when standing on htspot & using a spcific cursr
Post by: Egmundo Huevoz on Mon 15/01/2018 12:17:19
Hello all. I'm making a "map" room, in which the locations are represented by hotspots. I want it to work in a way so that when the character is standing on the location/hotspot AND he clicks it with the interact cursor, then it changes the room. I know how to do either of those separately, but I can't figure out how to do both of them at the same time.
I need this to work like this because the character can just skip the location by walking over it, so just entering the room by standing on the hotspot is not an option. Also, only interacting with it it's not an option either, because when I interact with a hotspot, the character walks toward it while blocking the other scripts (which I need for monster spawning, yadda yadda).

Any other alternatives to my theoretical method are also welcome!

Thanks in advance! :-D
Title: Re: Run hotspot interaction only when standing on htspot AND using a specific cursor
Post by: Matti on Mon 15/01/2018 13:29:54
One possibility would be to put the monster spawning code(or anything else you want to happen) in the repeatedly_execute_always.

Another way would be to make the walking non-blocking and setting a variable that keeps track of what hotspot has been clicked on. Then, you not only check whether the player is standing on a certain hotspot, but also if the variable is equal to the hotspot's ID.
Title: Re: Run hotspot interaction only when standing on htspot AND using a specific cursor
Post by: Egmundo Huevoz on Mon 15/01/2018 13:50:22
Yeah, I already have it on the repeatedly_execute_always. But still, if the player clicked the location by accident, he would still have to walk all the way there (it takes like 20 seconds) and get ambushed by monsters without having a possibility to move.

Is there a way to make the "walk to hotspot" thingy non-blocking? I'm gonna try the variable thing right now.
Title: Re: Run hotspot interaction only when standing on htspot AND using a specific cursor
Post by: Matti on Mon 15/01/2018 14:14:50
Create a global variable (int hotspotclick = 0) and do something like this:

Code (ags) Select

// any click on hotspot:
hotspotclick = hotspotname.ID
player.Walk(mouse.x, mouse.y);

// stands on hotspot:
if (hotspotclick == hotspotname.ID)
{
  hotspotclick = 0;
  player.Changeroom();
}
Title: Re: Run hotspot interaction only when standing on htspot AND using a specific cursor
Post by: Egmundo Huevoz on Mon 15/01/2018 15:00:56
I arrived to a similar code myself, but the problem with both your and my code is that I can click the hotspot, then interrupt my walking, do something else, and when I walk through the hotspot it without having JUST clicked it, it still changes the room.

After a lot of trial and error, I managed to do it!

Code (ags) Select

int standing;

function repeatedly_execute_always()
{
if (!player.Moving)
    standing=0;
}

function on_mouse_click(MouseButton button){
if ((button == eMouseLeft)&&(mouse.Mode==eModeInteract)){
  player.Walk(GetViewportX()+mouse.x, GetViewportY()+mouse.y, eNoBlock);
  Hotspot *h=Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  standing=h.ID;}
}

//then, on the particular hotspot/location walkon function:

function hAnyGivenHotspot_WalkOn()
{
if (standing==hAnyGivenHotspot.ID)
  Display("It worked!");
}
Title: Re: [SOLVED] Run htspt inter. only when standing on htspot & using a spcific cursr
Post by: Khris on Mon 15/01/2018 23:54:05
Or do this (just nitpicking though):
Hotspot* clickedHotspot;

  clickedHotspot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);

  if (clickedHotspot == hAnyGivenHotspot)

i.e. use a variable name actually describing what it stores and a Hotspot pointer.