ID:2480785
 
(See the best response by Flick.)
This is the code for the Bar itself
obj/maskbar
appearance_flags = KEEP_TOGETHER
mouse_opacity = 0
var
obj/foreground
obj/background
obj/fill
obj/mask

width = 0
height = 0
orientation = EAST

New()
Build()
vis_contents.Add(mask,foreground)
..()

Del()
//break relationships
vis_contents.Remove(mask,foreground)
background.vis_contents -= fill
mask.vis_contents -= background
..()
proc
Build()
//create constituent objects
foreground = new/obj/maskpart/fg(null,icon)
background = new/obj/maskpart/bg(null,icon)
fill = new/obj/maskpart/fill(null,icon)
mask = new/obj/maskpart/mask(null,icon)

//arrange constituent objects
background.vis_contents += fill
mask.vis_contents += background

setValue(ratio=1.0,duration=0)
//constrain the ratio between 0 and 1
ratio = min(max(ratio,0),1)

//apply orientation factors for fill bar offsets
var/fx = 0, fy = 0
switch(orientation)
if(EAST)
fx = -1
if(WEST)
fx = 1
if(SOUTH)
fy = 1
if(NORTH)
fy = -1

//calculate the offset of the fill bar.
var/invratio = 1-ratio
var/epx = width * invratio * fx
var/epy = height * invratio * fy

//apply the offset to the fill bar
if(duration)
//if a time value has been supplied, animate the transition from the current position
animate(fill,pixel_w=epx,pixel_z=epy,time=duration)
else
//if a time value has not been supplied, instantly set to the new position
fill.pixel_w = epx
fill.pixel_z = epy


obj/maskpart
layer = FLOAT_LAYER
plane = FLOAT_PLANE

bg
icon_state = "bg"
appearance_flags = KEEP_TOGETHER
blend_mode = BLEND_MULTIPLY
fg
icon_state = "fg"
fill
icon_state = "fill"
mask
icon_state = "mask"

New(loc,icon)
src.icon = icon
obj/maskbar/test
icon = 'HUD.dmi'
screen_loc = "CENTER:-81,CENTER"
width = 162
height = 5
orientation = EAST
client
proc
UpdateUI()
mob.bartest.setValue(mob.health,10)

and the current temporary login code
mob
Login()
world << "<b><font color=aqua><small>RAVEN BOT</small></b> </font>[src.key]([src.name]) logs in."
icon='player.dmi'
icon_state="The Girl With a Hat"
bound_x = -22
bound_y = -2
bound_height = 60
bound_width = 20
usr.character = "The Girl with a Hat"
src.loc = locate(1,1,1)
usr.health = 100
usr.stamina = 100
usr.shock = 0
step_size = 8
bartest = new/obj/maskbar/test()
client.screen.Add(bartest)
..()
Logout()
world << "<b><font color=navy><small>CROW BOT</small></b> </font>[src.key]([src.name]) logs out."
verb
TestDamage()
usr<<"You hurt yourself!"
health -= 10
client.UpdateUI()


As you can see i created a verb to deal 10 damage to the player (out of 100 maximum health) and created a proc to update the ui which is in the ui code right at the bottom.

Issue is when the player takes damage nothing happens until the player reaches 0 health.
Best response
It looks like bartest.setValue wants a ratio. Try sending it mob.health/mob.maxHealth
That did it, did not know you could us a ratio like that in dm.
Thank you very much!
Went to work; Thanks flick.
And thank you for the script to begin with ter!
Interesting issue i noticed today. when im on 20 health the bar is completely depleted. Trying to figure it out myself but if you might have any ideas, would appreciate it.

EDIT: NVM im a dunce and forgot to change the icon with settings