Be a Supporter!

As:enemy's Random Attack

  • 4,460 Views
  • 20 Replies
New Topic Respond to this Topic
Vengeance
Vengeance
  • Member since: Mar. 18, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
As:enemy's Random Attack Dec. 8th, 2005 @ 12:57 AM Reply

@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
authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As:enemy's Random Attack Dec. 8th, 2005 @ 01:11 AM Reply

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
Vengeance
Vengeance
  • Member since: Mar. 18, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to As:enemy's Random Attack Dec. 8th, 2005 @ 01:15 AM Reply

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
authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As:enemy's Random Attack Dec. 8th, 2005 @ 01:38 AM Reply

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
GuyWithHisComp
GuyWithHisComp
  • Member since: Nov. 10, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to As:enemy's Random Attack Dec. 8th, 2005 @ 02:03 AM Reply

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


BBS Signature
Invisable-Slayer
Invisable-Slayer
  • Member since: Dec. 4, 2005
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to As:enemy's Random Attack Dec. 8th, 2005 @ 08:34 AM Reply

huh what is this about???

Claxor
Claxor
  • Member since: Oct. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As:enemy's Random Attack Dec. 8th, 2005 @ 10:26 AM Reply

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
Claxor
Claxor
  • Member since: Oct. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As:enemy's Random Attack Dec. 8th, 2005 @ 10:27 AM Reply

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

Name =P


BBS Signature
ELFERRETO
ELFERRETO
  • Member since: Dec. 3, 2004
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As:enemy's Random Attack Jan. 11th, 2006 @ 04:27 AM Reply

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..

Vengeance
Vengeance
  • Member since: Mar. 18, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to As:enemy's Random Attack Jan. 11th, 2006 @ 04:36 AM Reply

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
blingblingx1
blingblingx1
  • Member since: Mar. 22, 2006
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to As:enemy's Random Attack Mar. 28th, 2006 @ 10:47 PM Reply

this AS dosnt work for me..=\

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

ELFERRETO
ELFERRETO
  • Member since: Dec. 3, 2004
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As:enemy's Random Attack Nov. 10th, 2006 @ 04:46 AM Reply

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. :)

maxxist
maxxist
  • Member since: Nov. 30, 2003
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to As:enemy's Random Attack Nov. 10th, 2006 @ 03:38 PM Reply

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

ta

mAx

541-ExE
541-ExE
  • Member since: Oct. 10, 2007
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to As:enemy's Random Attack Jan. 24th, 2008 @ 01:28 AM Reply

its tons of errors in it

nightmare222
nightmare222
  • Member since: Apr. 15, 2006
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to As:enemy's Random Attack Mar. 11th, 2008 @ 08:06 PM Reply

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

nightmare222
nightmare222
  • Member since: Apr. 15, 2006
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to As:enemy's Random Attack Mar. 12th, 2008 @ 10:48 AM Reply

what does the || mean?

Cojones893
Cojones893
  • Member since: Mar. 9, 2003
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to As:enemy's Random Attack Mar. 12th, 2008 @ 11:08 AM Reply

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.

Paranoia
Paranoia
  • Member since: Apr. 22, 2005
  • Offline.
Forum Stats
Member
Level 35
Game Developer
Response to As:enemy's Random Attack Mar. 12th, 2008 @ 11:25 AM Reply

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
JohnnySkul
JohnnySkul
  • Member since: Aug. 15, 2007
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to As:enemy's Random Attack Jul. 13th, 2008 @ 02:02 AM Reply

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

uh. i dont think it works..


BBS Signature
PlatformSource
PlatformSource
  • Member since: Aug. 11, 2005
  • Offline.
Forum Stats
Member
Level 13
Programmer
Response to As:enemy's Random Attack Dec. 13th, 2008 @ 01:25 PM Reply

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
Renandchi2
Renandchi2
  • Member since: Jul. 24, 2008
  • Offline.
Forum Stats
Member
Level 13
Filmmaker
Response to As:enemy's Random Attack Jan. 17th, 2009 @ 07:58 PM Reply

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?


/