Quote from: blexx on Tue 20/08/2024 01:21:04Clicking on this hotspot will make the player walk to it, BUT the cursor will be disabled in this process. This prevents you from canceling the walk.I literally copy and paste the same snippet of code between all of my projects, exactly because of this.
I originally stole it from the Maniac Mansion Mania template.
I'm not sure how helpful it'll be for you, but here it is:
function move_player (int x, int y)
{
// Move the player character to x,y coords, waiting until he/she gets there,
// but allowing to cancel the action by pressing a mouse button.
mouse.ChangeModeGraphic(eModeWait, 5);
cancelled = 0;
player.Walk(x, y, eNoBlock, eWalkableAreas);
player.Walk(x, y, eNoBlock, eWalkableAreas); // Seems to fix a bug where it cancels out early if you're already moving
// Wait for release of mouse button
while (player.Moving && (mouse.IsButtonDown(eMouseLeft) || mouse.IsButtonDown(eMouseRight)))
{
Wait (1);
lblActionText.Text = Game.GetLocationName(mouse.x, mouse.y);
}
// Abort moving on new mouse down
while (player.Moving)
{
if (mouse.IsButtonDown(eMouseLeft) || mouse.IsButtonDown(eMouseRight))
{
player.StopMoving();
player.ActiveInventory = null;
cancelled = 1;
}
else
{
Wait (1);
lblActionText.Text = Game.GetLocationName(mouse.x, mouse.y);
}
}
// A counter measure in case the function doesn't run correctly.
if (player.x != x || player.y != y)
{
//player.Say("I am currently at X:%d Y:%d", player.x, player.y);
//player.Say("And I'm supposed to be at X:%d Y:%d", x, y);
cancelled = 1;
}
mouse.ChangeModeGraphic(eModeWait, 0);
lblActionText.Text = "";
return !cancelled;
}
You just throw that into an If statement, and there you go.
Something like this:
if(move_player(248, 178))
{
player.ChangeRoom(2,7,75);
}
It would be nice if there was a function that already did this though.