NPC Running Away Pathfind script

Hello! I was wondering if anyone could find/create a simple script that makes it so NPCs don't get stuck on objects when they are running away from you, or would any ol' Pathfind script do that for me?
A pathfinding script finds the quickest path to a target. In the case of running away, you don't have a target. You potentially have many. How would you choose which tile to run to? Selecting a random tile that is X tiles away from the player could see you trying to reach a target that's unreachable (the pathfinding script would not work).


If you're using a move route, you could just add a random movement in there every 4-5 steps or so. So if they're moving away and there's an obstacle, there's a chance that they'll side-step it after trying to go through it a few times. Of course that won't help if they go into an enclosed area.
thanks for the tip. I was trying to keep the map so that there aren't any enclosed areas that NPCs can get trapped in. I could swear TheoAllen (maybe someone else?) had given me a snippet of code, or a short script that prevented NPCs from hanging up on obstacles, but I can't find it anywhere. It was from nearly a year ago.

One more question: If I set up a map that loops horizontal and vertical, and I use an available pathfinding script, could I set the NPCs to run away from the player to a certain place on the map, and switch event pages to make them run to a new position on the map when they reach X,Y position on the map?
probably, though how are you going to figure out when to switch it? And you could probably do it without multiple event pages, if you're using another event to track where they are and when to go to the next point.
Running away from player is possible but you can't do it constantly, you need to add a "random" move to it to prevent them from "sticking" to the wall.

Try this script for that

http://forums.rpgmakerweb.com/index.php?/topic/44421-rogue-like-movement-chase-mode-surprise-attack/
probably, though how are you going to figure out when to switch it? And you could probably do it without multiple event pages, if you're using another event to track where they are and when to go to the next point.
Well, I went back and looked over my original plan, and found it wasn't possible to use variables to store map position of moving events like you can with the player. So, I have no idea how I am going to figure out when to switch... I am currently using a parallel process for another thing, I could just add event tracking info for NPCs, but I don't see an option to do that.
What you may want to do is a thing like this:
Move route: This event
     Run away from the player
Play in loop
Ignore if impossible

Start of loop
Move route: This event
     A step Upwards
Ignore if impossible


Move route: This event
     A step Rightwards
Ignore if impossible


Move route: This event
     A step Downwards
Ignore if impossible


Move route: This event
     A step Leftwards
Ignore if impossible


Move route: This event
     A step an a random direction
Ignore if impossible
End of loop

This may work without the loop thing


EDIT: I tried it myself, it kinda work, but it's also really messy. This may work properly if we could check for event collision :s

EDIT 2: Actually there is a way: Using RMEx (http://rmex.github.io/) scripts (Rpg Maker Extender), you can check for event's position, and then see if it has moved or not, and then processing the whole thing with conditions in loops.
it wasn't possible to use variables to store map position of moving events like you can with the player
What? Why not?
I think because you can't get the efent's position.
Erm, if you actually could, that would solve the whole thing 🙂
@Shaz, I guess what I should say is I can't find any method to store location information for events via variables. Like when you set player X and Player Y to a variable, I don't see a method to store the same information for a moving event.
Well, as I said earlier, if you install RMEx scripts, you'll b able to use those two commands: http://rmex.github.io/RMEDoc/#event_x and http://rmex.github.io/RMEDoc/#event_y
use these script calls in control variable's script box:

$game_map.events[id].x

$game_map.events[id].y

id = event's id

Original thread: https://forums.rpgmakerweb.com/threads/npc-running-away-pathfind-script.46137/