Without much info, the most straight forward method would be to detect how far away the enemy is from you.
+ System compare distance(you.x,you.y,enemy.x,enemy.y) is greater than n amount
-> enemy do this
+ System compare distance(you.x,you.y,enemy.x,enemy.y) is less than n amount
-> enemy do that