[SOLVED] Run htspt inter. only when standing on htspot & using a spcific cursr

Started by Egmundo Huevoz, Mon 15/01/2018 12:17:19

Previous topic - Next topic

Egmundo Huevoz

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

Matti

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.

Egmundo Huevoz

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.

Matti

Create a global variable (int hotspotclick = 0) and do something like this:

Code: ags

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

// stands on hotspot:
if (hotspotclick == hotspotname.ID)
{
  hotspotclick = 0;
  player.Changeroom();
}

Egmundo Huevoz

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

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!");
}

Khris

Or do this (just nitpicking though):
Code: ags
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.

SMF spam blocked by CleanTalk