Solved Custom EXP bar values

Discussion in 'Spigot Plugin Development' started by MrDienns, Apr 16, 2017.

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

    I'm trying to create a plugin that has fully custom exp bar values. Players would be able to level up by killing monsters, just like always, but the values should be different. I want a player to have a custom leveling & exp bar. They can level up to 100. Every level should have 50% more exp required than last one. How would I best do this?

    Thanks
     
  2. Photon

    Supporter

    1) First of all I would recommend to disable the vanilla exp system (set the according gamerule to false via #getServer().getWorld(...).setGameRuleValue(...)).
    2) Set up some system to save the current xp of a player (db / file)
    3) Set up some formula to get the total required xp for the next lvl (1.5^x) and a method to determine the xp til the next level
    4) Add some listeners to detect the killing of entities to give the killer the amount of exp you wish
    4) #getPlayer().setLevel(...) / #getPlayer().setExp(...) will set the bar values for you.
     
    • Useful Useful x 2
    • Agree Agree x 1
  3. Also keep in mind Player.setExp(float f) is the percentage for the xp bar. I was a little confused at first, but I figured it out as I'm also working on a plugin that uses levels.
     
    • Friendly Friendly x 1
  4. I ehm, I think I broke something.

    [​IMG]

    I got it working thanks to the help. I'm doing some extremely hard math right now and looks like my math completely broke the game lmao
     
    • Funny Funny x 3
  5. lol the value of setExp() should be somewhere between 0.0f and 1.0f

    So for example:

    Code (Text):
    public void example(Player player) {
        player.setLevel(2); /* Level is 2 */
        player.setExp(0.3f); /* XP bar is 30% full */
    }
    You could either work with percentages or make an algorithm that converts number of exp to percentages that's up to you, but just know that's how it works in the bukkit api.

    If you did do it that way show us your math.
     
  6. Check https://www.spigotmc.org/threads/math-issues.233599/
     
    • Agree Agree x 1
Thread Status:
Not open for further replies.