ID:148196
 
Alright i got a code i can't seem to make. It's a Health Hud that shows your health :P, but i made one and you got to DoubleClick the HUD every time you get hit or want to see how much damage was inflicted. I want to know how to just let it refresh and not having to Double Click.

obj/Health
icon = 'HealthExp.dmi'
icon_state = "0"
layer = MOB_LAYER+100
DblClick()
usr<<"[usr.Health]/100"
if(usr.Health == 100)
icon_state = "1"
if(usr.Health ==95)
icon_state = "2"
if(usr.Health ==90)
icon_state = "4"
if(usr.Health ==85)
icon_state = "7"
if(usr.Health ==80)
icon_state = "8"
if(usr.Health ==75)
icon_state = "10"
if(usr.Health ==70)
icon_state = "15"
if(usr.Health ==65)
icon_state = "18"
if(usr.Health ==60)
icon_state = "20"
if(usr.Health ==55)
icon_state ="20"
if(usr.Health ==50)
icon_state = "21"
if(usr.Health ==45)
icon_state = "21"
if(usr.Health ==40)
icon_state = "22"
if(usr.Health ==35)
icon_state = "22"
if(usr.Health ==25)
icon_state = "23"
if(usr.Health ==20)
icon_state = "23"
if(usr.Health ==15)
icon_state = "27"
if(usr.Health ==10)
icon_state = "24"
if(usr.Health ==5)
icon_state = "25"
if(usr.Health ==0)
icon_state = "25"

New(client/C) screen_loc = "[world.view+1],[world.view+2]", C.screen+=src


Ack. That series of if() statements is friggin' awful. You really need to replace that with something better, like this:
obj/meter
proc/Update(value, maxvalue)
var/n = max(0,min(value,maxvalue))
icon_state="[round(n*metersize/maxvalue)]"
To get this to auto-update, you really just have to call the Update() proc any time the stat you're recording changes.

Lummox JR
I think you just need to create a Damage() proc that combines several functions, such as damaging the mob, checking to see if it died, and updating the health meter.

Oh, and I propose a better way of determining which state is needed for the health meter's current level of health, since using a bunch of if() checks is a really nasty way to do it. So, create a meter that has 33 states, from 0 to 32. Then have the state determine like this:

<code>round(32 / max_value * current_value)</code>

Where max_value is the max HP, and current_value is the player's current HP. The 32 is also the number of states (minus one) that the meter has.
In response to Lummox JR
what is this metersize var? explain to me what it's for
In response to JohnReaper
JohnReaper wrote:
what is this metersize var? explain to me what it's for

That's just filler I put in for the maximum number you can use for the icon state of the meter. In Spuzzum's snippet that works out to 30, but it might be less or more depending on the way you draw your meter icons.

Lummox JR
In response to Lummox JR
Can you give me the url to Spuzzums demo?
In response to JohnReaper
Look it up! Just go up to the top search box and type in "Spuzzum". =P

<font size=-3> =)</font>
put it in the stat() panel

fin

-Salarn