Making a Health System
September 16th, 2006 by awesty
In this tutorial I will teach you how to make a Health System so when you character hits the enemy your health will decrease.
What you need to know:
- Basic flash skills. Like using all the tools and everything.
- You need to have taken my ‘Moving MovieClips with the ArrowKeys tutorial’. Click here veiw it now.
- It would also be good if you had taken my hitTest tutorial, but it doesn’t matter if you haven’t. Click here to veiw it now
- It would help if you had knowledge of another programming language like PHP, JavaScript or C++. Or even better know some ActionScript.
I am using Flash 8 for this tutorial, but you can use Flash MX 2004 if you want.
Lets begin!
Thanks for taking the time to veiw this tutorial. You can find more here. Please take your time to leave some feedback below
Filed under Flash Tutorials















how do i make a lose screen when the hp bar hits zero?
On the health bar change the code from this:
onClipEvent(enterFrame){
this._xscale = _root.hp;
if(_root.hp < 0){
_root.hp = 0;
}
}
To this:
onClipEvent(enterFrame){
this._xscale = _root.hp;
if(_root.hp < 0){
_root.hp = 0;
_root.gotoAndPlay(2)
}
}
And on the second frame add the lose screen.
ok yea i made the enemy have the health bar, and when you kill him it takes you to the secound page, and so i added another enemy on that page, but for some reason it skips that page and goes to the 3rd one, i am REALY lost and any help will be nice [oh and no error box comes up when i play the movie
Did you put:
stop();
on the second frame?
hello sir,
my problem is the healthbar:
onClipEvent(enterFrame){
this._xscale = _root.hp;
if(_root.hp <= 0){
_root.hp = 0;
_root.gotoAndPlay(2);
}
}
i also used the _root.gotoAndStop(2)
inside the healthbar movievlip on the frame # 2 i put the win or lose screen, but it doesnt work when the healthbar turn to “0″ ?
awwwww SNAP
Great tutorial but there is an error in the script for the enemy mc. It should be as follows:
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
_root.hp -= (random(5) 1);
}
}
when you add the code for the lose screen you also need to add a stop action to frame 1:
stop();
Take two. Angle brackets are not allowed
onClipEvent(enterFrame){
this._xscale = _root.hp;
if(_root.hp (LESSTHAN) 0){
_root.hp = 0;
}
}
This is faster and more elegant (not that it matters much):
onClipEvent(enterFrame){
this._xscale = Math.max(_root.hp,0);
}
Still, good tutorials. Maybe I should write a few someday
It didnt work!!!!!
i dont know wat went rong!!!
Click on your enemy movieclip and put the actions with this:
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
_root.hp -= (random(5) 1);
}
}
I accidentally left out a bracket in the tutorial, but stuler pointed it out to me.
I will fix the .fla tomorrow.
i have tryed 4 times.. it\’s donsen\’t work..if i root over the enmy there stil nothing happend..
On what frame or object do i put the _root.hp = 100; script?
how can i make a button that if “man” walk’s over it will change frame?
i figured it out… i added:
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
_root.gotoAndPlay(4)
}
}
to the finish “line”.
On what frame or object do i put the _root.hp = 100; script?
@rafel: Please explain your problem to me clearly.
@rok: You put that script on the first frame, it doesn’t matter which one as long as it is one of the first.
@haavard: Yep, that is right.
@Joe: Like I have already mentioned put it on the first frame.
OK, i’ve tried it with every possible variation i could think of but i cant get the health bar to decrease when man touches enemy, is there a .fla that you could post or e-mail me so i can see what i am doing wrong please?.
BTW Great tutorials, but this is the only one i cant seem to get right
i cant seem to get the enemy script right.
what is it?
other than that, cool tute… keep them coming.
do you have like a source file or something, that you can email me?
Try changing it to this:
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
_root.hp -= (random(5) 1);
}
}
it says :
**Error** Scene=Scene 1, layer=main, frame=2:Line 3: ‘)’ expected
_root.hp -= (random(5) 1);
**Error** Scene=Scene 1, layer=main, frame=2:Line 5: Unexpected ‘}’ encountered
}
Total ActionScript Errors: 2 Reported Errors: 2
This is great. For class we are going to design a game, and I wanted to make a game to keep score by adding up the points, and this tutorial helped me to learn just that.
@sam:
Try changing
_root.hp -= (random(5) 1);
to
_root.hp -= (random(5)-1); (if there is no minus symbol there just pretend there is
)
Wonderfull! Tut! But one itsie pobs, how do i make it so say i have a movie clip called “upgrade” (the instance) when a movie clip called “shot” hits “upgrade” the hpbar goes up a bit?
put this code on upgrade:
onClipEvent(enterFrame){
if(this.hitTest(_root.shot)){
_root.hp = [NUMBER];
}
}
and replace number with whatever number you want to score to go up by. it is exactly the same code put some of the instance names are changed around and it is \’+\’ instead of \’-\’.
ive got my char to move wiv arrow keys,ive got him bumping into walls but i cant get the darn char to lose health its realy frustrating please e.mail me & tell me how to stop it sayin 2 errors & then loads of other stuff (=[
plz write bak soon by the way i reli need the info dude cus ive wanted to create a game cince i was like 4
Please email the .fla to me here and I will try to find the problem.
none of the enemy scipts work
*sigh*
i’ll have to use a different website
I can’t see any thing the movie is white
hey awesty good tut um… could u make a tut that sorta teaches the main points of a RPG or something like that or a tut on how to make a game like thing thing or something
thnx
kickass
@Bradosia: Are you sure you didn’t miss a step?
@P: Do you have the latest flash player?
@kickass: Yep, that will probably be my next tut.
NICE
um.. ok im confused??
about?
Wow! Just gotta work a bit with the scripts and it’s done!
Now my next step is to change the enemy and player to what I want them to look like!
I love it!
Great Tut(s) All Work Great! Will Definately Help Me On My Way To Learn Simple Game Design!
Is there a way to put a cap on the health bar so it wont raise above 100?
Yep.
if(_root.hp => 100){
_root.hp = 100;
}
Put that between the onClipEvent(enterFrame){} on any movieclip.
i have the same problem as many above…
i cant get the healthbar to go down when i “walk” over the enemy.. im using Flash Mx, not 2004, not pro.
Why won’t my movie work?
@Carl: Well it will only work with Flash MX 2004 and Flash 8 since they are the only versions that use ActionScript 2.0. The previous versions use AS 1.0 and the upcoming Flash 9 will have AS 3.0.
@m: I don’t know. Maybe if you explained it to me better I might.
nope…
**Error** Scene=Scene 1, layer=main, frame=2:Line 1: Statement block must be terminated by ‘}’
onClipEvent(enterFrame){
**Error** Scene=Scene 1, layer=main, frame=2:Line 4: Syntax error.
}
Total ActionScript Errors: 2 Reported Errors: 2
want me to send it to you? whats the address?
Tut works great, save the Last bit of AS.
The part with if (_root.hp
@Sam: admin[@]awestyproductions[.]com
@Shani: Huh?
It cut it off.
I ment to say the part with if
(_root.hp
.. And It keeps cutting it off.
The part of action script where the hp isn’t supposed to go to negitive numbers. When I copy and paste it from the tutorial and keep the man MC on the enemy, the numbers bounce from 0 to negitive numbers.
I have no clue whats wrong but I cant seem the get the hp bar to decreas umm i dont know your e-mail but i can send it to ya and mine is truedhar0k@aol.com the o is a zero.
This is what it is saying **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 5: Unexpected ‘}’ encountered
}
Total ActionScript Errors: 3 Reported Errors: 3
I have tried over 10 times and added all the stuff in the forums if you can give me your email ill send it to ya.
ok i fixed some things so ill send you an updated version but still cant get bar to decrease. This is what its saying:
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 2: ‘)’ expected
if(this.hitTest(_root.man){
Total ActionScript Errors: 1 Reported Errors: 1
Hey, I get a weird problem, I’m using Flash 8.
Alrighht, Everyuthing wroks fine, except when i move on him his health doesn’t lower. It says I have no errors but it still doesn’t work.
is there any way i could make a energy meter like it slowly goes up then when you use a energy attack it goes down depending wat lvl the attack is
@Chris: Add an extra bracket on.
if(this.hitTest(_root.man)){
@Jordan: Make sure you have all your instance names on the right MC. If you do send it to admin[@]awestyproductions[.]com and I will see the problem.
@Darin: Yes.
Set the energy up like the health (a bar and dynamic text). Give the text a variable name of energyTxt and put this on the bar:
onClipEvent(enterFrame){
this._xscale = _root.energyTxt;
if(_root.energyTxt < 100){
energyTxt = 2;
}
if(_root.energyTxt >= 100){
energyTxt = 100;
}
And put this on the frame:
energyTxt = 50; //So then it doesn’t start off full.
And then take this tutorial (link) and on the ‘man’ MC put this code.
if(this._currentframe == 3){
_root.energyTxt -= 10;
}
Put that between the onClipEvent(enterFrame)’{}’.
That is just off the top of my head so it might have a few bugs.
cooooooooooooooLLLLLLLLLLLLLLLLLLLLLLll
can you give me a code to make locked charecters that can be unlocked when u meet certain conditions
No, sorry. I might do a tutorial on it, but it would take a while so you might have to wait.
ok ill wait
I tried the code you created for the energy, but the energy bar neither decreases when the man moves, nor does it increase when the man is not moving.
Is it intended to do that?
If not, how could you make it do that?
I loved this tute, but I have to say that some things didn’t work. I use Flash 8, and have had no problems before with other tutorials. This one seems to be the first.
Ok, The bar doesn’t get smaller when I touch the enemy. Have I done anything wrong?
Can you make it so that if the health upgrade touches the “shot”, the upgrade dissapears?
So if I shoot the upgrade, my health goes up, then the upgrade dissapears?
@Goofy: Yes. I will try to do a tutorial for a simple shooter game.
@Jotte: Make sure you have all the instance names and variable names on the right thing, and make sure you have the codes on the right MC/frame.
@Jax: Just send the .fla to admin[@]awestyproductions[.]com
Thanks a ton, yo. But there’s still one prob.
Why does it show negative numbers? Didn’t the tute tell that It’s not supposed to do that?
It’s a great tute anyways
Put this code onto the health bar:
onClipEvent(enterFrame){
this._xscale = _root.hp;
if(_root.hp
For < it won’t work unless you do this:
& l t ;
Without the spaces. (not in flash, in the comments).
What goofy tried to say was:
onClipEvent(enterFrame){
this._xscale = _root.hp;
if(_root.hp <= 0){
_root.hp = 0;
}
}
I have a little problem. It all turned out fine except that the bar comes down from both sides to the midle insted of just coming from the right like yours. And it goes to 1 negative.
I’ve tried changing the codes, i’ve tried everything. The codes are all right but it keeps hapening. What do I do?
cannot put enemy action error look
Clipboard Actions: Line 2: ‘)’ expected
if(this.hitTest(_root.man){
You are missing a ‘)’, just like it says.
Your code has 2 opening brackets and only 1 closing one.
Change it to this:
if(this.hitTest(_root.man)){
Hi,
Love the tutorial everythings working fine. I have a guy with a hammer and he can hit with his hammer when i press space bar. I want to know how if i have my big square and my guy hits the big square the health decreases.
Thanks
I was wondering - if you can make it go to and play frame 2, which has the game over screen, when your health reaches zero, is it possible to play another frame when your score reaches 1000? I have already created a scoring system., I just need to know how to link it to another frame.
Thanks.
@Jax: Put this on a movieclip:
onClipEvent(enterFrame){
if(_root.score >= 1000){
_root.gotoAndStop(3);
}
}
Just change score to whatever yours is called and on frame 3 put the win screen or whatever.
@Lachy: Read this tutorial and you should be able to.
Ah, I see.
I was trying to put this on a frame instead of a movie clip.
It worked, thank you.
sometimes when i try to watch the animation
i can’t it just dosen’t come up. so if you
could just write it out it might be easier
for people with slow internet to find out
what to do
Try getting the latest flash player and clear you cache or something because no matter how slow your computer is it should still work. It works on my 64mb RAM 54mb Internet laptop so it should work on most computers
hey.. my health bar has problem. the number will go beyond zero (negative) when it reaches zero and come back to zero again. can’t i just let it stay zero all the way?
i followed your tutorial very closely..
I done it on the first try… ~~
@Zack: There is no way to stop that from happening, but if you do this it will only happen once.
Change this:
onClipEvent(enterFrame){
if(this.hitTest(_root.man){
_root.hp -= (random(5) 1);
}
}
To this:
onClipEvent(enterFrame){
if(this.hitTest(_root.man){
if(!_root.hp <= 0){
_root.hp -= (random(5) 1);
}
}
i have the same problem as jordan… no errors but still the hp doesnt lower, ill check my mc’s. And could u tell me how to make a game that you can type your name in at the start, and then it can say for example… ” hello (your name) “
I will quickly exlpain it to you.
You need an input text box, give it a variable name of \\\’name\\\’ (without quotation marks), also put stop(); on the frame. Make a button underneath the input text box and make it go to the next frame. Make a dynamic text box and give it a variable name of output. Now on the second frame put this code:
stop();
_root.output = \\\”Hello \\\”+_root.name+\\\”!\\\”;
NOTE: Leave out the \\.
And thats it.
Now put this code on the frame:
_root.hp = 100;
What is the frame?
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Clip events are permitted only for movie clip instances
onClipEvent(enterFrame){
Total ActionScript Errors: 1 Reported Errors: 1
what does that mean and what do I do?
@Matt: Any of them, it doesn’t matter which layer, as long as it is the same as the dynamic text (the frame, not layer).
@Vikram: That means you put the code on a frame instead of a movieclip.
hey, i tested the program, but sometimes, when the box goes past the enemy, the health slightly increases. how can i fix this problem?
That shouldn’t be happening unless you put in a different code.
**Error** Scene=Scene 1, layer=Layer 1, frame=2:Line 2: Operator ‘=’ must be followed by an operand
_root.output = ”Hello ” _root.name ”!”;
Total ActionScript Errors: 1 Reported Errors: 1
_root.output = “Hello “+_root.name+”!”;
hey,
regarding to a really old comment i sent you…
i have a text box on the first frame saying
‘whats your name?’
an input text box to type in your name(variable = name ) and an enter button.
on the next frame, there’s a dynamic text box (var = output) in which i want it to say ‘hello _your name_’
you’ve sent me this code for my second frame:
_root.output = “Hello “ _root.name ”!”;
but i always get this error:
**Error** Scene=Scene 1, layer=Layer 1, frame=2:Line 2: Operator ‘=’ must be followed by an operand
_root.output = ”Hello ” _root.name ”!”;
Total ActionScript Errors: 1 Reported Errors: 1
please help!!
This comes up in a box called output
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 2: ‘)’ expected
if(this.hitTest(_root.man){
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 1: ‘;’ expected
oonClipEvent(enterFrame){
what does this mean?
i cant get this to work.
For the first once change it to this:
if(this.hitTest(_root.man)){
The second one to this:
onClipEvent(enterFrame){
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 3: ‘)’ expected
_root.hp -= (random(5) 1);
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 5: Unexpected ‘}’ encountered
}
Total ActionScript Errors: 2 Reported Errors: 2
this keeps comeing up wot shell i do or can u send me a copy of the flash thing so i can see and look at it my self
I am a junior hool student here but i am trying to make a game using flash mx. our school is teaching us how to do simple games. I am trying to make a dating game (something similar to sim girl or dna2) but I dont know how to make a health bar which is decreasing everytime the main character works to earn money. Anyone help me??? email me at lui_friend@yahoo.com
thanks!
@Daniel: Just send the .fla to admin[@]awestyproductions[.]com
@LOuiii: I don;t konw actionscript 1.0, which is what Flash MX uses. If you can grab hold of a cop of Flash MX 2004 or Flash 8 I could help you
/* This is for Flash MX,.. click the movie clip enemy and put this code. the enemy will react when the life is “0″ */
onClipEvent (enterFrame) {
if (_root.hp == 0) {
enemy = true;
_alpha = 75;
_rotation = 20;
_y = _y 26;
_x = _x 40;
}
/* the “9.5″ below refers to what damage you can give to enemy */
if (this.hitTest(_root.man)) {
_root.hp -= (random(1) 9.5);
}
}
I’m having the same problem as daniel i can’t figure out wat i copied wrong
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 3: ‘)’ expected
_root.hp = (random(5) 1);
Total ActionScript Errors: 1 Reported Errors: 1
hi plz will anyone help me i am a beginner to flash i have done that and i have put a square box in the bottom corner i want to be able to go over that ow with my object and it will take me to another frame IE level 2 so plz will any one tell me
ok, im sorry (your tutorials great!) but since its not changed theres ALOT of actionscript errors. It wontwork.
ok ifigured out what to do for the hpBar but the enemy script still doesnt work. Right now i have
onClipEvent(enterFrame){
this._xscale = _root.hp;
if(_root.hp
please
correct me if im wrong
@cool: it cut off
@tommo:
if(this.hitTest(SOMETHING){
gotoAndStop(FRAME);
}
it wont work forme the health bar it dosent go down it just says _level0.hpbar
Make sure you put this on the frame.
_root.hpbar = 100;
I cant get the enemy to effect my health at all.
None of the above scripts work.
Help please!
Give me more information and I will be able to help.
What flash version are you using?
I’m having trouble with this my errors are…
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 2: ‘)’ expected
if(this.hitTest(_root.man){
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 4: ‘)’ expected
_root.hp -= (random(5) 1);
o yes also i reported this because i need a Health bar for my Fighting Game…
PS: In ur RPG game (if u have ever playe Final Fantasy or are familer with it) can you make an attacking thing with spells attacks and the works? nothing to fancy but maybe with squares?
or something…
For the first one, add an extra bracket to the end.
if(this.hitTest(_root.man)){
For the second one, I think if you fix the first it should go away, but if not try getting rid of the brackets around the random, not the 5 though.
About the final fantasy question, yes you could do that with flash.
um does it matter that it doesent show the var propitie on the heath is not where is it do i need flash8 for this
?
You need flash 8 or flash MX 2004. It says that up the top.
hey awesty health bar still didnt work my formula is as follows
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
if(!_root.hp
and my error is
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 4: ‘)’ expected
_root.hp -= (random(5) 1);
theirs something wrong with
_root.hp -= (random(5) 1);
@Bryce: Angle brackets are not allowed (for hacking reasons), so I couldn\’t read the rest of your comment.
@Tari: Yep. Just change that whole code it is in to this:
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
_root.hp -= (random(5)+1);
}
}
hello,
i am trying to make a game where you are a man trying to avoid a fire balls, wot would the actionscript be for when the fireball hits the man?? he dies if he hits it??? also 4 sum weird reason this tute isnt working.
ollie
if(this.hitTest(FIREBALL){
Do whatever happens when dead;
}
You obviously have to change a few things there. What exactly isn’t working in the tutorial?
uhh wtf is angle brackets
Like less than and greater than signs.
okay awesty i found out how to make it work anyway how do u make it so when the HP equalls zero ur charecter dies or goes to a Game Over screen?
how come the enemy’s health just keeps going down?
like if u stay on the enemy it just keeps going down. is there a way to make it so u “walk” on the enemy it does watever damage and u have to “walk” of and back on to the enemy?
@Bryce K:
if(_root.hp <= 0){
_root.gotoAndStop(FRAME);
}
@RedV: You could do that, but i recommend you don’t, it would make it very easy to beat the game.
But you would do it with variables. I can’t think of a way to do it off the top of my head, but when I do I will maybe do a tutorial or just post it here.
ty u r da greatest
i dont think u understood me
i think its too easy to beat now because you could just camp on the enemy
@Bryce K: I like to think so
@RedV: Lol, we are thinking differently. I meant for the health to be yours, and when you hit the enemy you lose health. If it was the enemy’s health I would probably make an attack.
right thanx
everything works great except when i stay on the enemy the hp bar keeps going down (into negatives)
please help :S
am i surposed to go through my enemy?
if not why am i?
yeah the enemy code dont work at all its tellingme i got a bunch of errors and im using flash 8
@Tyler: It shouldn\’t go into negatives. Make sure you put on all the script correctly.
@Mike: Yes, you are.
@Roar: Try replacing this:
onClipEvent(enterFrame){
if(this.hitTest(_root.man){
_root.hp -= (random(5)+1);
}
}
With this:
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
_root.hp -= (random(5)+1);
}
}
how will i make the “man” moveing up by pressing the space bar?
http://www.awestyproductions.c.....-tutorial/
Try that tutorial.
ok i changed this:
onClipEvent(enterFrame){
this._xscale = _root.hp;
if(_root.hp
sorry i got cut off
i changed this:
onClipEvent(enterFrame){
this._xscale = _root.hp;
if(_root.hp
to this:
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
_root.hp -= (random(5) 1);
}
}
and it works better cause it is barely going up and down any more but it is still going into negatives please help me and give me a correct code to use… thx:)
You got cut off again. You can’t use angle brackets in the comments because of hacking reasons.
The one in the tutorial should be correct.
You could also try this:
onClipEvent(enterFrame){
this._xscale = Math.max(_root.hp,0);
}
lol thnx 4 the tips
It keeps going into negatives. I need some help please. Thanks
Ive read ALL the comments above but the hp bar just wont go down at all… plz can some1 give me a proper code tht actully works! Im using flash mx 2oo4 so i dnt think its anythin to do wif tht… ty
This is what shows up. Ive tried changing the enemys code that everyone is suggesting above, but no sucsess.
**Error** Symbol=enemy, layer=Layer 1, frame=1:Line 2: ‘)’ expected
if(this.hitTest(man_mc){
**Error** Scene=Scene 1, layer=Playing, frame=51:Line 3: ‘)’ expected
_root.hp -= (random(5) 1);
**Error** Scene=Scene 1, layer=Playing, frame=51:Line 5: Unexpected ‘}’ encountered
}
Total ActionScript Errors: 3 Reported Errors: 3
@Bob: Does it keep going into negatives or does it flick from negatives to zero?
@RDB2006: Make sure your enemy has an instance name of man and change this:
if(this.hitTest(man_mc){
To this:
if(this.hitTest(_root.man)){
I tried it but it didnt work.. mabey its cuz i have the instance name of man on my char? it comes up with a different error
**Error** Symbol=enemy, layer=Layer 1, frame=1:Line 2: ‘)’ expected
if(this.hitTest(man_mc){
**Error** Scene=Scene 1, layer=Playing, frame=51:Line 3: ‘)’ expected
_root.hp -= (random(5) 1);
**Error** Scene=Scene 1, layer=Playing, frame=51:Line 5: Unexpected ‘}’ encountered
}
**Error** Symbol=enemy2, layer=Layer 1, frame=1:Line 3: ‘)’ expected
_root.hp -= (random(5) 1);
**Error** Symbol=enemy2, layer=Layer 1, frame=1:Line 5: Unexpected ‘}’ encountered
}
Total ActionScript Errors: 5 Reported Errors: 5
can i send u my fla doc so u can look at it plz?
Did you read my last comment?
There isn\\\’t an .fla for the tutorial, I did the coding in the actual tutorial. But I have a .fla from a different tutorial I did from a site that isn\\\’t around anymore. It is the same tutorial and I am fairly sure the code is the same. You will need Flash 8 to open it though.
http://www.awestyproductions.com/images/Health% 20system% 20tut.fla
Remove the spaces to download.
ok the last advice helped but now its goes down fast but still goes into negatives!!!! >:(
also on your platform tutorial i cant find anyway to be able to jump onto it…
i check the arrow keeys but that just makes it float
and my last message i wrote u might not have recieved so i will type it again.
” ok the last advice you gave me was great because now the hpBar goes down faster, but it still goes into negatives but after walking off the enemy it goes right to 0, but i want it to just stop at 0″
please help me with those questions!?!?!
thanks
That is going to happen regardless. Since you are telling it to minus 5 off it, so it goes to -5, but then it says go back to 0, so it does.
Try changing this:
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
_root.hp -= (random(5)+1);
}
}
To this:
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
if(_root.hp > 0){
_root.hp -= (random(5)+1);
}
}
}
That should work.
eventually! it works :D:D i gave up weeks ago! lol
mine when i test it says NaN were it should say 100 plz could you help me.
@mart on the first keyframe that your health bar is on, click on the keyframe and open the actions panel. type in this code
hp = 100;
think that workz..
soz the code is
_root.hp = 100;
Yes, thats right.
Also, I finally took all the errors out of the tutorial, so hopefully there are no more problems.
i put my health bar inside of my MC, man but when it reaches zero it doesn;t go to frame 2 even when i put _parent.gotoAndStop(2);
[…] This tutorial will be a whole lot easier if you have already taken my Moving MovieClips with the arrow keys, Making walls with hitTests and Making a health system tutorials since alot of the script used in those will be used in this tutorial so I won’t go into as much detail with them as I might with the rest of the script. […]
@Bryce K: Use _root.gotoAndStop(2);
whats the code that if hp hits 0 it stays 0 and goes onto another frame?
if(_root.hp <= 0){
_root.gotoAndStop(FRAME);
}
Hey awesty, WHERE do you learn you flash?
cuz i learn mine from you and tutorialized?
if you dont wan to anwer, you may not
(”’)-.-(”’)
ive created my own simpl maze game so when my hero touches a wall he oges back to the start but i cant add the health bar to it when it jus keeps on flashing and the number sut goes up and down from 99 t0 100
please can somenone help me
@KIM: The internet of course
@dunno: Send the .fla to:
awestyproductions[@]gmail[.]com.
hi, i love ure tutorials. theyre great! however im trying to make a game where things fly in from the left, and u hav to dogde them, or ure health decreases, wot would the script be if the enemies move at 3?
thanks
>
@ollie:
this._x = 3;
{ > }
Do you know how to make a score system? Also, if you do, how would I make it so the score resets if you lose all of your health?
Yes, i could do a tutorial on it. Just post it here:
http://www.awestyproductions.c.....s/request/
ok it kinda works… when i hit the enemy it goes downlike 5 helth but then goes right back to 100… any 1 know how to fix or did i just do something wrong
Just send the .fla to
awestyproductions[@]gmail[.]com
how do i make it so if an enemy hits me, i get hurt, but if my charcter is punching, he wont get hurt and the enemy will die?
thank you
if(!punching){
//Health Code
}
And when he is punching, make the punching variable true, else it is false.
I’m making an RPG game, it’s really lame, but with ur hp bar, right after the monster attacks me and it goes to my menu for attack choices, it goes to full hp bars fr a frame b4 going bak to wat it’s supposed to be. It works fine, but it just keeps doing that weird flash thingie, like it’s refreshing itself or something. Can u help? I can send you the .fla if u don’t get it.
I can’t get my health bar to stop at 0 it will go down to -5 then back to zero than to -5 than back to zero …
@h4×0r: Yea, sure. Just send it to
awestyproductions[@]gmail[.]com
@m7hj5: Just change this:
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
_root.hp -= (random(5) 1);
}
}
To this:
onClipEvent(enterFrame){
if(_root.hp > 0){
if(this.hitTest(_root.man)){
_root.hp -= (random(5) 1);
}
}
}
It’s amazing…. It worked with ONE try! Great job fellows! Keep up the good work…
Hey, your health number goes into negatives, change this:
onClipEvent(enterFrame){
this._xscale = _root.hp;
if(_root.hp
Does your page have a limit? it cut off my last comment…
No, you cant use the less than sign. (<). Just replace it with LESSTHAN when posting a comment.
Hey, when i run over the enemy, the text box says NAN how do you fix that?
I am running flash 8 on windows xp pro.
Did you put this on the first frame?
_root.hp = 100;
Yeah, never mind about it anymore i fixed it by redoing it all over.
Tanks! I love your tuts
Hey Awesty had do i make it so when an object flies and hits my guy he gains life and when a fire ball hits me it loses liƒe. It won’t let me because i can’t use the same symbol
P.S,
Please Respond
hey awesty i play my game and it says: **Error** Scene=Scene 5, layer=Frontground, frame=1:Line 3: ‘)’ expected
_root.hp -= (random(5) 1);
**Error** Scene=Scene 5, layer=Frontground, frame=1:Line 5: Unexpected ‘}’ encountered
}
Total ActionScript Errors: 2 Reported Errors: 2
do you know whats wrong?
never mind i found out what it was
I’ll Have to try this.
2 YOU!
OTHER COMMENT HAVE THE RIGHT TO STAY 5000 MEETERS AWAY:) TO ME
@Mr. Rock: Well, it would be something like:
if(this.hitTest(FIREBALL)){
_root.hp -= NUMBER;
}
if(this.hitTest(MEDIC)){
_root.hp = NUMBER;
}
There are a few things there that you obviously have to change.
@Crap_Face: huh?
umm, my health bar goes decreases brom both sides, u know what i mean?..it doesnt go form right to left…. help!!!!!!Q!!#@!#!@$EWSW$@!#
You need to set your registration point to the left.
How would I make it so that once health is 0( or less ) you lose a life?
I had..
if (_root.bluehealth
Well, I have no idea why my whole comment didnt post last time? I dont thik it did anyway.. I only see a bit of it.
How would I make it so that once health is 0( or less ) you lose a life? I had:
onClipEvent (enterFrame) {
if (_root.bluehealth
You cant post < signs in comments.
Where it says to give the text box a variable name of hp, the diagram is from flash 8, and im using flash mx 2004 and i dont know how to give it the variable name coz i cant find the “var” box.
plz help.
I also tried fixing the other problems in mine but i still have this one:
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 3: ‘)’ expected
_root.hp -= (random(5) 1);
This tutorial was a great help. I’ve placed your site in “favorites” and will check on new tutorials once you release them. I do not want to be a bother, but I have one question. I did everything like you said in the tutorial, and everything works, except for one thing - the numbers. When I touch the enemy, the health bar decreases, but I don’t see the numbers representing health. I don’t even see them them before I touch the bar. Any help would be great, and again, i don’t want to be a bother, for you helped me greatly already.
@mick: Im not really sure, I have never used flash MX 2004.
Try _root.hp -= (random(5) 1);
@NP: Make sure the text color for the box isnt set to white.
oh well, i give up. any way these tutorials have been a great help, keep up the good work.
find a script with if == 0 gotoandstop(2);
sumthin like that m8 ill find now
Ok it works awsome, but i want to make my hp not go down when im in frame 3 of my hero mc (my atack frame) but i dont know how to code it xD, also do you know how the code would look for me to go new frame by the man_mc hitting a box(or door)?
Ok i got my guy to go in to doors, but how would the code look to move a mc to a x and y
ex: move _root.hero to (330,10)
but idk how flash code would look.
when ever I put
onClipEvent(enterFrame){
this._xscale = _root.hp;
if(_root.hp
@Spencer: Well for the attacking this, put this around the health decreasing code:
if(!_root.man._currentframe == 3){
}
For the new _x and _y try:
this._x = 330;
this._y = 10;
@Matty: Your code got cut off, you cant use the less than ( < ) sign.
hentai video clips…
outdoor orgy teen voyeurs group masterbation…
forced anal sex…
rape comix outdoor flashing cartoon rape…
Ohh here
when ever I put this on the HP mc for the lose screen
onClipEvent(enterFrame){
this._xscale = _root.hp;
if(_root.hp [LESSTHEN] 0){
_root.hp = 0;
_root.gotoAndPlay(2)
}
}
Ohh here
when ever I put this on the HP mc for the lose screen
onClipEvent(enterFrame){
this._xscale = _root.hp;
if(_root.hp [LESSTHEN] 0){
_root.hp = 0;
_root.gotoAndPlay(2)
}
}
it constently plays the lose screen and the hp gose down then gose back two 100
it does the same thing when I try to make a win screen for my maze on ur other tutorial
thanks for you help,Matty
Did you put
stop();
on the win/lose screen?
woooooooot thanks so much!
on mine instead of the health stoppin on 0 it goes to a negative number then goes back to 0
how can i fix this?
@zebeker: I have answered that question at least 50 million times before. Please read some of the previous comments.
How do i get to a variable in flash 8 I’m really new and i don’t know were stuff is.
im makin a test game with flash to figure out actionscript and im usin your tutorials to figure some of it out but the health bar starts at zero
Ok since you didn’t get my e-mail i said, Do you know how to make a health bar with hearts so if you get hit by an enemy your heart disappears and you didn’t answer me in the message on
* Making a fight game
How can I have it so he moves forwards alotmaticly but you have control of him moving up and down (mines in water).
sorry my last post was not meant to be here… i though i was on a different page! (sorry!)
Ok I’m stupid with var lol.
@Selvin: Make you you have:
HealthName = 0; (obviously change HealthName to the name of the health.)
@Kurt: Try this tutorial:
http://www.awestyproductions.c.....ables-101/
no i mean i found it…
hey awesty, i cant get the the code working here
if(_root.hp
oh sry, but the loose thing doesnt work.. cant get it to jump frame? where do i add the code? and which code?
In the if(health is less than zero){ statement just add
_root.gotoAndStop(Lose frame);
hay the healf bar dosont go down when my char totches it could you email me the right acshoin script plz
by the way my email is sirmadboy@gmail.com
No, just follow the tutorial and it should work.
I can’t seem to get the lose screen working. It never goes to the second frame.
hey i got everything working and i love your tutorial and i also twisted it a lil and made it where i can gain health but i need a code to make the health bar not go over 100 i thought this might work
if(_root.hp [GREATERTHAN] 100)
_root.hp = 100;
but it dont
o and rulinian from my experince i have found that mabey its just on mine but on mine the person/thing that kills u has to be on top
@Rulinian: You realise that isnt included in the tutorial?
@Chad: Um… Just put an if statement around the increasing health part, so it might look like:
if(_root.hp >= 100){
_root.hp = 100;
}else{
//Health Increase code here
}
ooo ok thanks awesty your the best
now i have another question it really hasnothing to do with this but i dont know where else to post it i need a code that makes a movie clip play at random times
I loved it thanks so much!
@Chad: Put this on the frame:
[INSTANCE_NAME].onEnterFrame = function(){
this.gotoAndStop(random(FRAMES)+1);
}
Replace [INSTANCE_NAME] with the instance name of the MC, and replace FRAMES with the amount of frames in the MC.
Hi, I’m making a game where the health is 10000. I wanted to put a health bar in and i did everything in the tutorial but health bar is way to big when I play the movie. I did some experimentation, and when the health is less than 100 the bar is smaller. Obviously there is a percentage thing happening somewhere.
Is there any way I can have the health at 10000 and still be able to have the hp bar at the right size at the start?
Another thing, is is possible to change the colour of the movie clip from say Green to orange to red as the health goes down?
@Matt: Yes. You would have the hp _xscale equal the currentHP/MaxHP*100. That would get the percentage of the health left, and therefore it would be the same as if you had 100 health.
About the color thing, I will do a tutorial on that tonight.
howcome if you duplicate the enemy mc, with the same code, only the original works? and not the one you copied?
great tute! keep them coming:)
Well if you duplicate an MC and the code is on that MC it should still work.
Ok I used your tutorials to make a new game
http://www.deviantart.com/deviation/57277076/
Nice work man
I have a question, where you say go to frame two where it has your lose screen, it will then instantly reset your game. How do you fix that?
Put stop(); on the lose frame.
my hero has his health system, and I made one for the enemy, but when my enemy loses health, my hero loses health also, what do I do
Make sure all the instance names are different.
can i make just some part of my “hero” hit the enemy and the enemy loses health? like i made a hero and i also made a sword. when the sword touches the enemy, i also lose health.
please help.
Hm, I’m young so if I make a mistake, just correct me =)
Well, if your sword is a mc, you could type this into it:
onClipEvent(enterFrame) {
if(this.hitTest(_root.”A”)) {
_root.”B” -= “C”;
}
}
“A” - bad guys instance name
“B” - bad guys health bar’s instance name
“C” - however much hp u wanna decrease when sword hits him
you could make it a movie clip on it’s own but with the same movement script so it gives the impression that the guy is carrying a sword but he isnt
i have a problem you kno when the health bar goes to ways i want it to go 1 way lol like a rpg game were the health bar goes down from the right please tb thanks.
Try changing the registration point of the HP Bar MC.
yeah, like above, it go down to the middle. how can u make it go down from left to right just like u???
and i sent u an email and u didn’t reply so i have to ask here, how can i finish a level and it goes to a shop frame when u can buy some upgrades and potions.
thanks a lot…
Hiya, I got a problem with my health bar and was wondering if you could help. I have the bar going from right to left after reading some posts(Alot of questions already answered, hate ppl who don’t read posts first lol), but I need to bar to only extend to 100, but need to lower from the maximum health. Since that probably didn’t make any sense at all, I’ll explain it a lil bit more lol. The health bar is way too long right now, and if I try to restrict it to 100, the health bar doesn’t lower until the MC’s health goes below 100. Since your starting health is 120, you gotta get hit for awhile until u finally see your health bar go down. If anyone could help, would be great =)
P.S. I got a website with tutorials xD, just started it tho.
www.freewebs.com/flashtutorialsrpg/
Wow, scratch that out, I just read above and found the answer… I must be retarded o.O, sry for the post =( Really sorry for the repeated question lol.
do u kno how 2 make a number health?
just take the red rectangle away from the stage…
hi is there anyway to make it so that you have 3 harts and if you get hit by an certin enemy it would only take a away a certin amount like say there was a running bomb like if you got hit buy one of them if would take a way a full hart but if you were to get hit by a fluffy pillow it would only take a way half a hart (like the Zelda health system)
i made an rpg (a quarter of it xD) and i made a sleep button. When I press sleep I want the hp go up to 100. help!
Type this on the sleep button. Unfourtunatly, if you read all of awestys tuts, u should be able to do it yourself lol.
on(release) {
hp = 100;
}
orrrr if your hp is a MC for some odd reason
on(release) {
_root.hp = 100;
}
Hope this helps =)
hi, great tutorial.
im trying to make a shooting game… what do i do to make the enemy lose life everytime the cursor clicks on it?
“hi, great tutorial.
im trying to make a shooting game… what do i do to make the enemy lose life everytime the cursor clicks on it?”
All you need to do is change the action script in the enemy.In the enemys action script where you typed
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
_root.hp -= (random(5)+1);
}
Change it to
on(release) {
_root.hp -= (random(5)+1);
}
That wouldn’t necessarily work. The enemies hp would probably have to be different first of all, unless you’re immortal and cannot be killed.
How can i make the health bar to stop whenever it reaches to 0? I’ve than everything and i got it successful but my is that when it reaches zero it continues to negative(-1 and so on).
What I am going to do? Please help.
@angel_metal - make sure you have this code on the health bar:
onClipEvent(enterFrame){
this._xscale = _root.hp;
if(_root.hp
?? it didn’t post the whole code!
(continue)
if(_root.hp
what the? look in the tutorail for this code.
the hp bar goes down but sometimes even if i dont hit the enemy the bar goes down for no reason
How do you make it so you die when it hits 0?
if(health==0){
//do something;
}
i tried to view this tutorial because im making a game. i wanted to know why i can’t view the tutorial and a couple or others? maybe you could email me how to make this health bar. it would really help me.
that is one kwl tutorial
thanku guys
I got the hp bar working, but what if you changed the max life to over 100? How can you get the bar to stay the same length as 100% and still be able to decrease?
hey,
regarding to a really old comment i sent you…
i have a text box on the first frame saying
‘whats your name?’
an input text box to type in your name(variable = name ) and an enter button.
on the next frame, there’s a dynamic text box (var = output) in which i want it to say ‘hello _your name_’
you’ve sent me this code for my second frame:
_root.output = “Hello “ _root.name ”!”;
but i always get this error:
**Error** Scene=Scene 1, layer=Layer 1, frame=2:Line 2: Operator ‘=’ must be followed by an operand
_root.output = ”Hello ” _root.name ”!”;
Total ActionScript Errors: 1 Reported Errors: 1
please help!!
Lol it would more be like this:
_root.output.text = (”Hello ” + _root.name);
great tut worked great with this peice of script added on to the endof the script which you put on the frame:
for(i=1;i<=20;i++)
{
_root[”enemy”].duplicateMovieClip(”enemy”+i,i+1000,face);
}
also I put this code on the end of the enemy code:
onClipEvent(load)
{
function reset()
{
if(this._name==”enemy”)
{
this._visible=false;
}
else
{
this._visible=true;
}
this.dead=0;
this.speed=random(4)+3;
this._x=600;
this._y=random(400);
}
this.reset();
}
onClipEvent(enterFrame)
{
this._x-=this.speed;
if(this._x<-40)
{
this.reset();
}
}
is their any way to make it a maximum health so that it goes no higher than 100, what i did was i continued this on and made a health pack that adds 50 to your health then dissapears (this took a while) how can i make its so that i don’t have 150 health when i touch it but so that it will not go higher than 100?
Usually I wouldn’t do this since if you read the tutorial and comments, you should be able to figure it out, but I see you tried to do it (with health packs and stuff) so I’ll give you the code. Add this:
if (_root.hp > 100) {
_root.hp = 100;
}
thanks that worked
but i tried stuff like that before and it wouldn’t work I don’t know why
mannn I am getting NaN on the HP bar, I have it like this, on the frame, the actions
stop();
_root.bluehp = 550
and there’s a movie clip movable called man, he has
onClipEvent(enterFrame){
if(Key.isDown(Key.RIGHT)){
this._x += 5;
}
if(Key.isDown(Key.LEFT)){
this._x -= 5;
}
if(Key.isDown(Key.UP)){
this._y -= 5;
}
if(Key.isDown(Key.DOWN)){
this._y += 5;
}
}
And then the enemy named blueguy
onClipEvent(enterFrame){
if(this.hitTest(_root.man)){
_root.bluehp -= (random(5)+1);
}
}
So every time I attack blueguy with man, bluehp just displays NaN instead of a decrease in numbers from 550, can anyone help please?
did you create a dynamic text field with a variable of bluehp? if yes then see if removing the stop frame works.
if no then theres your problem.
hope that was of help
Nevermind I fixed it, but I got an issue, the healthbars I have are like massive, when their size is practically as small as yours from the tut
Thanks! Finally a tutorial that works! (plus your first message on these posts was a great help too)
i did this tut and when my one guy attacks the enemy his healthbar gets smaller as well as the enemy’s does anyone know what i can do to fix it?
most likely you have the same instance name for both health bars or only one health variable or the nemies hp text box has a the same “var” as the players.
hope that was of use.
what is a frame?
i know what the frame is now just i cant make the health bar stop at zero. whats wrong i want an awnser from awesty.
When I go into Dynamic Text Box, it will not allow me to make a variable in the slot. I am not allowed to type anything. I am using Adobe CS3 with ActionScript2 . Please e-mail me if you have awnsers
i hv made my health system, but i got a problem. it decreases frm both ends. i want it to decrase frm right to left like yours. plz help
i did everything by the letter, one problem though my healthbar goes down to 5 below zero on touch and when my “man” moves away from my “enemy” it goes back to zero, and back to below 5 when they make contact. if it helps i use Flash CS3 but write in AS2 so i dotn think that would be a problem would it?
Thanks for the tutorial but …
I will do a game of street fights
and if I make the enemies if I play I do not want to lose my character hp
I have to get this code?
if (this.hitTest (_root.man)) (