ID:159498
 
Hi, im making a level system and i want it so that in early levels (1 to 10) the exp needed to level up is doubled untill your level 10, which is reduced to 1.9 and when you get to level 20 is goes to 1.8 and so on. I used just this first, "usr.expn = round(expn * 1.5, 1) + round(expn/100*10)" but as i got to level 30 odd i needed millions of exp to level :S which in my opinion is retarded (too many numbers everywhere) and if i make that formula too low all the low levels will only need 1exp to level up so thats why im trying to do it a different way.


if(usr.level==1||2||3||4||5||6||7||8||9||10)
usr.expn=round(expn*2)
else
if(usr.level==11||12||13||14||15||16||17||18||19||20)
usr.expn=round(expn*1.9)


This code always seems to double the expn even if it goes past level 10, even tho im using the "and" operator :S Isnt there an operator to tell byond to chose it if its inbetween the certain values? one to ten etc.


Any help will be appreiated greatly :)

You're not using the operators correctly. You're saying this:

If level is one, or if 2, or if 3, or if 4, or if 5, etc. etc.

It'd be if(level == 1 || level == 2 || level == 3 etc. etc. if you wanted to do it that way.

More compact would be if(level in (1 to 10)), which I'm pretty sure works.

More compact still, come up with a formula for it:

var/expmod = 2 - round(level/10)
expn = round(expn*expmod)

EDIT: Oh, that formula won't work if level>=100, so you'll want to check for that case. That could be your level cap, for example.
Use <dm> and </dm> tags.
    if(usr.level==1||2||3||4||5||6||7||8||9||10)
usr.expn=round(expn*2)
else
if(usr.level==11||12||13||14||15||16||17||18||19||20)
usr.expn=round(expn*1.9)


That is because (usr.level==1||2||3||4||5||6||7||8||9||10) is always true. DM thinks you mean "(if the user's level is 1) or (two) or (three)..., not (if the user's level is one or two or three...
Any number but 0 is always considered true.
Try
if(usr.level >= 1 && usr.level <= 10)
usr.expn = ...
else if(usr.level >= 11 && usr.level <= 20)
usr.expn = ...
...

Also note how "else if" is on one line.
In response to Jp
Correction: That formula won't work if level >= 190. At level 100, it multiplies exp by 1, at level 110, it multiplies exp by 0.9, etc.
In response to Immibis
At level 100, expn is getting multiplied by 1 - that is, levelling up from 100-101 takes as much experience as levelling from 99-100. I consider that to be broken.

At level 110, it takes less experience to hit 111 then the 109-110 transition took. Also broken.

This is assuming that expn is the amount of experience required to reach the next level, of course.
In response to Jp
Based on the code in his original post, I don't think that's what he is trying to do. I don't know what he is trying to do, though.
Aside from the stuff others have mentioned here this is a good usage of the switch() statement.

switch(src.level)
if(1 to 10)
// Some stuff
if(11 to 50)
// Other stuff
else
// If it's below 1 or more than 50 this'll be hit.
In response to Nadrew
aha, the level cap will be level 100 :) And thank you all for your responses I'll get back to all once I've tried some of your methods :D
In response to Andrew001
Sorry for double post but, i got it the way i intended :) thank you all for your help.
            switch(src.level)
if(1 to 10)
usr.expn=round(expn*1.3)
if(11 to 100)
usr.expn=round(expn*1.1)