ID:139449
 
Code:
mob
var
hp = 100
maxhp = 100
percent = (src.hp/src.maxhp)*100


obj
Bar1
icon='Huds.dmi'
icon_state="bar hud 1"
New(client/C)
screen_loc = "1,10"
C.screen+=src
if (usr.percent <= 29 && usr.percent >= 25) icon_state="bar hud19"
else if (usr.percent <= 24 && usr.percent >= 20) icon_state="bar hud20"
else if (usr.percent <= 19 && usr.percent >= 15) icon_state="bar hud21"
else if (usr.percent <= 14 && usr.percent >= 10) icon_state="bar hud22"
else if (usr.percent <= 9 && usr.percent >= 5) icon_state="bar hud23"
else if (usr.percent <= 5 && usr.percent >= 1) icon_state="bar hud24"

Bar2
icon='Huds.dmi'
icon_state="bar hud 2"
New(client/C)
screen_loc = "2,10"
C.screen+=src
if (usr.percent <= 64 && usr.percent >= 60) icon_state="bar hud12(2)"
else if (usr.percent <= 59 && usr.percent >= 55) icon_state="bar hud13"
else if (usr.percent <= 54 && usr.percent >= 50) icon_state="bar hud14"
else if (usr.percent <= 49 && usr.percent >= 45) icon_state="bar hud15"
else if (usr.percent <= 44 && usr.percent >= 40) icon_state="bar hud16"
else if (usr.percent <= 39 && usr.percent >= 35) icon_state="bar hud17"
else if (usr.percent <= 34 && usr.percent >= 30) icon_state="bar hud18"

Bar3
icon='Huds.dmi'
icon_state="bar hud 3"
New(client/C)
screen_loc = "3,10"
C.screen+=src
if (usr.percent <= 94 && usr.percent >= 90) icon_state="bar hud6"
else if (usr.percent <= 89 && usr.percent >= 85) icon_state="bar hud7"
else if (usr.percent <= 84 && usr.percent >= 80) icon_state="bar hud8"
else if (usr.percent <= 79 && usr.percent >= 75) icon_state="bar hud9"
else if (usr.percent <= 74 && usr.percent >= 70) icon_state="bar hud10"
else if (usr.percent <= 69 && usr.percent >= 65) icon_state="bar hud11"
else if (usr.percent <= 64 && usr.percent >= 60) icon_state="bar hud12"

Bar4
icon='Huds.dmi'
icon_state="bar hud 4"
New(client/C)
screen_loc = "4,10"
C.screen+=src
if (usr.percent <= 100 && usr.percent >= 95) icon_state="bar hud5"


Problem description:
I am making hp bar
My problem here is that it gives error:
Battle.dm:47:error: hp/maxhp: undefined var
Battle.dm:47:error: =: expected a constant expression
it gives those from that "percent = (src.hp/src.maxhp)*100"
You have to provide a snippet to the code that the error points to.
In response to Darker Legends
what kinda snippet? ive tried modifying alot that place what error points but none worked (and i am just starring with code starred just 3 days ago)
You cannot define one variable to be a function of other, non-constant variables. If you want the percent variable to always equal the percentage of maximum health your current health is at, you need to update it every time maximum or current health changes.
Niko can we talk ?
1. those health bars will only update once(upon creation).
2 you cannot define a variable as a sum with changing numbers(it doesn't work, you try calculating something if the numbers keep changing.
3. the way you are assigning the icon_states is just silly, you've typed the same thing over and over again.

My advice here use, a library :D.

Alternatively, add an extra bit to the bar path called HUDbars. create a separate dmi for each bar e.g. Bar3.dmi,Bar4.dmi. Then give each icon state a number based on a percentage e.g. 10, 20 ... 90, 100. Then remove all the code under C.screen += src in the bars. and make a proc called update_bars(). It should end up something like this.
mob/var/list/Bars = list()

obj/HUDbars
Bar1
icon = 'bar1.dmi'
layer = 50
New(client/C)
screen_loc = "1,10"
C.screen += src

mob/proc
update_bars()
client/C = src.client
var/percent = round((src.hp/src.maxhp)*100)
for(var/I in C.screen)
if(I in src.Bars)
I.icon_state = percent

Stat()//this will be a VERY simple way of continually looping it but only for a client.
src.update_bars()
..()

Okay I added a bit extra and it's a bit basic but form what I see it'll work better.
You might want to look at the HUD Groups library. It comes with a demo showing how to create health meters that you can easily hide, show, move around, and update.