Solved Exp - How does it work?

Discussion in 'Plugin Development' started by number1_Master, Feb 21, 2013.

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

    number1_Master

    I'm working on a plugin which involves removing experience, but I'm very confused on how the methods for this work!
    Here are the methods for getting experience:
    Code:java
    1. Player player = (whatever).getPlayer();
    2.  
    3. player.getTotalExperience(); // returns the experience in levels
    4. player.getExp(); // returns the experience as a float, not as a level
    5. player.getExpToLevel(); // returns the experience in levels, like above
    6. player.getLevel(); // returns the experience in levels, like the above two
    7.  
    8. player.setTotalExperience(player.getTotalExperience() - amount); // removes x levels of experience
    9. player.setExp(player.getExp() - amount); // removes x experience in float
    10. player.setTotalExperience(player.getExpToLevel() - amount); // removes x levels of experience, like above
    11. player.setLevel(player.getLevel() - amount); // removes x levels of experience, like above
    12.  


    Does each method return what I think it returns? If so, what are the differences between getTotalExperience(), getExpToLevel(), and getLevel() ? What is the difference?

    Thanks in advance!

    Edit: Please don't link me to the Docs. I've read them three times now. The question isn't exactly the definition of the method, but what the differences is in using the different methods.
     
  2. I would like to know this also. I had a good idea today and I was wondering how to do this.
     
    number1_Master likes this.
  3. Offline

    Erigitic

    This page will help you out: Player API. The Bukkit API is always a good thing to take a look at when coding plugins. It will tell you what each method does.
     
  4. Offline

    RealDope

    JavaDocs are your friend. Go look at each of these methods under the Player object, it explains them all.

    Code:JAVA
    1.  
    2. player.getLevel(); // Returns what the player's level is
    3. player.getExp(); // Returns how much exp the player has towards the next level
    4. player.getTotalExperience(); // All experience the player has, converts all levels to exp and adds on how much exp the player has towards the next level
    5. player.getExpToLevel(); // Either how much MORE the player needs to level or how much TOTAL the player needs to level, not sure which
    6.  
     
  5. Offline

    number1_Master

    Yes, I looked at that already, but each of the four methods respond with the same text. "Gets the players current experience level."

    What is the difference?

    Edit: Much more clear now. When I read it, it all looked the same to me.
    Still, what would be the proper way to subtract experience? getLevel() - amount ?
     
  6. Offline

    Erigitic

    Do you want to remove all the experience?
     
  7. Offline

    number1_Master

    Read the main post next time before you ask that question.
     
  8. Offline

    Erigitic

    Do you want to remove all the experience or a set amount? Was not clear enough which is why I asked. Do not want to give you the wrong information.
     
  9. Offline

    number1_Master

     
  10. Offline

    Erigitic

    I'm trying to help you here. But because you will not answer the question I will just guess that you want to remove a set amount of EXP. This should work:
    Code:
    player.setTotalExperience(player.getTotalExperience() - AMOUNT);
    .
     
  11. Offline

    number1_Master

    Even though you gave me a correct answer, for not knowing what I'm asking for (come on, I even bolded the answer):

    [​IMG]
     
  12. Offline

    Erigitic

    I like to make sure that I am understanding what is being asked before I go about giving people code. I would rather give you correct code then the wrong code. Their is no need to be rude, I am just trying to help you after all. Best of luck with your plugin.
     
  13. Offline

    number1_Master

    It isn't a first you know. I'm a well experience plugin developer. It sounds like you are treating me like a noob.
    Even so, it doesn't sound like you read my post. I mentioned 'removing x levels' various times and even posted some code which I think would work, yet you had no clue what was going on!

    My question wasn't really how to subtract experience, it was which method would work. Although that isn't too evident, you really need to read posts more carefully next time. You would of understood what I was asking for.
     
  14. Offline

    Erigitic

    I apologize if I made you feel that way, was not my intention.
     
    number1_Master likes this.
  15. Offline

    number1_Master

    Apology excepted.
     
  16. Offline

    RealDope

    Now for the make-up sex.
     
  17. Offline

    number1_Master

    [​IMG]
     
  18. Offline

    RealDope

    That picture doesn't load for me :mad:
     
  19. Offline

    number1_Master

    Fixed :p
     
  20. Offline

    Frazz86

    RealDope
    Actually i do believe getExp() gets how much experience you've gained for this current level, getExpToLevel get experience left to level and getTotalExperience gets all experience gained in all levels so far.
     
  21. Offline

    RealDope

    Maybe I worded it funny, but I thought that's exactly what I said Frazz86
     
  22. Offline

    number1_Master

    so getExp gets the experience for the currnet level
    getExpToLevel gets the next level
    getTotalExperience gets all the experience in your hotbar, not levels? or does it both
     
  23. Offline

    Erigitic

    getTotalExperience() returns the total amount of experience that the player has, it does not return the amount of levels. getLevel() will return the level that the player has.
     
  24. The javadoc of the methods are explaining them just fine... but if you want a rephrase:

    getExp() is the progress bar to the next level, no actual exp values are returned, it's just from 0.0 to 1.0... as in 0% to 100%.


    getTotalExperience() is the total amount of experience points the player has, this value can be used to calculate which level the player is but it would be pointless because you have getLevel().


    getExpToLevel() returns the amount of xp needed to level up.


    getLevel() is obviously the level of experience (not height level, not power level but experience level !), the same value you see in your HUD and the same value you trade for enchants and stuff.


    So I don't know what you've read in the javadocs 3 times but it was there all along in plain english.



    For removing exp... I'm not sure if this trick still works, someone showed it to me and I don't remember who but here it is:
    Code:
    int xp = player.getTotalExperience(); // store xp points
    int amount = -100; // subtract 100 exp
    
    // clear player's levels so giveExp() recalculates them
    player.setTotalExperience(0);
    player.setLevel(0);
    
    player.giveExp(Math.max(xp + amount, 0)); // Math.max() to make sure it doesn't go below 0
     
  25. Offline

    number1_Master

    I've figured it out now. I don't know what I was reading in the JavaDocs ... it just seemed different to me ... but I've figured it out now :p

    Edit: Actually, I already figured it out from the start of this thread but I was unsure if I was correct ...
     
  26. number1_Master
    If you mean the comments from the code in the first post, then no, you didn't get it at all.

    getLevel() is the only method that has anything to do with levels, getExp() is a progress bar, has nothing to do with levels nor experience points... and the other two are raw experience points ! The little orbs you pick up, those give you points.

    And setting experience lower than what the player's level is won't down-level him, you need to re-calculate his level OR use what I posted :p
     
  27. Offline

    number1_Master

    Yes, I know wat experience is ... and the entire point of this thread was to confirm my thoughts on getting experience via the Craftbukkit API ... and yes, I knew from the start that I needed to recalculate the player's level then set it ...

    The entire time, I was wondering if what I thought the definition of the methods were was correct ...
     
  28. Offline

    NemesisMate

    number1_Master
    Did you get how does this methods really works?, I'm trying some code with them but nothing, they do strange things.
    I can't transform Levels to exp.
     
  29. Offline

    number1_Master

    What do you mean you cannot transform Levels to exp? Sorry, it seems unclear.
     
  30. Offline

    NemesisMate

    number1_Master

    What I'm trying is to give/remove levels to a player (giving it in levels), for example, give a player 10 levels or remove him 10 levels. I tried on lot of ways but nothing, I got the exp gave but not removed, the levels gave but the players hadn't really the exp of that levels and many other results but the correct.

    So I would like to know how just do that, give a player some levels or remove him that levels (having the correspondent experience updated too, of course)
     
Thread Status:
Not open for further replies.

Share This Page