Forum Topic: Health AS

(222 views • 8 replies)

This topic is 1 page long.

<< < > >>
None

Phantox

Reply To Post Reply & Quote

Posted at: 1/6/08 01:08 PM

Phantox EVIL LEVEL 23

Sign-Up: 10/29/06

Posts: 8,674

Hey I was wondering if any of you could tell me the AS needed for the following things:

1. Make health NOT go under 0 or over 100 (-5 or 105)

2. Make health increase/decrease by random when a button is pressed.

Could one of you please tell me the action script for those two? The first one doesn't matter much but the second one does.

Thanks

Gamertag: PhantoxNG
Pokemon D/P Friend Codes|Hentai!|

BBS Signature

None

DemonDesigns

Reply To Post Reply & Quote

Posted at: 1/6/08 01:11 PM

DemonDesigns NEUTRAL LEVEL 02

Sign-Up: 12/31/07

Posts: 23

At 1/6/08 01:08 PM, Phantox wrote: Hey I was wondering if any of you could tell me the AS needed for the following things:

1. Make health NOT go under 0 or over 100 (-5 or 105)

2. Make health increase/decrease by random when a button is pressed.

Could one of you please tell me the action script for those two? The first one doesn't matter much but the second one does.

Thanks

well you would have to use a if function. if (health = 0){
health = 0
}
or

if (health = 0){
gotoAndStop("die")
}

None

Hoeloe

Reply To Post Reply & Quote

Posted at: 1/6/08 01:15 PM

Hoeloe LIGHT LEVEL 28

Sign-Up: 04/29/04

Posts: 4,983

At 1/6/08 01:08 PM, Phantox wrote: Hey I was wondering if any of you could tell me the AS needed for the following things:

1. Make health NOT go under 0 or over 100 (-5 or 105)

2. Make health increase/decrease by random when a button is pressed.

2nd post is wrong.

You need to set two:

onEnterFrame = funcion(){
if(hp<= 0){
hp = 0;
//die;
}
if(hp>= 100){
hp = 100;
}
}

and, for the button:

on(release){
_root.hp += random(51) - 25;
}

that should work.

Sex!
------------------------------
Super Nuke Bros. Melee, the web's no. 1 awaited Super Smash Tribute Game!

BBS Signature

None

Phantox

Reply To Post Reply & Quote

Posted at: 1/6/08 01:16 PM

Phantox EVIL LEVEL 23

Sign-Up: 10/29/06

Posts: 8,674

At 1/6/08 01:11 PM, DemonDesigns wrote:
well you would have to use a if function. if (health = 0){
health = 0
}
or

if (health = 0){
gotoAndStop("die")
}

I currently have:

onEnterFrame = function*( {
if(root_.health <= 0) {
_root.gotoAndStop(3);
}

It does the same but it shows -(number) for a while which looks ugly. I could probably fix that but it would be easier if I knew how to prevent a number going below 0 or over 100

Gamertag: PhantoxNG
Pokemon D/P Friend Codes|Hentai!|

BBS Signature

None

Phantox

Reply To Post Reply & Quote

Posted at: 1/6/08 01:20 PM

Phantox EVIL LEVEL 23

Sign-Up: 10/29/06

Posts: 8,674

At 1/6/08 01:15 PM, Hoeloe wrote:
on(release){
_root.hp += random(51) - 25;
}

that should work.

I see... Let me try it out...

Alright it seems to work but it sometimes decreases the health instead of increasing (it might do like ++++--+++-+) any way to stop that?

Gamertag: PhantoxNG
Pokemon D/P Friend Codes|Hentai!|

BBS Signature

None

Dragy2005

Reply To Post Reply & Quote

Posted at: 1/6/08 01:21 PM

Dragy2005 NEUTRAL LEVEL 05

Sign-Up: 04/17/06

Posts: 41

If I got you right, then define the health
var health:Number = 100;

You wanted the health to randomly decrease or increase, so we'll have to use the random() method. So when the button is pressed:

health += Math.floor(Math.random()*20-10);

This will add the health number -10 to 10 randomly. Math.floor should fix 'ugly' numbers.

if you don't want the health to get under 0 or above 100, use conditional stuff after changing the health var,

if(health>100){
health = 100;
}else if (health<0){
health= 0;
}

Hope this helps.


None

Hoeloe

Reply To Post Reply & Quote

Posted at: 1/6/08 01:23 PM

Hoeloe LIGHT LEVEL 28

Sign-Up: 04/29/04

Posts: 4,983

Ok, perfect script time:

onEnterFrame = funcion(){
while(hp<0){
hp = 0;
//die;
}
while(hp>100){
hp = 100;
}
}

and, for the button:

on(release){
_root.hp += random(51);
}

Sex!
------------------------------
Super Nuke Bros. Melee, the web's no. 1 awaited Super Smash Tribute Game!

BBS Signature

None

Phantox

Reply To Post Reply & Quote

Posted at: 1/6/08 01:26 PM

Phantox EVIL LEVEL 23

Sign-Up: 10/29/06

Posts: 8,674

At 1/6/08 01:21 PM, Dragy2005 wrote:
Hope this helps.

Yep. Thanks!

At 1/6/08 01:23 PM, Hoeloe wrote:
and, for the button:

on(release){
_root.hp += random(51);
}

Alright thanks! BTW, I can change the 51 to any number right?

Gamertag: PhantoxNG
Pokemon D/P Friend Codes|Hentai!|

BBS Signature

None

Hoeloe

Reply To Post Reply & Quote

Posted at: 1/6/08 01:29 PM

Hoeloe LIGHT LEVEL 28

Sign-Up: 04/29/04

Posts: 4,983

Yes, also, use the while script I gave, that will get rid of any - numbers.

if checks a variable every frame, so when it ges under 0, you have 1 frame of - numbers. While checks multiple times a frame, so you don't. But don't ever get an infinite while loop. Crashes the damn flash.

Sex!
------------------------------
Super Nuke Bros. Melee, the web's no. 1 awaited Super Smash Tribute Game!

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 11:03 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!