ID:166701
 
Well, for some reason, I get HP in the negatives without dying [edit]and get more experience than the max without leveling up. (fixed)

mob
proc/level_up()
if(src.client)
if(src.exp >= src.maxexp)
src.stat_up()
src.level += 1
src <<"\red <b>You gained a Level!"
src.maxexp += rand(60,100)
src.exp = 0
proc/stat_up()
src.str += rand(2,5)
src.def += rand(2,5)
src.maxhp += rand(5,10)
src.hp = src.maxhp
proc/death_check(mob/M as mob,how_much as num)//handles death
if(src.hp <= 0)
if(src.monster == 1)
M <<"You killed [src]!"
var/obj/gold/G = new(src.loc)
G.amount = src.gold
M.exp += src.exp
if(src.client)
src <<"[M] killed you!"
src.loc = locate(3,1,2)
world <<"[src] was killed by [M]!"
src.hp = src.maxhp
M.level_up()
else
if(src.hp <= 0)
src <<"You have been killed by [M]!"
del(src)
else
if(src.client)
src <<"[M] killed you!"
src.loc = locate(3,1,2)
src.hp=src.maxhp
world <<"[src] was killed by [M]!"
M.level_up()
else
src <<"You have been killed by [M]!"
del(src)

verb/Attack(mob/M in oview(1))
var/damage = src.str - M.def
if(M.client)
M.hp -= damage
src <<"You attack [M] for [damage]!"
M <<"You are being attacked by [src] for [damage]!"
M.targetb = "[src.name]"
M.death_check(src)

else
M.hp -= damage
src <<"You attack [M] for [damage]!"
M <<"You are being attacked by [src] for [damage]!"
M.targetb = "[src.name]"
M.death_check(src)
Anyone!?!
In response to XxMalificentxX
1) Don't double post
2) Bump when your post atleast a day old and not on the first page
3) I see nothing wrong... maybe you are getting the -ve hp from something else... it is a wise idea to use generalized procs for damaging and stuff

- GhostAnime
In response to XxMalificentxX
I've read through your code, and I don't see exactly where the problem is comming from. However, I do see the design flaw that is at the heart of this problem: You're subtracting hp from the attacked mob in the attacker's attack verb. Because the attacked mob doesn't have control over it's own hp variable, it has no idea what's happening to it, and never knows when to die; it has to be told when to die. So, everywhere that the mobs hp is being lowered, you'll need to do the exact same checks to see if it has died, or if it's hp is above the max allowed, etc. Forget to update any one of these places, and your entire system fails. For an indepth discussion of this problem, and how to fix it, you should read Basic Combat System.

Basically, attack belongs to the attacker, hit belongs to the person being attacked (as does adjust_hp(), and die(); death_check() should be contained in adjust_hp()). Whenever you want to adjust a mob's hp, you should call mob.adjust_hp() so that the mob can respond correctly.
In response to IainPeregrine
Thanks everyone, but I fixed it...I added a M.deathcheck() somewhere and it worked o.O but now it says


XxMalificentxX has been killed by XxMalificentxX! and I dont know how to fix that >_>
In response to XxMalificentxX
In the deathproc, you can check if the killer was yourself >.>

world<<"[src] has [M==src ? "killed \himself" : "been killed by [M]"]!"


I also suggest that, if you didn't code that much of a battle system, to make a generalized proc for taking away HP >.>

If you do not know what '?' and ':' was used for, check this link out (near the middle)

- GhostAnime