How to make a char to walk to a specific location after random walk?

I dont know how to properly summarize the title to present such question, but i'll try to further explain with an example:

The map is a small room. There's a NPC that i made to walk randomly around.
Then a event will happen at a door where the player will be located.

When this event happen, I need that specific NPC to stop walking around randomly and, somehow, by any accessible path, he need to walk nearby the door to take a look and stop at a specific area.

Is there a way to do that? (the area is small, so i can't remove him and make him appear nearby with new movements)
In other words, is there a way to tell a npc that is walking around randomly to walk and stop to a certain location?
You need a plugin simillar to this - https://forums.rpgmakerweb.com/index.php?threads/smart-pathfinding.46761/
That one is for MV so i am not sure if it will work for MZ, but you can search for alternatives, there should be a few.

But i still haven't figured out how to check if the target is arrived at the location. It will continue to walk towards the destination until it will receive command to stop the script, but since the path can take various amount of time, i don't know how to do that.

Hovewer, if your location is small, it would be enough just to activate script, wait several seconds, then deactivate and proceed with whatever you want to happen next. That few seconds will be enough for him to reach the target.
You could try giving the character a repeating move route with 1 Script move command:

const x = 5, y = 6; 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--; $gameSwitches.setValue(7, true); } else this.moveStraight(d);
I.e.
  • Find a path to tile X = 5, Y = 6. Uses the built-in pathfinding routine.
  • If no path is found, or the next step is impassable, end this move route and turn on switch 7.
  • Otherwise, move 1 step along the path (and continue repeating this route).
Then to wait for the route to end, I believe you could structure your event something like this:
  • Turn off switch 7 (because that's the one that gets turned on when the route ends).
  • Set Move Route {as above}.
  • Loop:
    • If Switch 7 is ON (i.e. route has finished):
      • Break Loop.
    • Wait 15 frames.
Replace the numbers 5, 6, 7 with values appropriate for your situation~
another simple solution is just fade out on your scene and teleport the event or even hide that one temporarily and show a new event to represent that one where you want that one to be.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-char-to-walk-to-a-specific-location-after-random-walk.180141/