Level System

Discussion in 'Spigot Plugin Development' started by RayoxHD, May 6, 2017.

  1. Hello,

    im having trouble with my level system i need to make a exp progressbar like this: http://prntscr.com/f4qhqx how would that be done?
     
  2. Hello.

    It appears that it is item lore you are dealing with. So I would suggest you to take a look at String modification/creation classes(please correct me if I'm wrong) - StringBuilder, StringBuffer. You would want to insert color code at specific place of your progress bar
     
    • Agree Agree x 1
  3. yeha that i found out but how do i do it with the stringbuilder trying for a few hours now
     
  4. Take a look at StringBuilder#insert()

    You need to think of a way to calculate a position in your progress bar to place specific color code
     
    • Agree Agree x 1
  5. Code (Java):
    // you can make a variable called total
    // this is like how much exp or something they currently have
    int total = 10;

    // this is the max amount of exp or something needed
    int max = 100;

    // now we should calculate how many bars we should make green or something
    float  percent = (float) total/max;

    // since we just got the percentage, we can now like figure out how many bars we need to make green for example.

    // how many bars are there in total ?, we'll use 50 as an example.
    int amountOfBars = 50;

    // now we can just find the amount we need to change to green to show the progress.
    int bars = (int) amountOfBars *  percent;
     
    At the end "bars" is the amount of bars you should fill in to show the current progress.

    Hope this helps
     
    #5 KiranHart, May 6, 2017
    Last edited: May 6, 2017
  6. incoming "error. it expects a ;"
     
  7. WOW! Thanks that help but now i need to set the players exp bar to fill the percentage becauzs eiu have different exp/levelup values for exp my player is lvl 8 needs 830 exp to level up the total of exp to lvl 8 is 1200 now i want to represent the difference of those two values the percentage on the exp bar.
     
  8. Ah, fixed it :p
     
  9. so this is being done in the players level/experience bar? Like the exp?
     
  10. This one bugs a bit it only displays the greebar after 7% http://prntscr.com/f4rfu9
    Code (Text):

    public static Object displayProgressbar(int lvl, int exp) {
            int filled = (int) ((exp*100)/Main.exp.get(lvl));
            int max = Main.exp.get(lvl);
            int amountOfBars = 50;
            float  percent = (float) exp/max;
            int bars = (int) ((int) amountOfBars *  percent);
            StringBuilder sb = new StringBuilder("||||||||||||||||||||||||||||||||||||||||||||||||||");
            if(bars >= 1) {
                sb.insert(0, "§a");
                sb.insert(bars, "§7");
            }else if (bars < 1) {
                sb.insert(0, "§7");
            }
           
            return "§8[" + sb.toString() + "§8]§6 " + filled + "%";
        }
     
     
  11. I'd assume it will do that maybe, those numbers were just random try using th exact code I gave u like for the amount of bars put th actual number. Try playing around with the numbers and see
     
  12. your doesnt work i get a ArraysOutofBounds becaus eit gives me 260 bars
     
  13. Maybe it needs more space at the begining thats why its not coloring?
    Code (Text):
    if(bars >= 1) {
                sb.insert(0, "§a");
                sb.insert(bars, "§7");
            }else if (bars < 1) {
                sb.insert(0, "§7");
            }