dim3 Forum

Full Version: Health Counter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was wondering if it would be possible to script the health of an object as a damage percentage or hit points that would be visible on-screen; much like they did in games such as Super Smash Bros Melee. I would need two variations of this: one in which the value starts at 0% and goes upwards, and one where their health is rendered as hit points and decreases with each hit. Would I have to render that as a counter, or possibly a bitmap that somehow updates itself accordingly? I would really prefer some sort of counter, similar to the ammo readout for the grenades, but bigger, of course; the idea of having to possibly calculate myriads of possibilities for damage ratios is rather odious to me. If anyone has any insight into this, or possibly a more suitable alternative, I would be most appreciative!
Make a text object and get rid of the health bar. Instead of updating the health bar each time have the script update the text. I believe when doing the health bar it sets it to health/100, so just do health/100*100 to get a percent without the decimal point. It should also be easy to switch the script to count up instead of down. You can do that much, right?
In other words, set a text item and do all the permutations that I was attempting to avoid? That was a solution I already had in mind, I was simply hoping for something a little more convenient....

But thank you for your help, I appreciate it greatly!
Are you kidding? If the player can hold 200 health, just divide by 2 and you get the percent. Doesn't get more convenient than that. Smile
(and the script is already there, all you need to do is change the math, and change "bar" to "text")
ccccc Wrote:Are you kidding? If the player can hold 200 health, just divide by 2 and you get the percent. Doesn't get more convenient than that. Smile
(and the script is already there, all you need to do is change the math, and change "bar" to "text")

He also want's the "damage" in percent.
So if the player is at 200, the output would be 0. At 180, it would be 10, etc.
This is also easy to do though.
Just do:
Code:
var damagePercent = (obj.health.maximum - obj.health.current)/obj.health.maximum*100;
and you will get the damage in percent.
I just hope that I didn't make a mistake. lol

Then, to display it, create a text object in the interface.xml and use
Code:
iface.text.setText("name_of_the_text_object",damagePercent); //damage percent was defined above
Perhaps I can approach this another way; I suppose to be supremely technical, the player objects sustain no actual damage when they are hit; they merely retain damage events. I simply want my little counter to update itself accordingly each time they are hit; as I said before I intend to try to render 2 modes as it were, one where the health is rendered as a text object representing hit points (probably no higher than 500 or so), and one where, as Bink said, the counter starts at 0 and rises. However, I believe it was a bit inaccurate to say I wanted the health as an ACTUAL percent (although such will likely be very useful to know later on); I merely want it to look like a percentage, which I imagine could be specified in the text quite easily....

Also I did not at first fully comprehend what teh1ghool meant; I was still thinking bitmaps for the counter. He actually had the right idea; I wasn't sure if a text object would serve as a counter; I thought I would have to make multiple text objects and update accordingly.

You have all been most helpful indeed, I am in your debt!
Reference URL's