ID:1701638
 
(See the best response by Kaiochao.)
Code:


Problem description:

How can i create a life bar that will updata each time when hp change?
I remember answering this same question for you back in August here. I take it you didn't understand the resources back then, or did you read them at all?
It wont updata that why i ask again
It's pretty straightforward. Whenever HP changes (you should know when this happens), update the life bar (you should know how to do this).
create some screen objects update the screen objects when you update your hp.

solved();
In response to Kaiochao
Kaiochao wrote:
It's pretty straightforward. Whenever HP changes (you should know when this happens), update the life bar (you should know how to do this).

Not really
In response to Gokussj99
Gokussj99 wrote:
create some screen objects update the screen objects when you update your hp.

solved();

Not on screen i want it to be over base icon.
In response to MegaMan999
Best response
There are a few ways to do this. What will you be using as the graphic for the health bar? An icon with a bunch of icon states? Or a rectangle for current health over another rectangle for maximum health? Or something else?

Either way, the question you asked requires some assumptions; that you have a property "health" that causes something to happen when it changes.
mob/whatever
var health, max_health

proc
// You should use this wherever you want to change health.
// You shouldn't set health directly anywhere else,
// unless you don't want the health bar to update.
// You should never be writing:
// health = x, or
// health += x, or
// health -= x
// in any other proc.
SetHealth(Health)
// Set the health variable to the new value.
health = Health

// Call side-effect(s) of changing the health variable.
UpdateHealthBar()

UpdateHealthBar()
// update the health bar.
// What gets written here depends entirely on what YOU want it to do.
// (this goes for literally everything else in your game, too)
mob/var
tmp
Hpbar

mob
proc
createbar()
var/obj/C=new/obj/HUD/bars()
C.pixel_y=M.yoffset+7
usr.bars=C
usr.overlays+=C
update_HUD()
var/A=round((hp/max_hp*10),1)
Login()
health_bar = new(src, 'HealthBar.dmi',15, "health", "health_max", pixel_y =14)//or
src.createbar()

Stat()
stat("Health: [src.health]/[src.health_max] ([round(100*src.health/src.health_max)]%)")

//This is what i did
//Tried this next
mob/var
health= 50
health_max= 100
tmp
Hpbar

mob
proc
updateHealth()
var/percent=round(src.health/src.max_health*100,10)
if(percent>100) percent=100
if(percent<0) percent=0

Login()
health_bar = new(src, 'HealthBar.dmi',15, "health", "health_max", pixel_y =14)


Stat()
stat("Health: [src.health]/[src.health_max] ([round(100*src.health/src.health_max)]%)")