Enemy ai code

APPARENTLY THIS IS A CODE FOR AN ENMEMY BUT I DONT REALLY UNDESTAND IT CAN SOME HELP QUOTE IT PLZ SO I KNO WHAT THE LINES MEAN OR PERHARPS GIVE ME A BETTER CODE THANKS


var randAttack:Number = random( 3 );
var randSpecialAttack:Number = random( 10 );
var attackPower:Number = 100;
var takeHealth:Number;

if( playerClose > -50 || playerClose < 50 ) {

   for( i=0; playerClose < i; playerClose++ ) {
      --attackPower;
   }
   
   for( i=0; playerClose > i; playerClose-- ) {
      --attackPower;
   }
   if( randSpecialAttack === 1 ) {

      takeHealth = attackPower*2;
      trace( "- S P E C I A L	A T T A C K!!!" );

   } else {

      takeHealth = attackPower;
      trace( "Hit!" );

   }

} else {

   displayTime = 5;
   countDown = function() {
      displayTime--;
      if (displayTime === 0 ){
         clearInterval( timer );
      }
   }
   timer = setInterval( countDown,1000 );

}

[FONT=Courier New][/FONT]

Ok im gonna break this into chunks
[AS]
var randAttack:Number = random( 3 );
var randSpecialAttack:Number = random( 10 );
var attackPower:Number = 100;
var takeHealth:Number;

This is the variables being defined. Defining what attack, what special attack the enemy is going to use. The attack power and takehealth.

if( playerClose > -50 || playerClose < 50 ) {

for( i=0; playerClose < i; playerClose++ ) {
–attackPower;
}

for( i=0; playerClose > i; playerClose-- ) {
–attackPower;
}
if( randSpecialAttack === 1 ) {

  takeHealth = attackPower*2;
  trace( "- S P E C I A L	A T T A C K!!!" );

} else {

  takeHealth = attackPower;
  trace( "Hit!" );

}

}


So the first line checks if the player is 50 pixels or less from the enemy,
The two for loops I dont know what they do. And then the 'randSpecialAttack' is checking if the variable that was defined in the begining was 1. The variable defined was random 3 so it has a third chance of becoming one. If its one then its specialAttack!
if its not specialattack then its normal attack.


} else {

displayTime = 5;
countDown = function() {
displayTime–;
if (displayTime === 0 ){
clearInterval( timer );
}
}
timer = setInterval( countDown,1000 );

}


This happens if the player is not close.
and well it doesnt do anything but set an timer to do nothing :S
I guess we'll have to see the whole script to figure out some parts. Ask again if im being unclear :)

were would i put this code in the main frame and do you think you could make an easier code plz

Hi, first off, At least you have the code. You would probs put it in enemy’s mc or char’s mc. And second off, i don’t think that code can be put simpler

after reading joppes description i understood what i didnt before thnx joppe and seems like a good code :smiley:

Where did you get the code from if you dont know how to use it?
Im sorry but I dont think the code would work without some other parts of the script. Or well it would work but it wouldnt be used full fletched (sp?)

Here is the code i requested fo originally

[COLOR=blue][FONT=‘Comic Sans MS’]if Player away -> wait 5 seconds -> get near[/FONT][/COLOR]
[COLOR=blue][FONT=‘Comic Sans MS’]if near -> If Player standing or walking(running) -> Attack!! (random attack/Attack one or Attack 2) [/FONT][/COLOR]
[COLOR=blue][FONT=‘Comic Sans MS’]if finished attacking -> wait 5 seconds -> move away[/FONT][/COLOR]
[COLOR=blue][FONT=‘Comic Sans MS’] else[/FONT][/COLOR]
[COLOR=blue][FONT=‘Comic Sans MS’]if Player attacking(1x out 3x) -> if Player near -> try to Block / if not -> ignore dumb player attacking thin air… [/FONT][/COLOR]
[COLOR=blue][FONT=‘Comic Sans MS’]or[/FONT][/COLOR]
[COLOR=blue][FONT=‘Comic Sans MS’]if Player attacking(2x out of 3x) -> if Player near -> let player hit you… [/FONT][/COLOR]****[COLOR=red][FONT=‘Comic Sans MS’][/FONT][/COLOR]
[COLOR=blue][FONT=‘Comic Sans MS’]if Player does special -> if near -> let player hit you-> [/FONT][/COLOR]
[COLOR=blue][FONT=‘Comic Sans MS’] else[/FONT][/COLOR]
[COLOR=blue][FONT=‘Comic Sans MS’]if away -> block!![/FONT][/COLOR]

the code in the previous post it wat was given to me. i was hoping that one of you would be able to make a code matching that description above and if so perhaps quote the code please

not sure about the other code surrounding… or anything like that but would you need to put a repeat in there somewhere. another thing… You keep pasting these really big codes and never seem to know what they do… Maybe you should try wrapping your head around functions etc… that code is really basic. Take a look at my link below go to tutorials and read the basics… everything is explained there except the intervals.

http://www.n99creations.com/