Player Detection with Events only

Hi
I am starting an action rpg game project and I have a question for Rpgmaker XP:

Enemy will detect if Player is 3 tiles away from it in any direction and will move towards Player if Player is within this range. Like in Secret of Mana, Legend of Mana or Secret of Evermore, when the enemies "sees" the hero at a particular distance, they rush to attack him. Can anyone help on how can I make the Enemy calculates and detects Player? I would like to do this only with Events without any scripts.


Thank you for your help!!
Do you need to check for a collision as well as if the player is in the sight range?
Yes, a collision is also part of it when the player will touch enemy with his attacks. Thank you!
And when the player gets a certain distance away does it need to go back to normal movement? If so, it would be so much easier in a script.
the enemy will move at random direction and once player is out of its range, it just stop following player and continue its random movement. Is there a script demo or example that you know of?
I made one, but all my progress was lost when my other computer crashed. I'll recreate it for you.

Edit. Here it is:
  1.  
  2. class Game_Event < Game_Player
  3.     alias tdks_orig_init initialize
  4.     def initialize(map_id, event)
  5.         super(map_id, event)
  6.         if @event.name.sub!(/\(chase\, \d+\, \d+\, \d\)/,"")
  7.             @s_range = $1
  8.             @e_range = $2
  9.             @move_change = $3
  10.         elsif @event.name.sub!(/\(chase\, \d+\, \d\)/,"")
  11.             @s_range, @e_range = $1, $1
  12.             @move_change = $2
  13.         end
  14.     end
  15.    
  16.     alias tdks_orig_update update
  17.     def update
  18.         if @move_change and !@stored and @move_type != @move_change
  19.             dx = (@x - $game_player.x).abs
  20.             dy = (@y - $game_player.y).abs
  21.             distance = Math.sqrt(dx ** 2.0 + dy ** 2.0)
  22.             if distance <= @s_range
  23.                 @move_type, @stored = @move_change, @move_type
  24.             end
  25.         elsif @move_change and @stored
  26.             dx = (@x - $game_player.x).abs
  27.             dy = (@y - $game_player.y).abs
  28.             distance = Math.sqrt(dx ** 2.0 + dy ** 2.0)
  29.             if distance > @e_range
  30.                 @move_type, @stored = @stored, nil
  31.             end
  32.         end
  33.         super
  34.     end
  35. end
  36.  
Expand to see the code.


To use, put:
  1. (chase, range, new_move_type)
Expand to see the code.

in the event name, where range is the range from the player at which the event's movement should change, and new_move_type is the movement type to change to (0 - fixed, 1 - random, 2 - approach player).
Thanks for the help! I shall take a look and try to edit it to suit my game. Thank you!

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=76823