ID:148043
 
mob
proc
deathcheck(var/obj/monsters/M)
if(M.hp<=0)
src.textborders(1,1,13,5)
src.textletters(1.5,13,5,5,"[M.name] has been")
src.textletters(1.5,13,4.5,4.5,"defeated! You gained")
src.textletters(1.5,13,4,4,"[M.exp] experience points")
src.textletters(1.5,13,3.5,3.5,"and earned [M.goldp] gold")
src.textletters(1.5,13,3,3,"pieces!")
src.exp+=M.exp
src.gold+=M.goldp
del(M)
if(src.exp>=src.exptolevel)
checklevel()
else if(src.hp<=0)
src.gold-=round(src.gold/2)
src.textborders(1,1,13,5)
src.textletters(1.5,13,5,5,"You have been defeated")
src.textletters(1.5,13,4.5,4.5,"by [M.name]!")
sleep(src.inbattlesleep)
src.textletters(1.5,13,3.5,3.5,"You lose half of")
src.textletters(1.5,13,3,3,"your gold.")
src.endingbattle()
del(M)
src.loc=locate(1,1,1)
src.endingbattle()
checklevel(mob/M as mob)
levelup(M)
levelup(mob/M as mob)
if (knight == 1)
var/hpgain=rand(6,12)
var/mpgain=rand(3,7)
var/strgain=rand(1,4)
var/defgain=rand(1,4)
if (level == 1)
usr.spells += new/obj/Blaze
src.spells +=1
src.level+=1
src.str+=strgain
src.def+=defgain
src.hp+=hpgain
src.mp+=mpgain
src.maxhp+=hpgain
src.maxmp+=mpgain
src.exp=0
src.exptolevel=100
sleep(src.inbattlesleep)
src.textletters(1.5,13,2,2,"You have gained a")
src.textletters(1.5,13,1.5,1.5,"level!")
sleep(src.inbattlesleep)
closetext()
src.textborders(1,1,13,5)
src.textletters(1.5,13,5,5,"Your stats rose up!")
sleep(src.inbattlesleep)
src.textletters(1.5,13,4,4,"+[hpgain] HP")
src.textletters(1.5,13,3.5,3.5,"+[mpgain] MP")
src.textletters(1.5,13,3,3,"+[strgain] Strength")
src.textletters(1.5,13,2.5,2.5,"+[defgain] Defense")
src.textletters(1.5,13,2,2,"You learnt Blaze.")
src.endingbattle()
src.loc=locate(src.oldx,src.oldy,src.oldz)
if (level == 2)
src.level+=1
src.str+=strgain
src.def+=defgain
src.hp+=hpgain
src.mp+=mpgain
src.maxhp+=hpgain
src.maxmp+=mpgain
src.exp=0
src.exptolevel=200
sleep(src.inbattlesleep)
src.textletters(1.5,13,2,2,"You have gained a")
src.textletters(1.5,13,1.5,1.5,"level!")
sleep(src.inbattlesleep)
closetext()
src.textborders(1,1,13,5)
src.textletters(1.5,13,5,5,"Your stats rose up!")
sleep(src.inbattlesleep)
src.textletters(1.5,13,4,4,"+[hpgain] HP")
src.textletters(1.5,13,3.5,3.5,"+[mpgain] MP")
src.textletters(1.5,13,3,3,"+[strgain] Strength")
src.textletters(1.5,13,2.5,2.5,"+[defgain] Defense")
src.endingbattle()
src.loc=locate(src.oldx,src.oldy,src.oldz)
if (level == 3)
src.level+=1
src.str+=strgain
src.def+=defgain
src.hp+=hpgain
src.mp+=mpgain
src.maxhp+=hpgain
src.maxmp+=mpgain
src.exp=0
src.exptolevel=300
sleep(src.inbattlesleep)
src.textletters(1.5,13,2,2,"You have gained a")
src.textletters(1.5,13,1.5,1.5,"level!")
sleep(src.inbattlesleep)
closetext()
src.textborders(1,1,13,5)
src.textletters(1.5,13,5,5,"Your stats rose up!")
sleep(src.inbattlesleep)
src.textletters(1.5,13,4,4,"+[hpgain] HP")
src.textletters(1.5,13,3.5,3.5,"+[mpgain] MP")
src.textletters(1.5,13,3,3,"+[strgain] Strength")
src.textletters(1.5,13,2.5,2.5,"+[defgain] Defense")
src.endingbattle()

This is the code to my leveling up proc now i wnat it to be able to add spells so i was gonna make every level for every class seperatly.. The only problem is that whenever i level i sees hes level 2 so elkvels again then hes level 3 so it levels again and it really messes up.Any help would be appreciated.
Cloud54367
You've done your deathcheck backwards. In a deathcheck() proc, src should be the mob who may or may not have died, and the argument you pass (in this case M) should be the thing that attacked it.

In levelup(), you've got code to handle the end of the battle. By no means should you put it there. It shouldn't be in deathcheck() either; it should be in the proc that calls deathcheck() instead.

Also in levelup(), there's a great deal of repeated code in the various if() blocks. Not a good idea. Take everything out of those ifs, and do this sort of thing afterwards:
mob
var/list/class_leveling // a list of skills to gain
var/list/skills

proc/levelup()
... // other stuff here
for(var/S in class_leveling)
if(level < class_leveling[S]) continue
if(!skills) skills = new
if(S in skills) continue
skills += S
src << "You learn <b>[S]</b>!"

Lummox JR
In response to Lummox JR
Thres a few problems with your advice.One the ending battle sequence has to be in the level up proc because you supposed to be in battle when you see it. Also i dont understand when you say use M as the monster and src as the mob deathcheck(var/obj/monsters/M) I ahve it like that as u can see monsters/M I dont see the prob and then we come down to wut the problem was in the first place its leveling over again once its already leveled and out of battle anf getting a nasty bug
In response to Cloud54367
*B*U*M*P