ID:173998
 
I've managed to get the hp bar to show up on the player. But I can't get the bar to update when the hp is altered.
Does anyone have any advice? I've looked through the DM guide and didn't find much, I also checked out some tutorials on overlays. Any help would be most appreciated. Thanks.
You need to remove the icon from the overlay list, make another overlay with the updated icon for the meter, then add that.
In response to Loduwijk
mob/player
icon='player.dmi'
icon_state="fighter"
var
hp
maxhp
strength
defence
exp
nextexp
lvl

obj
hpbar
icon='hpbar.dmi'
icon_state="(round(([hp]/[maxhp]*100)/4),1)"

I'm trying to define the object so I can use it as an overlay. I keep getting errors that hp and maxhp are undefined variables. What am I doing wrong?
In response to OmniSlashX4
There are 2 problems:
1)"hp" and "maxhp" are not defined for obj/hpbar
2) You can't set an icon_state using variables (needs to be a constant) you can however change it in New()

You can do something like:

obj
hb
icon='healthbar.dmi'
layer=MOB_LAYER+3
proc
update(mob/M,hp,mhp)//arguements for the proc (The owner of the Healthbar,the owners hp, the owners maxhp
var/V=(hp/mhp)
var/obj/hb/A=new
if(V>=1) A.icon_state="full"
else if(V>=0.75) A.icon_state="3/4"
else if(V>=0.50) A.icon_state="1/2"
else if(V>=0.25) A.icon_state="1/4"
else if(V<0.25) A.icon_state="low"
else if(V<=0) A.icon_state="empty"
M.overlays-=M.healthbar//get rid of current healthbar
M.healthbar=A//make healthbar=new healthbar
M.overlays+=M.healthbar//Add the healthbar to the overlays

mob
var/obj/hb/healthbar
player//whatever your player is
Login()
..()
src.healthbar=new/obj/hb//make a new health bar
src.healthbar.update(src,src.HP,src.Max_HP)//update it
src.overlays+=src.healthbar//add it to overlays
Logout()
..()
src.overlays-=src.healthbar
Del()
..()
src.overlays-=src.healthbar


This assumes you only want it to be on players, and that you have the icon_state's a certain name. You could also do it as A.icon_state="[number]" to save the trouble of the special names for it (It was taken from a game I'm working on in which I figured it would be easier to do It like this). You also in this case need to call healthbar.update() (with arguements) everytime there is a change in hp. However it would not be hard to turn it into a loop if you would prefer to do it that way.
In response to Nick231
Thank you, that seems to work, I'm just having a little trouble calling the proc. When I input the args what am I supposed to be inputing?

"call healthbar.update() (with arguements)"<<

What I'm asking is what are the arguments I'm supposed to be inputting in there. Thanks

In response to OmniSlashX4
You would do something like:

src.healthbar.update(src,src.hp,src.maxhp

src just needs to be switched to whatever you are updating the healthbar of (Might be usr, or someother variable ie. if M.hp-=damage takes health from the player in a proc, then you would switch src with M).
In response to Nick231
Ok THANKS! That worked phew. I'm such a newb lol. Thanks for helpin out.
In response to OmniSlashX4
you are declaring the maxhp/hp variables as OBJ variables.

you declared mob/variables up top but when you're using a procedure for an obj it uses obj variables, try to be more specific...