Setting Movement Route to Specific Location

Hi guys! Is there a script or sth. allowing me to set the movement route to a specific location?
by default no, you'll need a pathfinding plugin for that.
Yes, there is.

If your event has a custom route:
JavaScript:
this.moveStraight(this.findDirectionTo(23, 2))
will make it move a single step towards coordinate (23, 2) on the map. The event will keep repeating this until it reaches its destination (and then it will stop moving). The event will, of course, try and avoid any obstacles in the way.

If you're using a Set Movement Route command, things get a bit more complex.
Since the above script only performs a single step, you need to put the Set Movement Route command in a Loop to ensure the event will reach the location. After all, the event will try to avoid obstacles, and if there are lots of moving obstacles, predicting how many steps the event will need becomes impossible (like when 2 people are trying to move past one another, but they both step left, then step right, then step left, etc. trying to get out of each other's way).

But using a Loop means you'll need to exit that Loop at some point (or the event will never stop). You can do that with a Conditional Branch with the following script:
JavaScript:
$gameMap.event(20).x == 23 && $gameMap.event(20).y == 2
which will check if Event #20 has arrived at its destination, then put a Break Loop inside the branch. If you need to check for the player instead of an event:
JavaScript:
$gamePlayer.x == 23 && $gamePlayer.y == 2
And if you want to select the "current event" instead, you can use:
JavaScript:
$gameMap.event(this.eventId()).x == 23 && $gameMap.event(this.eventId()).y == 2
which is useful for when you want to copy-paste the same event and are to lazy to change the ID with it.

Also, be careful about looping maps. The event will take the shortest route to its destination, which might be a different route from what you imagine when looking at your map (e.g. you placed the event at the rightmost edge of the map, and set its target to the leftmost of the map. You expect the event to move to the left, but since the map is looping, it will move to the right instead).
Yes, there is.

If your event has a custom route:
JavaScript:
this.moveStraight(this.findDirectionTo(23, 2))
will make it move a single step towards coordinate (23, 2) on the map. The event will keep repeating this until it reaches its destination (and then it will stop moving). The event will, of course, try and avoid any obstacles in the way.

If you're using a Set Movement Route command, things get a bit more complex.
Since the above script only performs a single step, you need to put the Set Movement Route command in a Loop to ensure the event will reach the location. After all, the event will try to avoid obstacles, and if there are lots of moving obstacles, predicting how many steps the event will need becomes impossible (like when 2 people are trying to move past one another, but they both step left, then step right, then step left, etc. trying to get out of each other's way).

But using a Loop means you'll need to exit that Loop at some point (or the event will never stop). You can do that with a Conditional Branch with the following script:
JavaScript:
$gameMap.event(20).x == 23 && $gameMap.event(20).y == 2
which will check if Event #20 has arrived at its destination, then put a Break Loop inside the branch. If you need to check for the player instead of an event:
JavaScript:
$gamePlayer.x == 23 && $gamePlayer.y == 2
And if you want to select the "current event" instead, you can use:
JavaScript:
$gameMap.event(this.eventId()).x == 23 && $gameMap.event(this.eventId()).y == 2
which is useful for when you want to copy-paste the same event and are to lazy to change the ID with it.

Also, be careful about looping maps. The event will take the shortest route to its destination, which might be a different route from what you imagine when looking at your map (e.g. you placed the event at the rightmost edge of the map, and set its target to the leftmost of the map. You expect the event to move to the left, but since the map is looping, it will move to the right instead).
Thank you so much 🙂)))

Original thread: https://forums.rpgmakerweb.com/threads/setting-movement-route-to-specific-location.145234/