ID:139502
 
Code:
mob
proc
deathcheck()
if(src.hp<=0)
src<<"You have been killed."
src.loc=locate(50,50,1)
src.burning=0
src.overlays-=/obj/fire
src.hp=src.maxhp
view()<<"<font color = red>[usr.name] kills [src.name]!"
usr.kills+=1
src.deaths+=1
if(usr.lvl>src.lvl)
usr.xp+=src.lvl+5
usr.gold+=10
usr<<"You gain 10 gold."
usr.lvlcheck()
else
if(usr.lvl<src.lvl)
usr.xp+=src.lvl+15
usr.gold+=20
usr<<"You gain 20 gold."
usr.lvlcheck()
else
usr.xp+=src.lvl+10
usr.gold+=15
usr<<"You gain 15 gold."
usr.lvlcheck()
lvlcheck()
if(src.xp>=src.maxxp)
if(src.lvl<14)
src.maxxp=src.maxxp*1.9
src.xp=0
src.lvl+=1
src<<"You've ranked up!"
src.rankcheck()
src<<"Your health has been increased by 50."
src.maxhp+=50
src.hp+=50
else
src<<"Sorry, you're exceeding the Rank limit, which is currently Rank 14."


Problem description: I'm making a PvP game for my bro, and there's only one problem: You get gold every time you hit someone, instead of every time your target dies. Can someone figure out the problem?

I might be wrong, not sure, since I'm fairly new to DM but I noticed that the way i've read it, that the gold gain statement isn't indented INSIDE the actual death check, but that after the check is completed, regardless of if the target was killed or not, the usr still gains money.
Well, you're not restoring their stamina upon death and your code is very messy!

mob
var Stamina = 10
var maxStamina = 10
var Experience
var maxExperience = 10
var Level
var Gold
proc
checkDeath(mob/Target)
if(Target.Stamina <= 0)
Target << "You have been killed."
Target.Stamina = Target.maxStamina
Target.loc = locate(50, 50, 1)
world << "[src] kills [Target]!"

if(Target.Level < src.Level)
src.Experience += Target.Level + 15
src.Gold += 20
src << "20 gold has been obtained."

if(src.Level > Target.Level)
src.Experience += Target.Level + 5
src.Gold += 10
src << "10 gold has been obtained."

checkLevel()
while(Experience >= maxExperience)
if(Level < 14)
Level ++
// extras here
else
// your else statement code
In response to Neimo
Q: What happens if src.Level == Target.Level?
A: Nothing, you didn't take that in to account. Please, use "else" instead of retyping a whole line where you don't have to, think of the bytes (actually, think about how many seconds you can save from your life with avoiding this type of problem in the future and pulling your hair in frustration)

Since the OP had a basic formula going on, you can add everything to a few lines or so (and to avoid giving you a huge headache, I will not put it in one or two lines):

Note that the OP showed:
Target.level < src.level = +5 src.level, 10 gold
Target.level == src.level = +10 src.level, 15 gold
Target.level > src.level = +15 src.level, 20 gold

Do you see a pattern? Each scenario has an increase of 5 :o what does that mean? Well, this:
if(!Target) return // no point of having runtime errors if there's no target defined
var/gain = 5

// The one line of the follow is as follows: gain +=(Target.lvl>=src.lvl)?(Target.lvl>src.lvl)?10:5:0
if(Target.lvl>src.lvl)
gain += 10
else if(Target.lvl==src.lvl)
gain += 5

Target.xp += src.lvl + gain
var/gold = gain + 5 // did you noticed that as well?
Target.gold += gold // This is an example, copy/pasting, for whatever reason, will cause problems.

Target<<"You gain [gold] gold."
Target.lvlcheck()