ID:178577
 
mob
var
obj/HealthBar
New()
..()
HealthBar = new/obj()
HealthBar.icon = 'Healthbar.dmi'
usr.overlays += HealthBar
usr.SetHealthIconState()
mob/proc/SetHealthIconState()
var/state
switch(round(health/max_health)*100)
if(0) state = "0"
if(10) state = "10"
if(9) state = "9"
if(8) state = "8"
if(7) state = "7"
if(6) state = "6"
if(5) state = "5"
if(4) state = "4"
if(3) state = "3"
if(2) state = "2"
if(1) state = "1"
HealthBar.icon_state = state

This doesn't add anything to my overlays, any suggestions why?
Sariat wrote:
> mob
> var
> obj/HealthBar
> New()
> ..()
> HealthBar = new/obj()
> HealthBar.icon = 'Healthbar.dmi'
> usr.overlays += HealthBar
> usr.SetHealthIconState()
> mob/proc/SetHealthIconState()
> var/state
> switch(round(health/max_health)*100)
> if(0) state = "0"
> if(10) state = "10"
> if(9) state = "9"
> if(8) state = "8"
> if(7) state = "7"
> if(6) state = "6"
> if(5) state = "5"
> if(4) state = "4"
> if(3) state = "3"
> if(2) state = "2"
> if(1) state = "1"
> HealthBar.icon_state = state
>

This doesn't add anything to my overlays, any suggestions why?

looks like state is going to vary from 1 to 100, not 1 to 10. Here's a simpler version with the correct math as well:
mob/proc/SetHealthIconState()
HealthBar.icon_state = "[round(health/max_health)*10]"
try overlaying an icon, you cant overlay a atom
In response to Skysaw
Thanks! But it still isn't making the health bar
In response to Sariat
I believe you need to set the icon_state before adding it as an overlay. Also, that means you'll have to remove the overlay and add it again anytime the icon_state changes.

-AbyssDragon
In response to AbyssDragon
AbyssDragon wrote:
I believe you need to set the icon_state before adding it as an overlay. Also, that means you'll have to remove the overlay and add it again anytime the icon_state changes.

That's true.

1. subtract overlay
2. set icon's state
3. add overlay
In response to Skysaw
Thanks again! But it just clears out the overlay all by itself. It goes from full to blank (the 0 icon_state).

mob/proc/SetHealthIconState()
HealthBar.icon_state = "[round(health/max_health)*10]"

I tried puting in usr, but still no luck. Sorry for bugging