ID:788759
 
(See the best response by Deathguard.)
Hello to begin with i'm a newb coder...I'm making an rpg demo to start getting used to this code thing :P.I've made the basic lvl up etc. but I forgot to make a gain exp proc (don't got an idea how to). Well the way I want the player to gain exp is by killing another mob (npc or player;an expecific exp for different npcs).Mind someone help me?Thanks
Best response
When a mob is killed, have it trigger a procedure that checks who the killer is and awards them the appropriate experience.

You could define what EXP each NPC provides as a variable belonging to that NPC, for now, but later on you could do something like divide the NPC's level by the player's level, and grant them EXP based on that. Just a thought; it's much neater than manually giving each NPC a set amount of EXP to provide.

Example of the proc?please because I've coded the npc or player dies when his Stamina reach 0 and with the death check proc it auto kills them so I don't know how should I code the killer thing DX
mob/var
exp_give

mob/NPC
Bat_Thing
icon = 'bat thing.dmi'
icon_state = ""
exp_give = 10 // Give 10 exp per kill


mob/verb
Attack(mob/M in get_step(usr,usr.dir)) // Check for the mod directly infront of you.
damage(usr, M) // send it to the damage proc defined below

proc
damage(mob/attacker, mob/defender)
var/damage = attacker.strength - defender.defense
defender.hp -= defense
view(defender) << "<b><small>[defender.name] took [damage] damage!"
if(attacker.client) // check to see if the attacker is a player and not an NPC
attacker.experience += defender.exp_give
levelUp(attacker)

levelUp(mob/M)
if(M.experience >= M.max_experience)
M.experience -= M.max_experience // take away the required amount to level up, leaving the remainder.
M.level++ // +1 Level
view(M) << "<b>[M.name] leveled up to level [M.level]!"



This is a basic idea. I didn't define most of the variables prior to use. But you should get the idea.