ProgressBar/HealthBar RPG style scripting

I’ve done some healthbar and I stood face to face with a big problem. Like We all know progressbar have precentage value from 0 to 1, it works only with constant values, We’re simply dividing the value through 100 and it works good… but what If I want to change the values? for example:

My character have a 100 HP. If my character is promoted to the next level, my life will increase about 5, and if add skillpoint to endurance takes additional 5 health… but then script of progressbar must be change because it will not fit… but how can I script that??

You gotta do something like:

Health & HealthMax

approach. 2 attributes basically.
And you’re gonna set the progress bar’s value to:

Health / HealthMax.

Whenever you level up, you’ll increase HealthMax. If you want (most games do), you can also increase current Health too (Health = HealthMax). There will be times where you want to increase HealthMax and not increase Health.

In general:

(Attribute - AttributeMin) / (AttributeMax - AttributeMin)

would be better progress bar percentage, if you ever wanna limit the minimum values too.

If not, stick with:

Attribute / AttributeMax.

ps: just make sure min & max values are not the same (division by zero error).

I have two variables - current health and max health. I need to create a one more variable health which is equal to the max health? but where I must to set up current health?

Btw thanks for help!

Your MaxHealth is just the maximum health the character has. The CurrentHealth is from 0 to MaxHealth, the health he currently has.

Both variables are inside the CharacterClass and you will just increase the MaxHealth on LevelUp and apply damage etc to the CurrentHealth.

For your Progressbar, you don’t caluclate it with CurrentHealth / 100, but with CurrentHealth / MaxHealth.

This will give you for example Current and MaxHealth = 100

100 / 100 = 1.0

→ LevelUp: CurrentHealth 100 and Maxhealth = 105

100 / 105 = ~ 0.95

And so on. As long as you divide it by the MaxHealth, you will get a range from 0.0 to 1.0.

eXi!

Thanks for example! now it works like a charm!

Big thanks guys!