# Pls. Help flash game AI

**URL:** https://forum.kirupa.com/t/pls-help-flash-game-ai/215107
**Category:** flash
**Created:** [February 4, 2007, 12:44pm UTC](https://forum.kirupa.com/t/pls-help-flash-game-ai/215107 "2007-02-04T12:44:24Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![cain\_1st](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@cain\_1st](https://forum.kirupa.com/u/cain_1st)
#### Post date: [February 4, 2007, 12:44pm UTC](https://forum.kirupa.com/t/pls-help-flash-game-ai/215107/1 "2007-02-04T12:44:24Z")

</div>

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;  
}  
}
