ID:263880
 
Code:
proc
Update(mob/M)
var/icon_state_num = round(M.hp/M.maxhp)*M.maxhp
if(M.hp < M.maxhp/10&&M.hp != 0)
icon_state_num = 1
icon_state = num2text(icon_state_num)
spawn(2)Update(M)


Problem description:
I've checked what should happen with a calculator, and it should work properly. But for some reason, it doesn't.

When the user's HP is full, the HP bar is also full. But when the user's HP is any other number, the bar shows it as 0 HP.

What am I doing wrong?
proc
Update(mob/M)
var/icon_state_num = round(M.hp/M.maxhp *100)
if(M.hp < M.maxhp/10&&M.hp != 0)
icon_state_num = 1
icon_state = num2text(icon_state_num)
spawn(2)Update(M)


try that o.o
In response to Pirata Inmortal
Pirata Inmortal wrote:
proc
Update(mob/M)
var/icon_state_num = round(M.hp/M.maxhp *100)
if(M.hp < M.maxhp/10&&M.hp != 0)
icon_state_num = 1
icon_state = num2text(icon_state_num)
spawn(2)Update(M)


try that o.o

That doesn't work either.
I actually tried that exact coding earlier.
When I use that coding, and my HP is any number that is NOT a multiple of 10 (91, for example), the icon state doesn't even show up.
In response to The_Jaxx
u should do this

if(blah blah>90&&blah blah<99)
blahblha.icon_state="90" /for example/


...:::Pirata Inmortal:::...
In response to The_Jaxx
You need to round it to the nearest 10:

var/icon_state_num = round(hp/maxhp*100,10)


Also: you're mixing M and src. You should use one or the other (probably src, as this is a mob verb).

Also: You don't need to call this proc five times every second. Just call it once whenever hp changes.
In response to Pirata Inmortal
No, you really really shouldn't.
In response to Garthor
but y?? cuz it works for me i use that code for my bleach game(non rip) o.o
In response to Garthor
Garthor wrote:
You need to round it to the nearest 10:

var/icon_state_num = round(hp/maxhp*100,10)

Also: you're mixing M and src. You should use one or the other (probably src, as this is a mob verb).

Also: You don't need to call this proc five times every second. Just call it once whenever hp changes.

It works perfectly! Thanks!
In response to Pirata Inmortal
For the same reason Move doesn't work like:

if(x==1 && y==1 && z==1 && dir==NORTH)
loc = locate(1,2,1)
else if(x==2 && y==1 && z==1 && dir==NORTH)
loc = locate(2,2,1)
else if(x==3 && y==1 && z==1 && dir==NORTH)
loc = locate(3,2,1)
//and so on...
In response to Pirata Inmortal
There are multiple ways to accomplish things, however, sometimes it's best to stick with the most efficient one.
In response to Iuss
Not sometimes. All the time.