calculating experience for level

Discussion in 'Plugin Development' started by Kenda, Aug 15, 2021.

Thread Status:
Not open for further replies.
  1. Offline


    Hey guys,

    Today i try to make a system of level with experience. I make a graphic to help but I have a problem.
    I would like each level to be 25% more than the old level, so basically for level 1 you need 200 xp, and for level 2 you need 200xp + 25% (so 200 * 2.25 = 450), And so on.


    But I have not found a mathematical formula to find the corresponding level. (Apart from making the conditions one by one but not the ideal).

    Can you help me ? Thanks you very much :)
  2. Offline


    I mean, this is just a mathematic question. First of all, if you mean 200 + 25%, this means 200 * 1.25 = 250. 450 is even over doubling.

    Formula to find the EXP from the level

    Anyway, the formula here is that u(n) = u(n-1) * 2.5 with u(1) = 200. This means that for the n-th number in this list, take the previous one and multiply by 2.5. But for the 1st number, aka level 1, it is defined to be 200.
    With n >= 2, you can calculate the number at the n-th position with the formula u(n) = u(1) * q^(n-1).
    So for level 4 for example, you put: u(4) = 200 * 2.25^3 = 2278,125. Correct?

    Formula to find the level from the EXP

    Take for example, 200k XP, which would be between level 9 and 10. You would want it to calculate and return 9 wouldn't you. We have 200000 = u(1) * q^(~n-1), where ~n is an approximate value of n. Just substitute the values that we know in first, now we have:
    200000 = 200 * 2.25^(~n-1).
    Simplify it, we get:
    1000 = 2.25^(~n-1)

    To get the exponent of the number, we take the logarithmic of the base because:
    log base n of n^x = x

    Apply logarithmic base 2.25 to both sides:
    logBase2.25(1000) = logBase2.25(2.25 ^ (~n-1))
    8.518 = n - 1

    Rounding the left side down, always, and solve for n:
    n = 8 + 1 = 9

    Hope you can make sense of this.
    Thanks for coming to my lecture.

    dude i had to open my text book during lockdown you have to make sense of this pls
  3. Offline


    Thanks for your answer, but I'm really bad at math
    Possible to have a slightly more simplified version if possible?
  4. Offline


    Math like that glazes my eyes over as well, lol. I think the most important point he made was that your assumption that the chart you posted is prior level + 25% is in err. If each level is supposed to be calculated like that, level 2 should be 250 not 450.

    Ideally, figure out the nifty formula Sheqp posted but another, more simplistic way, would be:
    public long getExperienceRequirement(int level) {
      long xp = 200;
      for (int x=2; x<=(level > 173 ? 173 : level); x++) {
        xp = Math.round(xp + (xp * 0.25));
      return xp;
    I don't recall if fractions are used in the experience system, if so you can switch to double. The 173 level check is because for any level over 173, it's gonna return the same amount anyway as you hit the limit.
  5. Offline


    Pain when everyone doesn't understand the maths. Simplifying too much would make it even less comprehensible as grossing over what a mathematic function does is not a good idea.

    EDIT: I only suggested that he could be wrong by meaning +25%. But all the maths and formulas were done with his original values.

    You can check very simply, for example, to find the exp needed for a level, which would be:
    u(n) = u(1) * q^(n-1)

    u(1) is the original value, at the lowest level, and n can not be lower than 1, which is 200 from his table.
    q is the multiple. You can calculate it by taking one value, and divide it by the value directly before it. Suppose we take u(2)/u(1) which is 450/200 and it evaluates to 2.25.
    n is just the level you want to find the exp requirement for.

    I'm pretty sure that was clear enough.
    Last edited: Aug 17, 2021
  6. Offline


    Pain when you had to deal with arrogant people online who think just because it's easy for them, it has to be easy for everyone. Some people just aren't good at this stuff.
  7. Offline


    bro i wasnt even making fun of you
    i tried my best to help, and to list out what i think that could be the solution

    i took majors in maths and english, so maybe i could be a bit better than you at the subject, but if you don't understand, the problem could also be my teaching, not you.
    you're probably better than me in some other way, who knows?

    i gave out full formulas, all you have to do is implement them in codes, and you did it, but using loops instead of a direct formula. that's all there is.

    i thought of everything and simplified the maths down to a "solve for x" problem, which should be easier to implement than having to think of all the transformations and substitutions. if i were to simplify it more, it wouldn't make sense why i use this math concept, this math function and whatever to a beginner.

    that's all. just calm down dude. maths isnt everything. but it has a close relative of programming in general, so it is still inevitable, and you will have to work with it.

    EDIT: @Kenda
    It's really hard to know what you don't understand if you just say that. You should read thoroughly, and pinpoint exactly where you don't understand, then we can start working on it.
  8. Offline


    lol calm down? I'm not upset, just saying the way you put that is a bit insulting.

    I don't get why people keep thinking math and programming go hand in hand. It depends on the industry you are working in. I've worked the last twenty years for a major municipal government, earning a six figure salary as a systems engineer where programming is a large part of my job and aside from basic stuff like calculating percentages or doing conversions math doesn't come into it at all.

    As to simplifying, I doubt OP really cares about the math lesson. The most simple answer would be like double xp = 200 * Math.pow(2.25, level-1). It's good to take the time to explain, but including the actual answer would've been more useful for OP ;)
  9. Offline


    1. Sorry if it sounded insulting
    2. I don't really care if OP cares about the math lesson. I just explained why the formula is that way, so if anyone else encountered the same thing, they would understand exactly what they are trying to implement.
    3. I'll take it that you have a lot more experience in programming than me, but saying maths don't go hand in hand with programming is just wrong. No, you don't need high level maths and weird concepts to do everyday. Basic operations are still maths, and you can't dispute that.
    4. Including the answer like that would be ok for people who learns by c&ping, But again, how would they know what it does, and how they can extend from it?

    This is probably my last post to this thread, I don't intend to prolong this argument anymore. Did you win the argument? If you think so.
    And if the OP feels like he learns better from your ways, then I'll just stop going into this thread.
  10. Offline


    As to #3, c'mon now, you're being a bit silly. You know I don't mean basic arithmetic :p
    Shqep likes this.
  11. Offline



    Thank you for your answers to both (no need to confuse you for so little).
    I think my table may be poorly designed, but using this example again:

    u (n) = u (1) * q ^ (n-1)

    I may have understood how your famous math calculations worked, which are quite simple after a good analysis.
    I tried to do my tests on my own, and I will come back if a few things don't work :)
    Shqep likes this.
Thread Status:
Not open for further replies.

Share This Page