Solved Easy maths help

Discussion in 'Plugin Development' started by KingFaris11, Apr 13, 2015.

Thread Status:
Not open for further replies.
  1. Hi, one of my methods needs to convert total exp (custom) to a level.

    Here's the conversion:
    Code:
    Lvl 0 = 0 EXP to 49EXP
    Lvl 1 = 50 EXP to 149EXP
    Lvl 2 = 150 EXP to 249 EXP
    Lvl 3 = 250 EXP to 349 EXP
    Lvl 4 = 350 EXP to 449 EXP
    Lvl 5 = 450 EXP to 549 EXP
    
    This continues adding 100 till Level 20 (max level).

    I want it something like:
    Code:
    public static int getLevel(int totalExp) {
        return <x>;
    }
    
    I know I can easily do the 'if' statement checks and see whether 'totalExp' is less than the maximum boundary for each level, but I was wondering if I can do this all in maximum a few lines?

    I can't figure out the formula right now, probably having a dumb moment, can someone help me please? Thanks in advance.

    Never mind, I got it.

    Code:
    public static int getLevel(int totalExp) {
        for (int i = 0; i < 20; i++) {
            if (totalExp < (i * 100) + 50) return i;
        }
        return 20;
    }
    
    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Apr 13, 2015
Thread Status:
Not open for further replies.

Share This Page