Exp formula's not accurate?

Discussion in 'Spigot Plugin Development' started by TheGamerPlayz, Jun 10, 2016.

  1. I am using this to get the amount of exp required to level up.
    Code (Java):

        public float exp(Player p){
            Scoring sc = new Scoring(pl);
            FileConfiguration score = sc.getData();
            int level = score.getInt("Score."+p.getUniqueId().toString()+".level");
            int exp = score.getInt("Score."+p.getUniqueId().toString()+".exp");
            float amount = 0;
            if(level <= 16){
                amount = 2 * level + 7;
            }else if(level <= 17 && 32 >= level){
                amount = 5 * level -38;
            }else if(level > 32){
                amount = 9 * level - 158;
            }
            amount = amount * (exp/(level*level*level));

            return amount;
        }
     
    and when I set the a player's exp to this it is not accurate lets say the level is 20 and the exp is 4000 it is giving around a 60% full exp bar instead of a 50% full one. Am i doing something wrong or is the formula actually inaccurate.
     
  2. 4000 xp -> Lvl 44
    Lvl 20 -> [550, 611]
    Something is very wrong with your formula..
     
  3. Sorry let me make this more clear. Exp i have is basically the amount of kills a player has for me. And level is if they have so many kills. I want the levels to be on the Exp bar and the exp bar itself to be how close they are to leveling up. And at lvl 20 they need 8000 kills to level up and they currently have 4000 kills I'd like their exp bar to 50% full
     
  4. If you want to make it 50% full wouldn't you just get rid if this line:
    Code (Text):
    amount = amount * (exp/(level*level*level));
    And just use:
    Code (Text):
    amount = amount * 0.5;

    Unless I'm misreading your code because I'm not sure what value exp is being set to, and I'm not sure what you are trying to do with that last line of code.
     
  5. It will not always be 50% it will change depending of the amount of kills the player has

    Also you have a very memorable name, I see you atleast once a day on here XD
     
  6. I work in IT, so I go on these forums whenever I have downtime. Could you just explain to me what the exact purpose of your method is? If you want to set the xp bar to 50%, then take the amount needed to get to 50%, subtract what they already have, and then add the difference. If they are above 50%, then take what the have, subtract the amount needed 50%, and remove the difference.
     
  7. Lets say their level is 20 and they need 8000 kills to level up.I want to their exp bar to show their progress. So when they are 10% done it is 10% full and when its 50% done the bar is 50% full and such.
    I am currently taking the amount of exp needed to level up and multiplying by (kills/kills needed)
     
  8. That should work if you are doing it properly. What exactly is this line doing:
    Code (Text):
    amount = amount * (exp/(level*level*level));
    What exactly is exp, and why are you dividing it by level^3
     
  9. The exp bar displays its progress from a value of 1-0 so if you want the bar to show up as 50% full you have to set the bars value to 0.5 and for 30% full you'd want 0.3 etc.
     
  10. Inkzzz

    Resource Staff

    From what I think you are wanting to do is display the players "kills" divided by the required kills.

    For instance:
    Code (Text):
    double complete = (kills / needed) * 100;