MV Pathfinding for Followers - through Script Call?

(Sorry if i'm posting in the wrong place, not sure if this suits 'Learning JS' better...)

Is there a way to move a >follower< to a certain coordinate?

It's possible to force move routes on them by using:
Code:
var _moveRoute = {"list":[],"repeat":false,"skippable":false,"wait":true};

_moveRoute.list.push({"code":Game_Character.ROUTE_MOVE_LEFT});
_moveRoute.list.push({"code":Game_Character.ROUTE_MOVE_RIGHT});
_moveRoute.list.push({"code":Game_Character.ROUTE_MOVE_UP});
_moveRoute.list.push({"code":Game_Character.ROUTE_MOVE_DOWN});
_moveRoute.list.push({"code":Game_Character.ROUTE_END});

var ev = $gamePlayer.followers().follower(0);

if(ev) {
 ev.forceMoveRoute(_moveRoute);
}

Since moveRoute.list.push doesn't have any commands for pathfinding (I think), I thought about combining "Game_Character.ROUTE_SCRIPT" with ".moveStraight(this.findDirectionTo(X, Y));"
The problem is: I don't know how. Or if it would even work.

I've also tried: $gamePlayer.followers().follower(0).moveStraight(this.findDirectionTo(X, Y));
But no dice.

I know there are plugins for that, but I'd prefer to use scripting, if possible...
I think you are on the right path, but the code should be:
JavaScript:
$gamePlayer.moveStraight($gamePlayer.findDirectionTo(x, y));

$gamePlayer represents the player character. That's what you want to move, and that's what you need to find a direction for.

In your original code, this.findDirectionTo(X, Y) wouldn't work, because when you execute a script command, you are in the context of the Game_Interpreter, so this is a Game_Interpreter, not the Game_Player. You probably copied the code from Game_Player.prototype.moveByInput(), which is a function belonging to Game_Player, which is why this is a Game_Player in that context.

EDIT:
Now that I think of it, you probably don't know how to fetch the x/y-coordinates either.

If you want to hardcode the coordinates, for example move the player to coordinates (4, 2), then the code would be:
JavaScript:
$gamePlayer.moveStraight($gamePlayer.findDirectionTo(4, 2));

If you are storing the x-coordinate in Variable #0001 and the y-coordinate in Variable #0002, then the code would be like this instead:
JavaScript:
$gamePlayer.moveStraight($gamePlayer.findDirectionTo($gameVariables.value(1), $gameVariables.value(2)));
or alternatively (this is easier to read):
JavaScript:
const x = $gameVariables.value(1);
const y = $gameVariables.value(2);
$gamePlayer.moveStraight($gamePlayer.findDirectionTo(x, y));

Also, keep in mind that this code only moves the player character by 1 tile towards the target. You'll need to run that same code repeatedly until the player character reaches the goal, so don't forget to check if the player character has reached the goal, so you can stop executing the move command, otherwise the game will soft lock.

You'll also need to be careful about movable events and map design. If an event blocks the player's way, the player character will try to move around that event. If it can't, the player will at least try to get as close as possible. And if for some reason the event can't move out of the way, your game will end up in a soft lock. This can happen when you try to move the player to a dead end and some unfortunate event gets caught in between the player and the player's target. The player will try to move closer to the target, but won't ever reach it because the event is in the way, and the event can't move out of the way because the player is blocking the only exit and won't move back.
For moving a follower, I think you're on the right track. In a move route Script, you can use this to refer to the character being moved. I curated a "path to" script call for the MV / MZ Script Call List a while back...based on that, you could try this:
JavaScript:
var x = 5, y = 6;
var pathTo = "var x = " + x + ", y = " + y + "; var d = this.findDirectionTo(x, y);"
           + "if (!d || !this.canPass(this.x, this.y, d)) {"
           + "this.forceMoveRoute({ list: [{ code: 0 }] }); this.setMovementSuccess(true);"
           + "this._moveRouteIndex--; } else this.moveStraight(d);";
var c = $gamePlayer.followers().follower(0);
if (c) c.forceMoveRoute({ list: [
  { code: Game_Character.ROUTE_SCRIPT, parameters: [pathTo] },
  { code: Game_Character.ROUTE_END }
], repeat: true , skippable: false });
Just change the x and y values on the first line.

I tested this and it seemed to work for me, but note that by default followers have Through ON (i.e. ignore passability), so you have to turn that off first unless you're OK with them walking through walls.
@caethyril @Nolonar a thank you is not enough but thank you so much! I'd never have guessed those codes... :LZYdizzy:

Original thread: https://forums.rpgmakerweb.com/threads/pathfinding-for-followers-through-script-call.151204/