ID:138977
 
Normally, I would fix this myself... but I have to go soon, and my grandparents will be here any minute. :) Could anyone explain to me why the HP Bar doesn't go down(visually), it just stays full? I think it simply doesn't get to the part where it changes the overlays around. I added an input to the usr, and it never showed.

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.

I don't think you understand what the modulus operator (%) does. It returns the remainder of A divided by B. In your case, assuming hp is never greater than maxhp, it'll always return the same value as hp.

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:

S.icon_state="hpbar_[round(10*src.hp/src.maxhp,1)]0"


If you're interested, I have a library that will handle all of this for you: Stat Bar Overlays
I don't have time to go through all that nonsense. But if you want it would be easier to use an interface Bar.

winset(src,"default.bar","value=[round(hp,mhp * 100)]")


Umm not to sure about that math to get the percent of two values. Just doing it quick to help ya out.