My healing potion code:
obj/items
Healingpotion
icon = 'items.dmi'
icon_state = "healingpotion"
Click()
if(src in usr)
usr.HP += 100
del(src)
What should i add so my HP doesnt go over my MAXHP ?
THX.
ID:179650
![]() Nov 24 2001, 11:25 am
|
|
OK, i've modified it a bit:
obj/items Healingpotion icon = 'items.dmi' icon_state = "healingpotion" Click() if(src in usr) if (usr.hp = usr.maxhp) usr<<"You don't need it yet!" return 0 else usr.hp += 100 if (usr.hp >= usr.maxhp) usr.hp = usr.maxhp usr<<"Some HP recovered !" del(src) After compiling, it says "missing expression" at the first "if". Any ideas ? Should i change something here ? THX. |
As an alternative to the code you were given, instead of using three lines of code, you can use the convenient min() function:
usr.HP=min(usr.HP+100,usr.maxHP) That says the user's new HP is either 100 higher than it was, or as high as it can go, whichever comes first. Lummox JR |
usr.HP = MaxHP