Set exp to level up

Discussion in 'Plugin Development' started by Eistee², Sep 15, 2013.

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

    Eistee²

    Hello, i had a question is it possible to set the exp you need to level up?

    nothing like

    Code:
    @EventHandler
    public void onPlayerExpChange(PlayerExpChangeEvent event)
    {
    int exp = event.getAmount();
    //some code here
    event.setAmount(exp);
    }
    I really mean set exp to level up :)

    Sincerely
    Eistee²

    sorry for my bad english
     
  2. Offline

    hanahouhanah

    Well, I'm not sure if you'll want to use PlayerExpChangeEvent because it'll level them up everytime they pick up an exp orb. But if you really wanted to use that event, something like this:
    Code:java
    1. @EventHandler
    2. public void onPlayerExpChange(PlayerExpChangeEvent e){
    3. Player player = e.getPlayer();
    4. player.setLevel(player.getLevel()+1);
    5. }
     
  3. Offline

    Eistee²



    It only was an example :)

    I make it configurable how much exp you need for my plugin (minebuilder)

    because I had a request if I could add something like this and my question is it if i could it some thing like player.expToLevelUp = 20 ore something like that :)
     
  4. Offline

    hanahouhanah

    Then I think something like this would work:
    Code:java
    1. int exp = (int)player.getExp();
    2. player.setExp(exp+getConfig().getInt("Something"));
     
  5. Offline

    Eistee²


    but this would only set exp or?
    Not the amount of exp you need to level up? :D

    But thanks for helping me
     
  6. Offline

    hanahouhanah

    I'm actually now confused on what you're trying to do now.
    Do you want them to just level up, or did you actually want to find how much exp they need to level up?
     
  7. Offline

    Eistee²



    Set how much they need to lvl up :)

    You need from lvl 1-16 = 17 exp
    16-17 = 20 and so on...
    and i want to change this so you need for lvl 1 = 20 exp
     
  8. Offline

    hanahouhanah

    I think I get what you're saying.
    So you want it to set custom exp levels.
    Code:java
    1. Player player = e.getPlayer();
    2. if(player.getExp() == getConfig().getInt("Level1")){
    3. player.setExp(0);
    4. player.setLevel(1);
    5. }
    6. if(player.getExp() == getConfig().getInt("Level2")){
    7. player.setExp(0);
    8. player.setLevel(2);
    9. }
    10. if(player.getExp() == getConfig().getInt("Level3")){
    11. player.setExp(0);
    12. player.setLevel(3);
    13. }

    It would be something like that. But I'm pretty sure there's a better way.
     
    Eistee² likes this.
  9. Offline

    Eistee²



    Ah i get what you mean :D thanks for the idea! :3
     
Thread Status:
Not open for further replies.

Share This Page