It's also possible to do with just standard events if you want.
Give the enemies 2 pages. One is just them normally moving randomly or whatever and the second page is the exact same thing, but it chases you instead and controlled by a switch.
Make a parallel process event that compares the player's X/Y location with the enemy's by subtracting the one from the other.
(subtract the enemy's X from the player's X and the enemy's Y from the player's Y.)
Then you just set up some conditional branches that define the range.
Say you wanted the enemy to chase the player if you got within 6 tiles of them?
So if the X comparison of their positions is greater than -6 but less than 6 you know they're within range and you can turn on the chase switch.
Make the same check with the Y and there you go.
but anyway, here's what the simpler version would look like controlling one enemy.
Code:
◆Wait:1 frame
◆Control Variables:#0009 Player X = Map X of Player
◆Control Variables:#0010 Player Y = Map Y of Player
◆Control Variables:#0011 Enemy X = Map X of enemy 1
◆Control Variables:#0012 Enemy Y = Map Y of enemy 1
◆Control Variables:#0009 Player X -= Enemy X
◆Control Variables:#0009 Player X -= Enemy Y
◆If:Player X ≥ -6
◆If:Player X ≤ 6
◆
:Else
◆Control Switches:#0003 Enemy 1 chase = OFF
◆Jump to Label:chase
◆
:End
◆
:Else
◆Control Switches:#0003 Enemy 1 chase = OFF
◆Jump to Label:chase
◆
:End
◆If:Player Y ≥ -6
◆If:Enemy Y ≤ 6
◆Control Switches:#0003 Enemy 1 chase = ON
◆
:Else
◆Control Switches:#0003 Enemy 1 chase = OFF
◆
:End
◆
:Else
◆Control Switches:#0003 Enemy 1 chase = OFF
◆
:End
◆Label:Chase
It sounds complicated but it's really just simple math.
The best part is that the single parallel event can be used to control the positions of every enemy on the map with the same variables, just by remaking the position comparison for each of them.
If you REALLY wanted to get fancy, rather than having the parallel event control switches you could have it control the enemy's actual movement by doing more complex comparisons and telling the enemies which way and how to move. it could be used to make an enemy that only moves diagonally, or one that lunges at the player when you walk in front of them or any other pattern you can imagine.
For running away just add a 3rd page to the enemy that runs away from the player and have it controlled by another switch. Something like " If the chase switch is on, and the player's level is greater than X, turn on the "run away" switch."