ID:165510
 
Awile ago I tried to do this, and after posting on the forums and still not being able to figure it out I took a huge break.
I have no idea where to start, or even what I need to look at doing. So far I after the person logs in and chooses their new game character it adds the health and mp bar as an overlay. I need the overlay due to the fact I want the user to be able to move with the mouse(Had to switch around the naming system in my game so it would always follow player without any lag). Here is my code for the above:
                world<<"<font color=green><b><u>[usr.key]:</font></u><b>decided to be a [a]!</b>"
usr.overlays+=new/obj/meter/healthbar
usr.overlays+=new/obj/meter/manabar
usr.Name()

Someone please help...... Until I get the GUI finished I can't convince myself to go on with anything else.
If your HP and MP bars are already added as overlays, there's no way to update them on the fly. The only way you can do this effectively is to put your update proc in charge of adding them and removing them again.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
If your HP and MP bars are already added as overlays, there's no way to update them on the fly. The only way you can do this effectively is to put your update proc in charge of adding them and removing them again.

Lummox JR
How would I go about this? As I said above, I have no clue how to do this except getting the proc to start, telling it to add the overlay, and subtract the overlay.
In response to FriesOfDoom
Just make an update proc, and every time stats change call it.
In response to Xx Dark Wizard xX
Xx Dark Wizard xX wrote:
Just make an update proc, and every time stats change call it.

The thing is, is that I have 28 or so diffrent health bar states to represent diffrent precentages. What do I need to do so that the compiler looks at the user's health and then chooses the right healthbar state to represent the user's health?
Or is there an easier and or better way?
In response to FriesOfDoom
look up num2text. like icon = "[num2text(round(src.hp/10),1)]". Thats sorta how I represent my hud in my game.
In response to Xx Dark Wizard xX
The help file in DM didnt help much.... but here is my code so far
                world<<"<font color=green><b><u>[usr.key]:</font></u><b>decided to be a [a]!</b>"
usr.overlays+=new/obj/meter/healthbar
usr.overlays+=new/obj/meter/manabar
usr.meterupdate()
usr.Name()
obj

var/width
meter
healthbar
name="HP"
icon='bars.dmi'
icon_state="1"
pixel_y=27
layer=MOB_LAYER+10
manabar
name="MP"
icon='bars2.dmi'
icon_state="1"
pixel_y=22
layer=MOB_LAYER+10

mob
proc/meterupdate(obj/meter/healthbar/h in src.overlays)
h.icon_state="[num2text(round(src.HP/src.MAXHP))]"
usr.overlays+=new/obj/meter/healthbar

The above does nothing..... It should display the 10th health bar state, which brings me to ask how would I make it so the 28th bar would display the user's health at their max hp point? Wouldn't I need to divide the current health by the max health or vise versa?

also this error shows up in game:
<font color=red>runtime error: Cannot modify null.icon_state.
proc name: meterupdate (/mob/proc/meterupdate)
usr: FriesOfDoom the Skeleton (/mob/player)
src: FriesOfDoom the Skeleton (/mob/player)
call stack:
FriesOfDoom the Skeleton (/mob/player): meterupdate(null)
New Game (/obj/menu/newgame): newmonster()
New Game (/obj/menu/newgame): Click( (15,8,1) (/turf/outside/grass))</font>
In response to FriesOfDoom
FriesOfDoom wrote:
    
> mob
> proc/meterupdate(obj/meter/healthbar/h in src.overlays)
> h.icon_state="[num2text(round(src.HP/src.MAXHP))]"
> usr.overlays+=new/obj/meter/healthbar
>

The above does nothing..... It should display the 10th health bar state, which brings me to ask how would I make it so the 28th bar would display the user's health at their max hp point? Wouldn't I need to divide the current health by the max health or vise versa?

also this error shows up in game

I suggest you go read some DM tutorials and the DM Guide. You can't just specify an object like that as a proc's argument, look up arguments...the proc is called with them to pass data/info to it, but you're trying to make the proc get the data alone...in the arguments place. That would make sense more in a for() loop in the actual procedure.
Also, Lummox said you CAN'T modify overlays on the fly; you have to remove the overlay and re-add a modified one, so even if you did the above correctly it wouldn't work.
After reading some DM resources, as recommended above, rewrite that proc. Just remove the overlay, then add a new image with the right state.
In response to Kaioken
Kaioken wrote:
I suggest you go read some DM tutorials and the DM Guide. You can't just specify an object like that as a proc's argument, look up arguments...the proc is called with them to pass data/info to it, but you're trying to make the proc get the data alone...in the arguments place. That would make sense more in a for() loop in the actual procedure.
Also, Lummox said you CAN'T modify overlays on the fly; you have to remove the overlay and re-add a modified one, so even if you did the above correctly it wouldn't work.
After reading some DM resources, as recommended above, rewrite that proc. Just remove the overlay, then add a new image with the right state.

I read a couple DM tutorials.....and I didn't understand them and/or couldn't get them to work thats why I posted here. Also, I had the above with a for() proc before instead of it in the proc arguments, but it didn't work either. I thought Lummox ment that you would have to do it in a proc when he said "you can't modify overlays on the fly". But I'll look up arguments again. Thanks for the help :D
In response to FriesOfDoom
mob
proc/meterupdate()
world<<"blah"
for(var/obj/meter/healthbar/h)
h.icon_state="[num2text(round(src.MAXHP/src.HP))]"
src.overlays+=new/obj/meter/healthbar

still cant get the thing to work.....
Could someone show me a simple example, would be nice to know what I need to do exactly as I said before!
In response to FriesOfDoom
OK. Lummox told you, I repeated it. We said that won't work. I see why you're having trouble with tutorials, you're having trouble reading. :P
You can't modify overlays. You must remove them, then add a new, modified overlay back in.
Also, even if you could, your for() loop would default to loop threw all those object types in the world; not in the overlays.

FiresOfDoom wrote:
"I thought Lummox ment that you would have to do it in a proc when he said "you can't modify overlays on the fly"

Where the heck is the sense in that? Why would he mean something entirely different than what he wrote? He never even said "proc".
In addition, other than compile-time setting/defining, ALL code is in procs (verbs are procs as well)...