Enemy random attack.
As i was looking through as:main the other day trying to think of something to do, i noticed that knowbody had made an enemy's random attack script. so i thought to myself "i know how to do that" so i started typing and came up with this.
Here is the script, it is self explanatory.
onClipEvent(load){
speed=6} //sets the movement speed
onClipEvent (enterFrame) {
if (this._currentframe==1 || this._currentframe==2 && this.hitTest(_root.player)) {// if the current frame is 1 or 2 and its hitting the player
this.gotoAndPlay(random(3)+4); //this goes to and plays a random frame between 4-6
}
if (_currentframe == 4 && !this.hitTest(_root.player)) { //if the current frame is 4 and its not hitting player
this.gotoAndPlay(1); //this goes to and plays 1
}
if (_currentframe == 5 && !this.hitTest(_root.player)) { //if the current frame is 5 and its not hitting player
this.gotoAndPlay(1);//this goes to and plays 1
}
if (_currentframe == 6 && !this.hitTest(_root.player)) {//if the current frame is 6 and its not hitting player
this.gotoAndPlay(1); //this goes to and plays 1
}
if (_root.player._x>this._x) { // if players _x is aboves this's _x
this._x += speed; //_x increases by speed
this.gotoAndStop(2); // this goes to second frame..modify for your movie
_xscale=-100 //xscale is -100 or backwards
}
if (_root.player._x<this._x) { //same as above just the other way around
this._x -= speed;
_xscale=+100
this.gotoAndStop(2);
}
}
*NOTE* don’t forget to change the variables according to your games.
The only things that you need are: a main character with the name of "player" the frames of it attacking as 4,5 and 6 (these can be changed in the script) and thats about it. if you are having any troubles then post a question or add me on msn; e-mail in my profile.
im sure there are other ways but this is the way that i use. post feedback and any questions.