00:00
00:00

As:enemy's Random Attack

5,345 Views | 20 Replies
New Topic Respond to this Topic

As:enemy's Random Attack 2005-12-08 00:57:09


@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 Spamburger
AS: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


========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

Response to As:enemy's Random Attack 2005-12-08 01:11:46


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:

framenum = 0
_root.onEnterFrame = function(){
framenum++;
if (framenum%4==0 && _root["thing"].hitTest(_root["player"])){
_root["player"].gotoAndStop(Math.floor(Mat
h.random()*3)+4);
} else {
_root["player"].gotoAndStop(1);
}
}

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.

still, clean this up some more...


BBS Signature

Response to As:enemy's Random Attack 2005-12-08 01:15:34


At 12/8/05 01:11 AM, authorblues wrote:
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:

no, it wasnt the problem before

framenum = 0
_root.onEnterFrame = function(){
framenum++;
if (framenum%4==0 && _root["thing"].hitTest(_root["player"])){
_root["player"].gotoAndStop(Math.floor(Mat
h.random()*3)+4);
} else {
_root["player"].gotoAndStop(1);
}
}

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


========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

Response to As:enemy's Random Attack 2005-12-08 01:38:17


At 12/8/05 01:15 AM, Flash_kid wrote: 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).


BBS Signature

Response to As:enemy's Random Attack 2005-12-08 02:03:43


This is just a setup of different things from AS:Main
I think this would fit better with Foss:Main


BBS Signature

Response to As:enemy's Random Attack 2005-12-08 08:34:36


huh what is this about???

Response to As:enemy's Random Attack 2005-12-08 10:26:46


At 12/8/05 08:34 AM, Invisable-Slayer wrote: huh what is this about???

Look at the ma,e of the thread.


BBS Signature

Response to As:enemy's Random Attack 2005-12-08 10:27:46


At 12/8/05 10:26 AM, Claxor wrote: Look at the ma,e of the thread.

Name =P


BBS Signature

Response to As:enemy's Random Attack 2006-01-11 04:27:49


can you please give me the script without any other writing in it? please help me in my game, and ill give you some credits in my game..

Response to As:enemy's Random Attack 2006-01-11 04:36:29


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);
}
}
but it is much better if you learn it.


========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

Response to As:enemy's Random Attack 2006-03-28 22:47:47


this AS dosnt work for me..=\

i have flash 8 does that have anything to do with it?

Response to As:enemy's Random Attack 2006-11-10 04:46:55


yes, i think it does, that is why i asked for the code without all of the writing in it, i thought that was the problem but it wasnt... go and buy flash 7 then come back. :)

Response to As:enemy's Random Attack 2006-11-10 15:38:54


Hey does anyone know how i would adapt this to work for flash 8?

ta

mAx

Response to As:enemy's Random Attack 2008-01-24 01:28:06


its tons of errors in it

Response to As:enemy's Random Attack 2008-03-11 20:06:49


thank you! now i think i'll be able to start my fighting game!

Response to As:enemy's Random Attack 2008-03-12 10:48:22


what does the || mean?

Response to As:enemy's Random Attack 2008-03-12 11:08:29


At 3/12/08 10:48 AM, nightmare222 wrote: what does the || mean?

It's a conditional 'or'.

so if you have

var a:Number = 10;
var b:Number = 20;
if(a == 12 || b == 20){
   trace("true");
}

because one of those is true the statement is true. So the if statement executes. The statement will only not work if both are not true. You can use as many || as you want in an if statement.

Response to As:enemy's Random Attack 2008-03-12 11:25:08


At 1/24/08 01:28 AM, 541-ExE wrote: its tons of errors in it

Yeah, I found this bug which bumps two year old threads.


BBS Signature

Response to As:enemy's Random Attack 2008-07-13 02:02:11


}
}
but it is much better if you learn it.

uh. i dont think it works..


BBS Signature

Response to As:enemy's Random Attack 2008-12-13 13:25:48


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.


we should move all the bibles to the fiction section in the library

BBS Signature

Response to As:enemy's Random Attack 2009-01-17 19:58:10


There are a lot of errors. I tried to work them all out, but no hope
Does anybody hav a .fla or .swf xample using the code?


/