Giving someone a certain amount of exp?

Discussion in 'Plugin Development' started by CandyCranium, Mar 11, 2014.

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

    CandyCranium

    I'm currently trying to give someone a certain amount of exp when they kill someone, but I'm not sure how this works. I'm not trying to set their level, but trying to give them exp. Does it have anything to do with e.getEntity().getPlayer().getKiller().getExp()...?
     
  2. Offline

    Wizehh

  3. Offline

    CandyCranium

    Wizehh
    This is my current code:
    Code:java
    1.  
    2. e.getEntity().getPlayer().getKiller().setExp(e.getEntity().getPlayer().getKiller().getExp() + 2);
    3.  

    I'm trying to make it so that each kill, the player will get 2 exp orbs automatically added to their exp bar, but when I do this, it glitches the exp bar out, and when I give myself 0 exp, it seems that the 2 exp given is actually 2 levels given.

    Does anybody know how to fix?

    I still need help if anybody can help me.

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

    Onlineids

    Trying setting exp to be equal to a variable and after every kill set that variable to exp+2
     
  5. Offline

    Amgis

    CandyCranium

    Code:java
    1. public void setExp(Player player, int exp) {
    2.  
    3. player.setTotalExperience(0);
    4.  
    5. player.giveExp(exp);
    6. }
    7.  
    8. public void giveExp(Player player, int exp) {
    9.  
    10. player.giveExp(exp);
    11. }
    12.  
    13. @EventHandler
    14. public void onEntityDeath(EntityDeathEvent event) {
    15.  
    16. Player player;
    17.  
    18. if(event.getEntity() instanceof Player) {
    19.  
    20. player = (Player) event.getEntity();
    21.  
    22. giveExp(player.getKiller(), expToGive);
    23. // expToGive = whatever value you want
    24. }
    25. }
     
  6. Offline

    Maurdekye

    CandyCranium Player#setExp() takes a float between 0 and 1, representing the percentage filled the exp bar is. Player#setLevel() takes an int, and changes the green exp number, not affecting the bar at all. They're completely different things; the game just handles what to set them to when you pick up an exp orb. If you want to give players an exp orb when they kill someone, just spawn the entity at their feet instead of manually increasing their exp level.
     
  7. Offline

    CandyCranium

    Found out how:
    Code:java
    1.  
    2. e.getEntity().getPlayer().getKiller().giveExp((int) 1.0);
    3.  

    Thanks for everybody who helped!
     
Thread Status:
Not open for further replies.

Share This Page