ID:1746222
 
Code:
mob/var
tmp/updatehp()

obj/bars
lifebar
icon='healthbar.dmi'
icon_state="30"
pixel_y=32
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(2)
src.updatehp()

while(src)
if(percentbar!=round(src.health/src.maxhealth*30,1))
percentbar=round(src.health/src.maxhealth*30,1)
if(percentbar>30)percentbar=30
if(percentbar<0) percentbar=0
A.icon_state=num2text(percentbar)
sleep(2)
mob/verb/Attack()
set category=null
if(src.canattack)
if(usr.wieldingsword)
flick("Sword Slash1",usr)
else
flick("punch",usr)
for(var/mob/M in get_step(usr,usr.dir))
var/damage=round(src.strength-src.defence)
if(damage>=0)
M.health-=damage
M.effectdamage(damage,"y")
M.updatehp()
if(M.enemy)
usr.hollowprotection=1
usr.canattack=1
return
usr.Death(M)
mob/login
spawn(-1) src.updatehp()//even when this is taken out it still happen.


Problem description:
Kinda still need to still need to add sleep on attack but the problem is when i attack an npc its talking about overlooping something thing then game crash.
That while loop has no breaking condition.
Isnt sleep the break?
I hope you realize that usr.Death(M) will NEVER be called, so your Attack() verb can't actually kill someone. I think I pointed this out in a different post of yours.

Also, removing it on Login() doesn't matter, because you call it in the Attack() verb anyway.

The issue is, in fact, your updatehp() proc.

The mere act of calling this proc crashes the game. Why? Having src.updatehp() in the proc itself means that it calls itself over and over and over, because each time it's called it makes another call, never ends, calls itself again, over and over. That's your crash.

Essentially, your updatehp() proc does this:

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(2)
src.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(2)
src.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(2)
src.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(2)
src.updatehp()


creating loops until the game crashes.

The easiest way to fix it is to NOT loop your updatehp(). Make the proc a one time update, and just call it whenever there SHOULD be a change, not every 2/10ths of a second regardless of whether there was a change or not.
but this doesnt show me the other part of the coding that when you get attack life bar will still update.