Page 3 of 3

PostPosted: Thu Aug 16, 2007 5:38 pm
by cyber ruler
I havn't used this kind of health bar in a while, so I may be a little off with this explanation.

Notice how there are 3 sections of the coding. Update health bar, change health, and set health.

Updatehealthbar: doesn't do much.

changehealth: put it in script editor when you want to add or subtract health. put ChangeHealth(*) but instead of the star, put a posotive number to add that much to the healthbar, or a negative to subtract it.

Sethealth: put it in script editor when you want to set exactly how much health you want to have at the time. use SetHealth(*) but instead of the star, put the amount of health you want the actor to have.

you will also have to put stuff in like (and some1 plz correct me if I did this wrong)
Code: Select all
if (g_PlayerHealth <= 0)
{
    ***
}

put in place of the star what you want to happen when the health bar is empty

PostPosted: Thu Aug 16, 2007 8:36 pm
by automail10
isn't this an old topic?

Re: Making a Health Bar - Tutorial

PostPosted: Mon Apr 13, 2009 4:27 pm
by TheVoiceInMyHead
Hello There,

Well... newbie here - i'm sorry for digging such an old post but i've really been trying to put this to work for hours!

So, I followed the tutorial as I do a C/C++ background it was fairly easy to understand what the functions were doing.
Symptoms:
- In the CreateActor of my HealthBar actor i put: SetHealth(10);
Perfect, it works! (it did change the initial text that I put 00 to 10)

- Now in the collision event of a harmful actor I wrote code to destroy the harmful actor, create another actor for explosion aaaannnd ChangeHealth(-1)
Guess what?! the harmful actor is destroyed, the explosion is created but no change in my health bar!

Other info:
- I created a test actor to hold my player's health (g_PlayerHealth) and something really odd happened: If I attempt to update this actor TextNumber in an event (such as the above collision) it works just fine!
Buuuuut
if I attempt to update its textNumber inside any of the 3 functions that I did put in Global Code guess what?! It doesn update the textNumber...
It's like if the functions could be called only once (in the CreateActor of the health bar) and no more after that

Has anybody got any clue of what is going on?

Many Thanks!

Re: Making a Health Bar - Tutorial

PostPosted: Mon Apr 13, 2009 8:03 pm
by DST
This is more of a scripted c healthbar; Its how you would make one if you weren't using ge.

Ge has so many shortcuts for things, you can easily just report health as a global array, or send health to the text actor.

textNumber=actorname.health; etc. etc. There are lots of simple health bars in ge.

If you're just messing with it for fun, then whatever.

If you're trying to make better health bars, check these topics:

viewtopic.php?f=6&t=5756

viewtopic.php?f=6&t=6335

viewtopic.php?f=6&t=6360

Re: Making a Health Bar - Tutorial

PostPosted: Mon Apr 13, 2009 9:20 pm
by jimmynewguy
oh, about the tower defense one. Is there anyway to edit that code to make it where it works when the view is moving?
i'm sure it's something simple im over looking......thnx in advanced anyone :)

Re: Making a Health Bar - Tutorial

PostPosted: Tue Apr 14, 2009 1:48 am
by sillydraco
MOVED

Re: Making a Health Bar - Tutorial

PostPosted: Tue Apr 14, 2009 1:50 am
by DST
xscreen
yscreen
screen_to_actor
actor_to_screen

Use these along with a canvas that moves along with view to translate from global x to screen x.

This would be good too, moving the canvas along with view, as then the canvas won't need to render anything that isn't on screen to begin with.

You can look those up in the script reference, using them to modify the draw shouldn't be difficult.

Re: Making a Health Bar - Tutorial

PostPosted: Tue Apr 14, 2009 2:09 am
by sillydraco
i'm working on a health bar atm ( viewtopic.php?f=6&t=6659&p=47716#p47716 ) but im having some trouble with the code :/ i know whats wrong with the code, i just dont know how to fix it!

i have the code set to if the animation is HP100, then it changes the animation to HP90, and 90 to 80, and so forth. then when its HP10, it changes the animation of the character to Splode (three guesses as to what that means!). i have the character set to destroy itself when the animation ends. yet when the character takes damage, it goes to HP90 and the character goes to splode, but thats it! i think the if code is going into a loop instead of only doing one :3


EDIT: i fixed it! i had one too many } between the Else statements :3 heres my code! i have ten animations, animindex 0-9, 0 being HP10 and 9 being HP100. going in increments of ten, being one box to ten full boxes. i made an activation event (collide finish with enemy) from my character to the health bar, and this script whenever i collide with the enemy. it just checks what animation the health bar is on, then puts it to one less. also i put a changeanimation function at the beginning, so he does his little OMG animation whenever he gets hit. i might add another changeanimation for my character blowing up, then have an animationfinish event, to destroy the actor.

heres the code!

Code: Select all
ChangeAnimation("Draco", "hurt1", FORWARD);

if(animindex == 9)
{
    {
    ChangeAnimation("Health", "HP90", FORWARD);
    }
}


else
{
 if(animindex == 8) {
    ChangeAnimation("Health", "HP80", FORWARD); }

else
{
 if(animindex == 7) {
    ChangeAnimation("Health", "HP70", FORWARD); }


else
{
 if(animindex == 6) {
    ChangeAnimation("Health", "HP60", FORWARD); }

else
{
 if(animindex == 5) {
    ChangeAnimation("Health", "HP50", FORWARD); }


else
{
 if(animindex == 4) {
    ChangeAnimation("Health", "HP40", FORWARD); }


else
{
 if(animindex == 3) {
    ChangeAnimation("Health", "HP30", FORWARD); }


else
{
 if(animindex == 2) {
    ChangeAnimation("Health", "HP20", FORWARD); }


else
{
 if(animindex == 1) {
    ChangeAnimation("Health", "HP10", FORWARD); }


else
{
 if(animindex == 0) {
    ChangeAnimation("Health", "HP0", FORWARD); }
}}}}}}}}}

Re: Making a Health Bar - Tutorial

PostPosted: Tue Apr 14, 2009 12:15 pm
by DST
Draco, you're doing it the ultra mega kamehameha hard way!

Don't use all those animations. Just pile them into one 10 frame animation.

then....are you ready for this?

healthmeter>draw actor>

Code: Select all
animpos=round(health/10);


or player.health if health is an actor variable.

Re: Making a Health Bar - Tutorial

PostPosted: Tue Apr 14, 2009 7:04 pm
by sillydraco
OMG im retarded! x.x ah well, at least its working!

Re: Making a Health Bar - Tutorial

PostPosted: Tue Apr 14, 2009 7:20 pm
by DST
Learning is fun!

Re: Making a Health Bar - Tutorial

PostPosted: Sat Apr 18, 2009 3:35 pm
by BlarghNRawr
only if its interesting