Code:
mob
proc
deathcheck()
if(src.hp<=0)
for(var/obj/O as obj in src.overlays)
if(O.name=="Health")
var/obj/S=new/obj/screen/hpbar
S.icon_state="hpbar_100"
src.overlays-=O
src.overlays+=S
world<<"<font color = red>[src.name] has been slain!"
src.loc=locate(0,0,0)
spawn(50)
src.loc=locate(1,1,1)
src.hp=src.maxhp
for(var/obj/L as obj in src.overlays)
if(L.name=="Health")
var/obj/S=new/obj/screen/hpbar
L.icon_state="hpbar_full"
src.overlays-=L
src.overlays+=S
else
if(src.hp % src.maxhp >= 0.8)
if(src.hp % src.maxhp <= 0.9)
for(var/obj/O as obj in src.overlays)
if(O.name=="Health")
var/obj/S=new/obj/screen/hpbar
S.icon_state="hpbar_10"
src.overlays-=O
src.overlays+=S
if(src.hp % src.maxhp >= 0.7)
if(src.hp % src.maxhp <= 0.8)
for(var/obj/O as obj in src.overlays)
if(O.name=="Health")
var/obj/S=new/obj/screen/hpbar
S.icon_state="hpbar_20"
src.overlays-=O
src.overlays+=S
if(src.hp % src.maxhp >= 0.6)
if(src.hp % src.maxhp <= 0.7)
for(var/obj/O as obj in src.overlays)
if(O.name=="Health")
var/obj/S=new/obj/screen/hpbar
S.icon_state="hpbar_30"
src.overlays-=O
src.overlays+=S
if(src.hp % src.maxhp >= 0.5)
if(src.hp % src.maxhp <= 0.6)
for(var/obj/O as obj in src.overlays)
if(O.name=="Health")
var/obj/S=new/obj/screen/hpbar
S.icon_state="hpbar_40"
src.overlays-=O
src.overlays+=S
if(src.hp % src.maxhp >= 0.4)
if(src.hp % src.maxhp <= 0.5)
for(var/obj/O as obj in src.overlays)
if(O.name=="Health")
var/obj/S=new/obj/screen/hpbar
S.icon_state="hpbar_50"
src.overlays-=O
src.overlays+=S
if(src.hp % src.maxhp >= 0.3)
if(src.hp % src.maxhp <= 0.4)
for(var/obj/O as obj in src.overlays)
if(O.name=="Health")
var/obj/S=new/obj/screen/hpbar
S.icon_state="hpbar_60"
src.overlays-=O
src.overlays+=S
if(src.hp % src.maxhp >= 0.2)
if(src.hp % src.maxhp <= 0.3)
for(var/obj/O as obj in src.overlays)
if(O.name=="Health")
var/obj/S=new/obj/screen/hpbar
S.icon_state="hpbar_70"
src.overlays-=O
src.overlays+=S
if(src.hp % src.maxhp >= 0.1)
if(src.hp % src.maxhp <= 0.2)
for(var/obj/O as obj in src.overlays)
if(O.name=="Health")
var/obj/S=new/obj/screen/hpbar
S.icon_state="hpbar_80"
src.overlays-=O
src.overlays+=S
if(src.hp % src.maxhp <= 0.1)
for(var/obj/O as obj in src.overlays)
if(O.name=="Health")
var/obj/S=new/obj/screen/hpbar
S.icon_state="hpbar_90"
src.overlays-=O
src.overlays+=S
Problem description: Thanks in advance for any help.
What you want is actual division (/).
Also, if you set those up in an if() ... else if() ... chain, you don't need to check that their hp is both above and below a certain percent.
That said, the best way to do this is to dynamically determine the icon_state, instead of using if()'s at all:
If you're interested, I have a library that will handle all of this for you: Stat Bar Overlays