ID:156658
 
how do u add bars to npc's and make it update? ive gone threw every lib there is and even written my own version of it ?

i can get it to show the hp bar above the character and npc's but it just wont trigger the icon_state shifting to match the current hp? is there any other way to add hp bars to npc's like maybe useing the skin interface? or something because regardless to what i do it just dosnt want to co-opperate

mob
proc
updateHealth()
var/percent=round(src.hp/src.maxhp*100,10)
if(percent>100) percent=100
if(percent<0) percent=0
for(var/obj/hudMeters/o in src)
o.icon_state=num2text(percent)

proc/add_hpbars()
usr.overlays += /obj/hudMeters/health_01
usr.overlays += /obj/hudMeters/health_02
src.updateHealth()

obj
hudMeters
health_01
icon='meter_01.dmi'
icon_state="0"
pixel_x=-16
pixel_y=40
health_02
icon='meter_02.dmi'
icon_state="0"
pixel_x=16
pixel_y=40

when the mob is hit it dose every other proc call there is like blood effect, damage numbers.. but for some reason this just wont fill the hp bar or reduce it

the game loads with the bar active but its also empty aswell even tho ive told the NPC's to trigger the update proc at spawning of all there outfits and weapons.

anyone have a clue whats going on here
You call updateHealth() health only once, make loop for it either call it manually
Yurgeta wrote:
how do u add bars to npc's and make it update? ive gone threw every lib there is and even written my own version of it ?

i can get it to show the hp bar above the character and npc's but it just wont trigger the icon_state shifting to match the current hp? is there any other way to add hp bars to npc's like maybe useing the skin interface? or something because regardless to what i do it just dosnt want to co-opperate

> mob
> proc
> updateHealth()
> var/percent=round(src.hp/src.maxhp*100,10)
> if(percent>100) percent=100
> if(percent<0) percent=0
> for(var/obj/hudMeters/o in src)
> o.icon_state=num2text(percent)
>
> proc/add_hpbars()
> usr.overlays += /obj/hudMeters/health_01
> usr.overlays += /obj/hudMeters/health_02
> src.updateHealth()
>
> obj
> hudMeters
> health_01
> icon='meter_01.dmi'
> icon_state="0"
> pixel_x=-16
> pixel_y=40
> health_02
> icon='meter_02.dmi'
> icon_state="0"
> pixel_x=16
> pixel_y=40
>

when the mob is hit it dose every other proc call there is like blood effect, damage numbers.. but for some reason this just wont fill the hp bar or reduce it

the game loads with the bar active but its also empty aswell even tho ive told the NPC's to trigger the update proc at spawning of all there outfits and weapons.

anyone have a clue whats going on here

@Ripiz A loop would when the mob is not being attacked or getting hurt would just be a waste of memory and cause excess lag when it is not needed.

As for the problem, you expect that overlays automatically update when they do not. What you need to do is 'replace' the current hud overlay with a remove and re-add method.

Also, your overlays are basically attaching the icon, and for you to manipulate it, you would need to have it create an image and make sure the old one removes.

It has been a while since I've programmed, but I believe this would work...

mob
proc
updateHealth()
var/percent=round(hp/maxhp*100,1)
if(percent>100) percent=100
if(percent<0) percent=0
overlays=list()
//What you need to do is update all your overlays by re-adding them so you can add the new set below... My prefered method to this is to make a different list with all the other overlays and do overlays+=P_Overlays or whever your list is called.
overlays += image('meter_01.dmi',icon_state="[percent]",pixel_x=-16,pixel_y=40)
overlays += image('meter_02.dmi',icon_state="[percent]",pixel_x=16,pixel_y=40)
..()


I'm not sure how well I was able to program it, but I believe this would work.
In response to Killer22
thanks killer, it works now, never thought about doing it like that lol now i know for future refeance, everything loads as expected and updates when hit, nice one