ID:178307
 
This isn't actually a question, I just thought I would share this equasion with people. If you want to show someone's HP as a percentage rather than an actual number (which is useful for style and for making HP meters), the equasion for doing so is this...
round(usr.HP+usr.MaxHP*(50/usr.MaxHP))
The round is unneccessary but gives you a whole percentage rather than a fraction. The equasion itself works like this: If the usr's max HP is 50, and their health is full, it works out to HP + MaxHP (100) * (50/MaxHP) (1) = 100. If their max is double that, it will be 200 * .5, resulting in 100. If their HP is -200/-200 (hey, it could happen) you will get -400 * -.25 = 100. The equasion only works if the MaxHP and usr.HP are both negative or both positive. If you have -100/100, you'll turn out with 0 * .5 = 0. You can fix this by adding a bit to the code...
if(usr.HP >= 0 && usr.MaxHP >= 0 || usr.HP <= 0 && usr.MaxHP <= 0)
round(usr.HP+usr.MaxHP*(50/usr.MaxHP))
else
round(abs(usr.HP)+abs(usr.MaxHP)*(abs(50/usr.MaxHP)))(50/usr.MaxHP)))*-1
When you put that in, it will first check to see if they're both negative or if they're both positive (or both 0), and if they are, do the equasion I gave at first. If they aren't, do the same equasion with all the numbers forced to be positive (the abs) then multiply by -1. Anyway, you can use this in your game if you want, but you have to change the code around a bit. These are designed to be put into stat panels. If you find any problems, or feel like thanking me for this equasion, feel free to reply.
Garthor wrote:
round(usr.HP+usr.MaxHP*(50/usr.MaxHP))

Have you tested this? Mathmatically, that expresion reduces to round(usr.HP + 50) which is definately not what you want.

Calculating a percentage is as easy as:
var/percentage = round(current_value/max_value * 100)