Convert exp table to level?

Discussion in 'Plugin Development' started by Svizz, Sep 8, 2011.

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

    Svizz

    Hello everybody. I have a table like this:
    Code:
    int[] expperlevel = {0, 10, 30, 60, 100, 150, 210, 280, 360, 450, 550};
    and i have to get a level from this table. It's my method:
    Code:
    public static int readLvl(String player) throws SQLException{
            String query2 = "SELECT * FROM rpgcraft WHERE nick='" + player + "'";
            ResultSet result = dbManage.query(query2);
            int exp = result.getInt("expPostaci");
            //int lvl = ????????????????????????;
            // how i can convert table expperlevel[] to level??
    
            return lvl;
        }
    I'm completly noob in java, so anybody can tell me, what i have to do? This plugin is only for learning :) Sorry for my english, i'm polish :D
     
  2. Offline

    Ghappy

    I'd say something like this: (if exp = 1000)
    int exp = 1000;
    int level = 0;
    for(int i : expperlevel){
    if(exp >= i){
    exp = exp - i;
    level++;
    } else {
    break;
    }
    int level now contains your level, and exp contains your current xp in this level, while (i - exp) is the exp to next level
     
  3. Offline

    Svizz

    Sorry, I used wrong words :) I only want to return level from experience.

    Ok, thanks! Only one question - now array 'expperlevel' contains a number of experience to next level? For example, if for level 2 I need 50 exp and for level 3 i need 75, array will look like:
    Code:
    int[] expperlevel = {0, 50, 25};
    or:
    Code:
    int[] expperlevel = {0, 50, 75};
    ?
     
  4. Offline

    stelar7

    probably the last one... Since when exp is at a point it it doesn't go back to 0
     
Thread Status:
Not open for further replies.

Share This Page