ID:179630
 
Ok, I have a have a problem with my healing spell, it works fine, everything is great, and even if you have max, it wont let you have any, but the problem is, when I have lets say 1 HP missing, it will add the full ammount (10), so the HP goes 9 over the max. Here is my code, can you help me out?


mob/proc/Heal(mob/M as mob in view(1))
set category = "Spells"
if(usr.MP<=15)
usr<<"You don't have enough MP"
if(usr.HP>=MaxHP)
usr.HP+=0
usr.MP-=0
usr<<"Game Info: Your HP is max!"
else
usr<<"You summon your power...."
usr.overlays+=/obj/overlays/HealStart
sleep(50)
usr.overlays-=/obj/overlays/HealStart
sleep(1)
usr.HP+=50
usr.MP-=10

After you add the health, whats there to stop it from going over the top? Your checking before if it goes over is good, but it doesnt do anything if it can still pass over once it adds the health.

I suggest adding a general proc to handle things like this, and just call it on the numbers you need to update, mayby like this:

proc/Update(num1,num2)
if(!num2) // In this case, you want to check for max
if(num1>max) num1=max // íf its over max, make it equal to max. max is up to you to determine
if(num1<0) num1=0 // if its under 0, set it equal to 0
if(num1>num2) num1=num2 // if you insert two numbers, your making sure that num1 isnt over num2


You could call it like this
mob/verb/Heal()
src.hp += 10
Update(src.hp,src.max_hp) // for one example
src.mana -= 10
Update(src.mana) // If you only give it one number, it checks to make sure if its under 0


Hope that helps
Alathon
Ok, I have a have a problem with my healing spell, it works fine, everything is great, and even if you have max, it wont let you have any, but the problem is, when I have lets say 1 HP missing, it will add the full ammount (10), so the HP goes 9 over the max. Here is my code, can you help me out?


mob/proc/Heal(mob/M as mob in view(1))
set category = "Spells"
if(usr.MP<=15)
usr<<"You don't have enough MP"
if(usr.HP>=MaxHP)
usr.HP+=0
usr.MP-=0
usr<<"Game Info: Your HP is max!"
else
usr<<"You summon your power...."
usr.overlays+=/obj/overlays/HealStart
sleep(50)
usr.overlays-=/obj/overlays/HealStart
sleep(1)
usr.HP+=50
usr.MP-=10
if(usr.hp>=usr.Maxhp)
usr.hp=usr.Maxhp
In response to Super16
o by the way the code isnt tested
In response to Super16
Hey, thanks alot Super16, that little bit of code worked great!

~KnightRen
In response to Super16
Super16 wrote:
if(usr.hp>=usr.Maxhp)
usr.hp=usr.Maxhp
Did you just copy whut I posted?