ID:1709519
 
(See the best response by PolskiPolakPL.)
Code:
mob/var
tmp/updatehp()
obj/bars
lifebar
icon='healthbar.dmi'
icon_state="100"
layer=50


var/obj/bars/lifebar/A = new


mob/proc/updatehp()
var/percentbar=round(src.Health/src.MaxHealth*30,1)
if(percentbar>30) percentbar=30
if(percentbar<0) percentbar=0
src.overlays -= /obj/bars/lifebar
A.icon_state=num2text(percentbar)
src.overlays+= A
sleep(1)
src.overlays-= A
src.updatehp()


Problem description:

How make lifebbar change without mob attacking npc?
Best response
I think no one understand your question. But if you need manual change npc HP with update huds, You need make a new proc.
mob/proc/TakeDamage2(var/mob/M,var/Damage)
src.HP-=Damage//attacked mob lost some HP
src<<"[M] attack you with [Damage] Damage!"
M.updatehp()



mob/verb/HurtSomeOne(var/mob/M in world)
M.TakeDamage2(src,10)
You're doing a lot of things wrong.

1. You're defining a procedure as a variable.
2. You're defining lifebar as a global object.
3. You're calculating a percent of 2 variables wrongly.
4. You're looping wrongly try looking up while() and for().

I prob missed something but I'm starting a game of strife.
gokussj99 show me how you would do this.
In response to MegaMan999
MegaMan999 wrote:
gokussj99 show me how you would do this.

I didn't mean to come off that way but maybe when o get home coding from a phone is bothersim.

And also for performance sake it would be wiser to only update objects such as life bars etc only when needed so for example you could make a procedure that alters your HP and then update the objects after from what I can see it seems like you're constantly calling the same procedure over and over in the same procedure which can cause a lot of issues because I don't think the previous procedure ever ends.
In response to MegaMan999
My stupid phone.