ID:157118
 
I'm trying to make it so when you kill someone you gain exp depending on your opponents level. So can someone help me code it?

Death(var/mob/killer)
killer.exp += (src.level * 20) // 20exp for each level the guy you kill is. lvl 1 = 20, lvl 2 = 40. lvl 3 = 60.


and then just run w.e proc you have to check if the exp >= required exp for level up.

Also might want to make something that stores and then adds the remaining exp. so if the exp is > required exp. It levels you up, and then adds the amount that was above the required exp back.

This could be done like so:
Level()
var/leftover
if(src.exp >= src.maxexp)
leftover = (src.exp - src.maxexp)
if(leftover <= 0)// avoid any negative stuff.
leftover = 0
src.level ++
src.exp = 0
src << "You gained a level"
src.exp += leftover


Additional information: You've posted in the wrong section, this should go under classified ads.
In response to Jarquille (#1)
That's backwards. The Death() proc should belong to the mob doing the dying, and the argument should be the mob killing it. So, you'd have:

mob/verb/attack(var/mob/M in oview(src,1))
M.die(src)

mob/proc/die(var/mob/killer)
killer.exp += 1
del(src)
In response to Garthor (#2)
my mistake. edited my original post.
In response to Jarquille (#1)
How do you make it so when you kill a npc you gain exp depending on its level?

In response to Alkhalif10 (#4)
This isn't a "request programmers to put in the effort for you" area, it is a place where people ask for help on how to go about doing something, possibly with some code they have worked out themselves. You cannot perfect programming in a week, a month, or a year. However, reading the guide will sureley speed you along.