ID:1425946
 
(See the best response by Phat T.)

I need a code to set a limit to lvl up


for example I have to gain 300 experience to climb to lvl 2 ..... 600 exp to level 3 ............. 900 lvl4 experience and all so ..... I need esooo ......... ........
Try working it out mathematically...you can use all kinds of operations like addition, subtraction, multiplication, and division, for example :P

How fast do you want it to climb exactly? Exponentially or a fixed amount each time?
Best response
mob
proc
Level_Up(mob/players)
if(src.level == 45) // set level limit
src.level = 45
src.exp = maxexp
return
if(src.exp >= src.maxexp) // leveling up
var/max_exp = src.level * 16999
var/rollover_exp = src.exp - src.maxexp
src.level ++
src.exp = 0
src.maxexp = max_exp
src.exp += rollover_exp


That is how i would do it :)
Thanks served me well
In response to Phat T
Phat T wrote:
> mob
> proc
> Level_Up(mob/players)
> if(src.level == 45) // set level limit
> src.level = 45
> src.exp = maxexp
> return
> if(src.exp >= src.maxexp) // leveling up
> var/max_exp = src.level * 16999
> var/rollover_exp = src.exp - src.maxexp
> src.level ++
> src.exp = 0
> src.maxexp = max_exp
> src.exp += rollover_exp
>
>

That is how i would do it :)

What if the rollover_exp var is still higher than maxexp? I wouldn't do it the way you've shown.

Edit:

Where is mob/players used?
Hmm, here it is

world
mob=/mob/players
mob/players
Login(/**/)


You can always use math to set rollover_exp. I don`t see any problem here sir ^^ I am just showing him the way it could be done.
In response to Phat T
Phat T wrote:
Hmm, here it is

>
> world
> mob=/mob/players
> mob/players
> Login(/**/)
>

You can always use math to set rollover_exp. I don`t see any problem here sir ^^ I am just showing him the way it could be done.

I'm not having a dig or anything, but mob/players isn't used in that proc at all. Maybe DM has changed since I last went in to it, but from what I know the "Level_Up(mob/players) could just be Level_Up().

I personally would do this:
mob/proc
Level_Up()
if(src.exp < src.maxexp) return /* I may actually make the operator
< and change return to
src.Level_Up() and place it where
the level up proc is called (Then
the proc won't get called when
it's not needed). */

while(src.exp >= src.maxexp)
src.exp -= src.maxexp
if(src.level < levelcap) src.level++
else break
src.maxexp += rand(300,500)
sleep(1)
Personally I would go with something like this, but there are numerous ways to go about these things.
(Heavily commented for the OP)
// Insert a level cap for your game
#define LEVEL_CAP 70

// Relevant variables
mob/var
level = 1
exp = 0
maxExp = 300

mob/proc
gainExp(amount)
// Can't gain exp once you reach the level cap
if(level >= LEVEL_CAP) return
// Ensure the amount is a number
if(isnum(amount))
// Add the exp
exp += amount
// If you have reached or exceeded the maxExp
if(exp >= maxExp)
// Get the excess experience
var/excess = exp - maxExp
// Run the levelUp() proc
levelUp()
// If there is excess exp, add it
if(excess) gainExp(excess)

levelUp()
// Increase Level, Reset exp
// and increase maxExp
level ++
exp = 0
maxExp += 300
mob
var
level = 1
exp = 0
max_exp = 300
proc
gainExp(amount)
exp += amount
while(exp>=max_exp)
if(level>=70)break
var excess = exp - maxExp
exp = excess
level++
max_exp+=300