@5: /\/\@1|\|. +3|-| 1337357 70P1C 3V@
Hi everyone, i made this a while ago but it wasnt accepted on as:main coz it wasnt detailed enough, so i decided to redo it;
as knowledge needed:AS:Random by SpamburgerAS:Condition's and loops -BleeBlap
what it is used for:
this code is used for making enemy's come at you and when they get to you they randomly attack.
set up:
have your main character's movie clip and give it the instance name of "player"
have your enemy movie clip with this on these frames:
1. standing still
2. walking
3. jumping
4. attack 1
5. attack 2
6. attack 3
the code:
onClipEvent(load){
speed=6}
onClipEvent (enterFrame) {
if (this._currentframe==1 || this._currentframe==2 && this.hitTest(_root.player)) this.gotoAndPlay(random(3)+4);
}
if (_currentframe == 4 && !this.hitTest(_root.player)) {
this.gotoAndPlay(1);
}
if (_currentframe == 5 && !this.hitTest(_root.player)) {
this.gotoAndPlay(1);
}
if (_currentframe == 6 && !this.hitTest(_root.player))
this.gotoAndPlay(1); //this goes to and plays 1
}
if (_root.player._x>this._x) {
this._x += speed;
this.gotoAndStop(2);
_xscale=-100
}
if (_root.player._x<this._x) {
this._x -= speed;
_xscale=+100
this.gotoAndStop(2);
}
}
explaining the code:
onClipEvent(load){
speed=6}
sets the speed that the character move's at to 6

if (this._currentframe==1 || this._currentframe==2 && this.hitTest(_root.player)) this.gotoAndPlay(random(3)+4);
}
if the current frame is either 1 or 2 (this._currentframe==1 ||this._currentframe==2) and it's hitting the player (&& this.hitTest(_root.player)) this.gotoAndPlay(random(3)+4) this movieclip goes to a random frame between for and 6, thats why you have +4 on the end.
if (_currentframe == 4 && !this.hitTest(_root.player)) {
this.gotoAndPlay(1);
}
if the current frame is 4 and it's not hitting the player, the movie clip goes back to the first frame. (having an ! before a statement makes it if its NOT true)
its the same for the next 3 statements, just with different frames.
if (_root.player._x>this._x) {
this._x += speed;
this.gotoAndStop(2);
_xscale=-100
}
if (_root.player._x<this._x) {
this._x -= speed;
_xscale=+100
this.gotoAndStop(2);
}
this checks whether the _x co-ordernates of the player is above or below this's and if its either this goes to the second frame, flips and move's that direction.
I hope you learnt something from this tutorial, reply with any questions/queries

At 12/8/05 12:57 AM, Flash_kid wrote:
Hi everyone, i made this a while ago but it wasnt accepted on as:main coz it wasnt detailed enough, so i decided to redo it;

i dont know if it was actually the issue before, and it certainly isnt the issue now, but this doesnt have any problem with detail. its more of an issue with is this the easiest way to do this? my answer: no. i think a simpler method could be devised. like:

of course, that isnt going to completely solve the problem, but something similar to that would probably be better than a bunch of _currentframe checks. maybe im just picky because ive never cared for the _currentframe property.

At 12/8/05 12:57 AM, Flash_kid wrote:
Hi everyone, i made this a while ago but it wasnt accepted on as:main coz it wasnt detailed enough, so i decided to redo it;

i dont know if it was actually the issue before, and it certainly isnt the issue now, but this doesnt have any problem with detail. its more of an issue with is this the easiest way to do this? my answer: no. i think a simpler method could be devised. like:

yer, but my code is for noobs who just wanna get their enemy to attack them. good luck trying to explain that to them

of course, that isnt going to completely solve the problem, but something similar to that would probably be better than a bunch of _currentframe checks. maybe im just picky because ive never cared for the _currentframe property.

ninja-chicken taught me the _currentframe property and i've never looked back

dont believe everything NC says. its a nice trick to use, but thats just excessive what youve done, and it creates a cluttered script. there are cleaner, shorter, and easier ways to do what youre trying to do (the only thing you really need to change is just use modulus, and you can cut away about 2/3 of your script).

yeah this doesnt even work, and im pretty skilled with flash, when i tried it , it gave me errors, i worked them out so it wouldent give errors, and when i do that the code never screws it up. so yeah, i dont know if others have this problem, but if you have an FLA or an SWF example, i would just oh so love to see it.