ID:951468
 
(See the best response by DvK87.)
obj
heal
icon = 'heal.dmi'
verb
Take()
set src in view(1)
if(usr.maxhp - usr.hp >= 10)
usr.hp += 10
del(src)
if(usr.mhp - usr.hp <= 9)
usr.hp += (usr.maxhp - usr.hp)
del(src)


I made it so when an enemy is killed a health globe drops. I am able to make it so that hp can be restored when the heal is picked up, but i'm having trouble making it so that if the player has max hp or under 10 hp missing (the heal heals for 10) it doesn't make the player's hp higher than the max hp. The problem I encounter is when the character has more than 10 hp missing it works fine, but when he has 9 or less hp missing the heal does nothing.

Best response
obj
heal
icon = 'heal.dmi'
verb
Take()
set src in view(1)
if(usr.maxhp - usr.hp >= 10)
usr.hp += 10
else
usr.hp =usr.maxhp
del(src)


Two situations exist, your hp is depleted by more than 10 or it damaged by less than 10. In the else case, simply set hp to the max hp and problem solved.

Your main issue was that you were deleting SRC before the second if statement came up. Do not del(src) until the very end of the verb usage.
Thanks, that solved it! Now I realized that it would be best to just be able to pick up and get the hp automatically by walking over it instead of having to click and use it. Would there be a simple way to do that?
In response to Mackonthemoon
Look up bump().
Just found it and got it to work. Thanks for the tip!
In response to A.T.H.K
For non-dense objects, it makes more sense to use Crossed. I'm pretty sure it works without pixel movement, even though it was added in that update.

Also, a quick shortcut to avoid using two if statements is to use the min() proc.
health = min(health + 10, max_health)

health will never be above max_health.