ID:1903956
 
(See the best response by Zagros5000.)
Code:
UpdHpb()
if(src.client)//
hpbar.icon_state="[min(max(round(Hp.val/Hp.max * x) * 10,0),100)]"


Problem description:
I can't seem to get it to work smoothly. This is the original, un modified code I was using. I have 50 states to my health bar, but it still seems to jump in much larger,less smooth increments.

Ideally I'd like the image to increment in 2% states.
Best response
hpbar.icon_state="[round(Hp.val/Hp.max*100,2)]"

should add a check to make sure icon state is still 100 if your hp goes above maximum for whatever reason
This is not going to be smooth in the way you describe if your maximum hp is below 100.

With a little work, you could have tween the shown value towards the actual HP value. I might write an example for you when I get out of bed.

[EDIT]: I am now out of bed.

This is more or less for giving you an idea on how to pull this off with icon states like you've described. If your health bar isn't just a resized rectangle, then using animate() with the transform parameter would probably be much better.

hpbar/var/shownValue //This is the currently shown value by this thing

mob/proc/UpdHpb()
if(src.client)
hpbar.shownValue += (Hp.val - hpbar.shownValue) * 0.75
hpbar.icon_state="[min(max(round(Hp.val/Hp.max * x) * 10,0),100)]"

The downside to this is you will have to constantly update the health bar every frame until it "reaches" the desired shown value. Whereas with animate(), you just call updhpb() only once, whenever the health changes.
If you want you hpbar to move smoothly you can animate it, instead of using so many icon states.
In response to D4RK3 54B3R
What Zagros5000 mentioned fixed all of my issues perfectly.
In response to Mar big
Example of this? I know I can do it. Was just unaware of how to do it.

I created the HP Bars I used with code so it only took 10-15 secs top.
In response to Avidanimefan
var
matrix/m = new
width = 100// this sould be the width of the icon
m.Translate(width/2,0)// set the left of the bar to the center
m.Scale(percent/100,1)// percent being the current health percent
m.Translate(-width/2,0)//reposition the bar
animate(hpbar,transform = m,time=5)
You can animate() through different icon_states with a for() loop:
var end = round(Hp.val / Hp.max * 100, 2)
var start = text2num(hpbar.icon_state)
var d = end - start
if(!d) return
var s = d / abs(d) * 2
animate(hpbar, icon_state = hpbar.icon_state, time = 0) // because animate(hpbar) doesn't work for some reason
for(var/n in start to end step s)
animate(icon_state = "[n]", time = world.tick_lag)
In response to Kaiochao
I'm a little curious as to how cpu intensive that would be in a game with a moderate playerbase?
In response to Zagros5000
Pretty sure animate was client-side mostly, so not very much.
Ok so if you put a transparent label over the bar with a bunch of I's or | you can get a cool retro looking megaman kind of bar for your game or try different letters for unique feel see what I did with I X and Z in the pic