Solved Charge EXP Level

Discussion in 'Plugin Development' started by HeavyMine13, Aug 16, 2014.

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

    HeavyMine13

    Hello! So I want to make an xp bar to "charge up" from level 0 to level 100 under 20 seconds and then stop at 100! How can I do that? Thanks!
     
  2. Offline

    Robin Bi

    HeavyMine13 You want it to "charge" like a progress bar? Then you'll have to use a RepeatingTask with your Scheduler and increase the XP of the player of a certain amount of XP that you have to calculate first ;)
     
  3. Offline

    teej107

    How would one initiate the charge? There are many ways to do this. One would to use Bukkit Schedulers, Testing time difference of the system, etc.
     
  4. Offline

    HeavyMine13

    I just want a charge method, since I already know where I want to start the charge up!

    Well then how can I calculate it so it like increases as if you are waiting for it to be 100 so you can cast a spell or such?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Offline

    DinosParkour

    HeavyMine13
    I use this in my plugin, but I'm not sure if it's 100% correct (but hey, it's working)
    Code:java
    1. public void charge(final Player p){
    2. final Float originalXP = p.getExp();
    3. final BukkitScheduler s = Bukkit.getScheduler();
    4.  
    5. p.setExp(0);
    6.  
    7. Runnable add = new Runnable(){
    8. public void run(){
    9. p.setExp(p.getExp() + 1/18F); //(if you look closely, the xp bar is divided in 18 smaller bars)
    10. }
    11. };
    12. final int xpTask = s.scheduleSyncRepeatingTask(this, add, 0, 60/18);//0 is the delay before it starts and 60/18 means it will have filled the 18 bars in 60 ticks (3 seconds)
    13.  
    14. Runnable reset = new Runnable(){
    15. public void run(){
    16. p.setExp(originalXP);
    17. s.cancelTask(xpTask);
    18. }
    19. };
    20. s.scheduleSyncDelayedTask(this, reset, 3 * 20);
    21. }
     
  6. Offline

    HeavyMine13

    Yes I want that animation, but i want the level number above the bar to go from 0 and smoothly increase to 100
     
  7. Offline

    DinosParkour

  8. Offline

    HeavyMine13

    well that doesnt make it work at all

    DinosParkour thanks for help, I looked into docs and made my own method! Thanks!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  9. Offline

    DinosParkour

    HeavyMine13
    If you do it correctly, it works:
    Make a repeating task, which will do p.setLevel(p.getLevel + 1) every time. You want it to start immediately so the delay number should be 0 and you want it to repeat every 1/5 of a second so the second number should be 4.
    Then make a scheduled task after 400 ticks and cancel the repeating task. (like i did in my code)

    EDIT: Oh, glad it worked :)
     
Thread Status:
Not open for further replies.

Share This Page