Event check if player if following them, stop and wait if too far away.

Hi everyone.


I'm currently trying to script the following behavior to an event.


Basically I want this NPC to go to it's smartpath destination, but when the player is too far away it stops, tells the player to keep up, and waits for them to be close enough. Then it keeps walking.


So something like this:


Track player X and Y position


Track this event's X and Y position


if (eventX - playerX >= 10 || eventY - player Y >= 10)


  cancel event smart path to destination


  Gab window text "Hey, keep up!"


  wait until player is close enough, then re establish smart path


else


  smart path to destination


This is what I've put together so far, which is not working. It's just going through the script over and over, as shown by my console log literally 2 seconds after the game starts. For whatever reason it's not actually stopping and waiting for the player.

Spoiler
Screen Shot 2016-04-06 at 6.56.51 AM.png


Screen Shot 2016-04-06 at 6.57.03 AM.png


Screen Shot 2016-04-06 at 6.58.04 AM.png





Am I going about this the wrong way? I'm pretty new to this so there might be a way easier way to do this.


Thanks in advance!
this would only work in one direction of the respective plane. In one direction the distance would be +10 and in the other it would be -10. You have to turn your numbers into unsigned integer or put in exceptions depending on the direction.
Thanks! That's definitely another problem with this script. My main issue was that it kept running over and over, but I just needed to make better use of multiple pages.


Now I need to try what you suggested to make the distance detection smarter.  🙂

Original thread: https://forums.rpgmakerweb.com/threads/event-check-if-player-if-following-them-stop-and-wait-if-too-far-away.60061/