Have an enemy sense when you're close by and chase you when you get close to it?

I'm positive there's a script out there for it, but does anyone know of a script that makes an enemy chase you/start a battle when you get close to it?

Also, I saw somewhere that someone used (I believe it was a script) that made the enemy path-find it's way to you when it chased you. This way, it wouldn't get stuck at a wall and would maneuver around objects to chase you. Does anyone know how I could get this to work too?

Thank you!
You don't need a script to have an enemy chase you when you get close to it, but a script call.

In the enemy event, set the autonomous movement type to Custom
Select Move route
Select script and input the following. (all one line)
Code:
move_toward_player if self.x.between?($game_player.x - 3, $game_player.x + 3) &&  self.y.between?($game_player.y - 3, $game_player.y + 3)

You will see that it has -3 twice and 3 twice. That's because I set it so that it started chasing when the player was 3 tiles away. Change that number to whatever suits.
Because a custom route move acts like a parallel process (without being one) this will run at any time that the player approaches and from any direction.

For your second question I know that the script Imenio did that, but it is no longer available (and wasn't free anyway). I haven't personally come across another.
To answer you second question, I've found this pathfinding script. Haven't used it but looks straightforward.


I also found this event chase script. But like Kes mentioned, you don't exactly need a script to make an event chase the player.


You can find event based chase examples searching youtube.
From what I can see without testing, TheoAllen's script combines both of your requests. If so, you will not need the script call I suggested.
Theo's script is recommended, but it only does two of the three parts you need (actually four really)
1. move to player
2. find best route to take
check and check.
3. move when seeing the player
4. move only when in visual sight (walls should block the view)

I remember other threads about 3 and 4 but don't know if there was a solution.
I know there is a script somewhere, fomar has a line of sight script, but I don't think it counts walls.
Is there any way to make it where you don't have to stay within the enemy's line of sight for them to keep chasing you? Like once you get into their line of sight they'll chase you until they catch you?
So I used the Event Chase Player script, and it seems top work great! The only issue is that I would like to have the enemy moving around before you get close to it instead of just sitting still. Is there a way I can make it move around without messing up the coding?
You don't need a script to have an enemy chase you when you get close to it, but a script call.

In the enemy event, set the autonomous movement type to Custom
Select Move route
Select script and input the following. (all one line)
Code:
move_toward_player if self.x.between?($game_player.x - 3, $game_player.x + 3) &&  self.y.between?($game_player.y - 3, $game_player.y + 3)

You will see that it has -3 twice and 3 twice. That's because I set it so that it started chasing when the player was 3 tiles away. Change that number to whatever suits.
Because a custom route move acts like a parallel process (without being one) this will run at any time that the player approaches and from any direction.

For your second question I know that the script Imenio did that, but it is no longer available (and wasn't free anyway). I haven't personally come across another.

Following that example, I came up with this quick method for letting the event chase down the player. Yeah, it's a quite creepy thought. :S

SkyBlue_the_Alicorn said:
So I used the Event Chase Player script, and it seems top work great! The only issue is that I would like to have the enemy moving around before you get close to it instead of just sitting still. Is there a way I can make it move around without messing up the coding?

Well, I could make the event move randomly if the player is too far away from it.

Ruby:
# * Simple Enemy Chasing Player Scriptlet * #
# Use it as a script call inside the Move Route Event Command.
#   chase_player(X Tiles, Y Tiles)

class Game_Enemy
  def chase_player(x_tiles, y_tiles)
    gpx = $game_player.x - @x
    gpy = $game_player.y - @y
    if gpx.abs <= x_tiles or gpy.abs <= y_tiles
      move_toward_player
    else
      move_random
    end
  end
end

Original thread: https://forums.rpgmakerweb.com/threads/have-an-enemy-sense-when-youre-close-by-and-chase-you-when-you-get-close-to-it.155362/