ID:1717906
 
(See the best response by Fushimi.)
Code:
obj/items/Bandages
icon='props.dmi'
icon_state="bandages"
name="Bandages"
verb/Use()
if(usr.Health<=99)
usr.Health+=25
del src
if(usr.Health==usr.MaxHealth)
del src
return
if(usr.Health==100)
usr<<"<font color=red><b><small>There's no point using that."


Problem description:
I'm taking out the ability to sleep to restore Health in my survival game. Makes it too easy, and instead making it so players can craft bandages that will restore health.

How do I stop them from going past 100 which is the MaxHealth? For example, I had 90 health and used a bandage and took me to about 115. I want it to stop at 100 which is the MaxHealth.

Hints, tips, etc?

Best response
obj/items/Bandages
icon='props.dmi'
icon_state="bandages"
name="Bandages"
verb/Use()
if(usr.Health<100)
usr.Health = min(usr.MaxHealth, (usr.Health + 25))
del src
else
usr<<"<font color=red><b><small>There's no point using that."


You would want to look into the min and max procedures.
In this case I used min(), which sets usr.Health to the minimum value given to the procedure.

In this case, if usr.Health +25 surpasses usr.MaxHealth, Health will be set to MaxHealth instead.
In response to Fushimi
Wow, such an easy fix.

Thanks mate.