ID:839657
 
Code:
//setting NPC stats
mob/CombatNPCs/Enemies
Character
// PowerMode="Ki Only"
proc/LevelScale(var/NewLevel)
if(NewLevel>=src.Level)
src.Level=NewLevel
var/BoostBy=round(src.Level)
src.MaxPL+=BoostBy*100
src.MaxKi+=BoostBy*50
src.Str+=BoostBy*10
src.Def+=BoostBy*5
src.Exp=BoostBy*10
src.AddPlPercent(100)
src.AddKiPercent(100)
//this is how i calculate EXP which player earns after killing
mob/DeathCheck(var/killer)
Killer.AddExp(round(src.Exp*100/50),"Kills")


Problem description:Is there a better way to give player exp?

I don't know why you're showing LevelScale() instead of something more relevant like AddExp().

Also, (src.Exp * 100 / 50) = (src.Exp * 2)
or u can create a mob/var/tnl and set it equal to w.e then do if(src.Exp>=tnl)//level up etc
i got that done all level up just wanted to know how can i make it so player earns more EXP when player kills higher level npc. in other terms how to calculate ammount of exp that player will earn killing Npc?
I would think you know how to do that. When a killer kills src, the killer gains half src's exp. This makes me think you're not using a level system, otherwise you would use src's level in killer.AddExp instead.

To answer your late question, all you want to do is factor in src.level in killer.AddExp instead of src.exp.

Do you know what you're doing with the code you have?
If not, start over and write code while you do know what you're doing.
In response to Kaiochao
Kaiochao wrote:
I would think you know how to do that. When a killer kills src, the killer gains half src's exp. This makes me think you're not using a level system, otherwise you would use src's level in killer.AddExp instead.

To answer your late question, all you want to do is factor in src.level in killer.AddExp instead of src.exp.

Do you know what you're doing with the code you have?
If not, start over and write code while you do know what you're doing.

sorry for not giving all the code
mob/proc/LevelCheck(var/Reason)
if(src.client && src.Exp>=src.MaxExp)
// var/PreLevel=src.Level
var/LevelsGained=round(src.Exp/src.MaxExp)
LevelsGained=min(LevelsGained,999999-src.Level)
src.Exp-=LevelsGained*src.MaxExp;src.Level+=LevelsGained;src.MaxExp=round(src.Level*100)
src.TraitPoints+=LevelsGained
src.TrackStat("Levels Gained",LevelsGained)
src.TrackStat("Levels from [Reason]",LevelsGained)
src<<"<b><font color=blue>Your Level has Increased by [FullNum(LevelsGained)] to [FullNum(src.Level)]![Reason ? " ([Reason])" : ""]"

AddExp Proc
mob/proc/AddExp(var/Exp2Add,var/Reason)
if(Exp2Add<=0) return
var/client/C=src.client
if(C)
Exp2Add=Exp2Add
C.mob.Exp+=round(Exp2Add)
C.mob.LevelCheck(Reason)
C.mob.UpdateHud()

i want an quation that can help me give equal exp/100
"help me give equal exp/100" doesn't make any sense.

Also, a few points.
var/LevelsGained=round(src.Exp/src.MaxExp)

This is incorrect. The expression "src.Exp/src.MaxExp" is the percentage of src.Exp to src.MaxExp. Instead, it should be the other way around, "src.MaxExp/src.Exp".
src.Exp-=LevelsGained*src.MaxExp

This is incorrect. Even assuming LevelsGained was correct, src.MaxExp changes for each level, so you can't simply multiply it.

The simplest way with the least math involved is just to loop.
mob
var
experience = 0
max_experience = 100

proc
gain_experience(amount)
experience += amount
check_experience()

check_experience()
var old_level = level
while(experience >= max_experience)
gain_level()
var new_level = level

var level_diff = new_level - old_level
if(level_diff > 0)
leveled_up(level_diff)

gain_level()
level ++
experience -= max_experience
max_experience = level * 100

leveled_up(amount)
if(level_diff == 1)
src << "You leveled up!"
else
src << "You gained [amount] levels!"


Also just to note, in AddExp:
Exp2Add=Exp2Add
// obviously does nothing

var/client/C = src.client
C.mob.blah = blah
// redundant because src == src.client.mob
// you could even do src == src.client.mob.client.mob.client.mob if you wanted
// but you shouldn't because that's just ridiculous.

// It's good to check if a mob has a client before using things like winset(),
// where a client is required.
// If that's the case, all you need is the if(client).