Pls. Help flash game AI

pls. help the code below are for my AI the only thing can do is chase the player if it’s in range and attack i need them to follow path and respown after 10 sec or so just like in warcraft3 dota pls. help or any links you can give thanks.

onClipEvent(enterFrame)
{
distance=200
rx=_root.player2whole._x
ry=_root.player2whole._y
erx=_root.monster2whole._x
ery=_root.monster2whole._y

if (Math.sqrt( (rx-erx)(rx-erx) + (ry-ery)(ry-ery))<distance)
{
if(rx<erx-20){
this._x-=2;
gotoAndStop(“monster2left”);
if(_root.monster2whole.hitTest(_root.player2whole) )
{
gotoAndStop(“monster2attackleft”);

}
}

else if(ry<ery-20){
this._y-=2;
gotoAndStop(“monster2back”);
if(_root.monster2whole.hitTest(_root.player2whole) )
{
gotoAndStop(“monster2attackback”);

}
}
else if(rx>erx+20){
this._x+=2;
gotoAndStop(“monster2right”);
if(_root.monster2whole.hitTest(_root.player2whole) )
{
gotoAndStop(“monster2attackright”);

}
}
else if(ry>ery+20){
this._y+=2;
gotoAndStop(“monster2front”);
if(_root.monster2whole.hitTest(_root.player2whole) )
{
gotoAndStop(“monster2attackfront”);

}
}
}
_root.monster2whole.m2hpcase._alpha = 0;
_root.monster2whole.m2hp._alpha = 0;
if(_root.monster2whole.hitTest(_root.player2whole) )
{
_root.monster2whole.m2hpcase._alpha = 100;
_root.monster2whole.m2hp._alpha = 100;
}
}