Smart Pathfinding

@Shaz, thanks for the quick reply - it works! Thank you once again.
Can I use this plugin in MZ?
If not, please tell me, will you port it to MZ and when?
This plugin is very necessary in MZ !
:LZSexcite:
This plugin will not work in MZ because it has plugin commands.

Will I port it? Initially I planned to port any plugin that people found useful. Now ... I don't know. The attitude people showed towards VisuStella and Yanfly was a major turnoff for me, and I don't know if I want anything to do with the engines or this community anymore.
@Shaz
The attitude some people had towards VisuStella was disappointing to say the least, but not everyone in the community is like that. I'm still hopeful that the majority is grateful for all the assets that are created.
It is a shame that it doesn't get reflected more in the comments/posts.

I do hope you remain in the community, because I can't imagine someone more helpful and inventive than you. Ultimately it is your own decision, if you want to port something or not. It is a hobby and you should have fun doing it.

I can imagine a port is a lot of tedious work, but I loved your smart pathfinding, because it could make whole villages that much more engaging and real. I bet this plugin breathed live into so much npcs in a bunch of MV games. Even if you don't port it, you can be proud of that and I'm thankful this plugin exists for MV.
I'm sorry if this has been answered before, but is there a way to limit the number of steps the event takes? I want event 1 to move to event 2 but only X steps. How do I do that?
No, it will not do that. You would have to tell it to find the path, then wait a certain number of seconds, then cancel the pathfinding. But you may not always end up the correct distance away from the event that you want to.

Are your events moving? If not, then you don't need to use a plugin at all - you can just do a Move Route to make event 1 move in a fixed direction.
I got here because I was having a problem with the script call for pathfing as it is found in the wonderful script call list assembled by @Archeia and incremented by many others.
I came here, found the solution and the answers to all subsequent problems I had.
Thank you @Shaz for taking the time to code it and share.
I am still amazed by how a piece of code made back in 2015 can still be useful to this day.
is this possible to make compatible with Galv_Diagonal Movement? I want events to move diagonally when using the pathfinding.. thanks
I don't think I'd have time to do this, but you're welcome to post a new thread asking someone to make a patch.

However, have you tried swapping the order of plugins around?
I don't think I'd have time to do this, but you're welcome to post a new thread asking someone to make a patch.

However, have you tried swapping the order of plugins around?
yes i tried swapping position of the two plugins, i even found a previous thread ..
Oh that thread is VE_Diagonal Movement.. ill check
This little plugin has made life so much better!

I've made a couple of little tweaks I thought I would share in case they would come in handy for anyone.

https://github.com/caseylutz/KCL-MV/blob/master/KCL_SmartPath.js

First off the ability to reference events by name. I actually created a separate module for this. It adds a findEvent call to the gameInterpeter to allow you to query events by numerical ID or canonical name. You can either include the FindEventsByName script and SmartPath by event names or you can not include it and just use the numbers. This version of SmartPath will only use the additional script if it's present.

e.g.:

SmartPath Lab_001_Hero Lab_001_ExitSmartPath -1 Field_001_CenterSmartPath 3 7I also added a plugin call for waiting until the smart path is reached.

SmartPath <event_target> WAITI also added an auto-cancelling trigger to clear the auto-path target once it's reached. This is useful if you are controlling the player and want to stop targeting at the end of the path. If you don't clear his target then he will constantly try to re-acquire it every time you move.

SmartPath <event_target> AUTO_CANCELIf your target is actually impassible for whatever reason I've also added a cancellation near (so if you're within 1 tile...)

SmartPath <event_target> AUTO_CANCEL_NEARNow if you have an event where you want the hero to walk to a given location, wait on him, do a cutscene or whatever, and then resume play you can do that like so:

Plugin Command: SmartPath -1 Event_LocationPlugin Command: SmartPath -1 Auto_CancelPlugin Command: SmartPath -1 WaitYou can also have some actions take place before the Wait if, for instance, you'd like to have a conversation but make sure the event waits for the target to reach its destination.
So I am having a bit of trouble with the Auto_Cancel command. I have a target event set to wander, but whenever it wanders away from the target coordinates in the SmartPath command, it immediately turns around to go back to those coordinates.
1643126811657.png
Still one of my favorite scripts that I may or may not be using in MZ.
Script Calls for those who need it.


JavaScript:
// Make Player go to X/Y
$gamePlayer.setTarget(null, X, Y);

//Make Player go to target event
const target = $gameMap.event(ID)
$gamePlayer.setTarget(target);

//Make event go to target event
const event = $gameMap.event(ID);
const target = $gameMap.event(ID)
event.setTarget(target);

//Make event go to player
const event = $gameMap.event(ID);
event.setTarget($gamePlayer);

//Cancel Pathfinding script calls. Use whichever you want.
$gamePlayer.clearTarget();
$gamePlayer.setTargetAutoCancel('on');
$gamePlayer.setTargetAutoCancel('near');

//Cancel Pathfinding script calls. Use whichever you want.
const event = $gameMap.event(ID);
event.clearTarget();
@Shaz,
Would it be possible to somehow make a script call to find a region id?
To avoid adding different events to points on the map?
@Shaz,
Would it be possible to somehow make a script call to find a region id?
To avoid adding different events to points on the map?
You could write a script to randomly pick a tile in a region, then use Shaz's plugin to have an event go to those coordinates. Do you want to go to the closest tile of region ID x or a random tile?
You could write a script to randomly pick a tile in a region, then use Shaz's plugin to have an event go to those coordinates. Do you want to go to the closest tile of region ID x or a random tile?
Plugin command for the event or player to find the nearest specified region id.
Plugin command for the event or player to find the nearest specified region id.
I just made the whole thing a plugin
Code:
 * This adds two extra script calls for Shaz Smart Path
 * this.moveToRegionRandom(regionId) - move the player or
 * event to a random tile of a specified region ID
 * Ex: $gameMap.event(8).moveToRegionRandom(2);
 * Moves event ID 8 to a random tile of region ID 2
 *
 * this.moveToRegionClosest(regionId) - move the player or
 * event to the closest tile of a specified region ID
 * Ex: $gamePlayer.moveToRegionClosest(4);
 * Moves the player to the closest tile of region ID 4
I just made the whole thing a plugin
Code:
 * This adds two extra script calls for Shaz Smart Path
 * this.moveToRegionRandom(regionId) - move the player or
 * event to a random tile of a specified region ID
 * Ex: $gameMap.event(8).moveToRegionRandom(2);
 * Moves event ID 8 to a random tile of region ID 2
 *
 * this.moveToRegionClosest(regionId) - move the player or
 * event to the closest tile of a specified region ID
 * Ex: $gamePlayer.moveToRegionClosest(4);
 * Moves the player to the closest tile of region ID 4
Thank you very much my friend, the plugin works perfectly.
I just wanted to make a suggestion.
It would be possible for there to be a condition that the event or player only moves if they are in another specific region, for example:
The event/player is in no region (0) and has to move to region (4).
The script call could be something like: this.moveToRegionClosest(0, 4)
Thank you very much my friend, the plugin works perfectly.
I just wanted to make a suggestion.
It would be possible for there to be a condition that the event or player only moves if they are in another specific region, for example:
The event/player is in no region (0) and has to move to region (4).
The script call could be something like: this.moveToRegionClosest(0, 4)
That's something you can do by putting a conditional where you're calling it
if(this.regionId()==1)
{this.moveToRegionClosest(regionId);}

if($gameMap.event(8).regionId()==1)
{$gameMap.event(8).moveToRegionClosest(4);}

If event 8 is in region 1, move event 8 to the closest tile of region 4
That's something you can do by putting a conditional where you're calling it
if(this.regionId()==1)
{this.moveToRegionClosest(regionId);}

if($gameMap.event(8).regionId()==1)
{$gameMap.event(8).moveToRegionClosest(4);}

If event 8 is in region 1, move event 8 to the closest tile of region 4
Can you turn this into a single script command, to make it easier in the movement route text box?
Can you turn this into a single script command, to make it easier in the movement route text box?
No, because I consider it a non-issue. I give you my permission to edit the plugin for your use case.

Original thread: https://forums.rpgmakerweb.com/threads/smart-pathfinding.46761/