ID:268953
 
Hm, How do I make hp meters that go right over the players character? I want there to be one for every mob in the world, npc , monster, everything. Thank ya.
At the sake of giving you code straight out, here.

mob
var
obj/healthbar
New()
..()
spawn()
var/obj/hpbar = new/obj
hpbar.icon = 'hpbar.dmi'
hpbar.icon_state = "100%"
hpbar.pixel_y = 32
src.healthbar = hpbar
src.overlays += hpbar


It would also be best to change the bar whenever you take damage, something like this:

src.healthbar.icon_state = "[round(src.health/src.maxhealth)]"


That should do you fine. If you don't want to create 100 icon states, you could reduce it to 20, then this is your formula:

round(src.health/src.maxhealth)/(100/numStates)*(100/numstates)


numstates is the number of icon states you made, if it is 20, 95.1231421% health would turn out to be 95%, and 93.123719% health would be 90%.
In response to Ter13
Sooo ermm.. What do I rename the icon states to?
In response to Skye Reaver
the icon states are best as percentages.

0%
1%
2%
etc.
etc.
100%

Get it?
In response to Ter13
Ter13 wrote:

It would also be best to change the bar whenever you take damage, something like this:

src.healthbar.icon_state = "[round(src.health/src.maxhealth)]"

That should do you fine. If you don't want to create 100 icon states, you could reduce it to 20, then this is your formula:

round(src.health/src.maxhealth)/(100/numStates)*(100/numstates)

numstates is the number of icon states you made, if it is 20, 95.1231421% health would turn out to be 95%, and 93.123719% health would be 90%.

You can also make use of round()'s second argument:

src.healthbar.icon_state = "[round(src.health/src.maxhealth,5)]"


That would automatically round it off to the nearest 5.
In response to Nick231
I learned to program in another breed of languages. I tend to do things inefficiently sometimes.
In response to Ter13
I'm also wanting to know how to do this, where would i put these 2 commands then

src.healthbar.icon_state = "[round(src.health/src.maxhealth,5)]"

and
round(src.health/src.maxhealth)/(100/numStates)*(100/numstates)
In response to ElderKain
That's for you to figure out. But I will give you a hint, rather than directly changing a person's HP, have an event system. When they lose some hp, call a mob procedure that does the subtraction and any events tied to it for you. those two lines should never go into the same code, as the second line was a formula, and the top line was a basic implementation.
In response to Ter13
OMG this is what iam look 4 but how do i make it that ever time u lose health it shows ?!?! stop being so greedy share plz!!!