Getting player ingame level

Discussion in 'Plugin Development' started by Scorpionvssub, Jul 29, 2015.

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

    Scorpionvssub

    Im trying to check if a player has level 100 or up to then do something and subtract those 100 levels.


    Tried several methods to complete this but every if seems to not be valid
    Code:
                Player player = getServer().getPlayer(getName());
                String level = valueOf(player.getLevel());
                getConfig().set("Settings.level", level);
                if (getConfig().getString("Settings.level") >= "100") {
    Code:
                Player player = getServer().getPlayer(getName());
                String level = valueOf(player.getLevel());
                if (level.valueof(100)) {
    And quite a few other ways but none seem valid, it asks either bout some binary format or an int but that seems to me like that wouldnt do what i want it to do. which is checking if a person has 100 xp levels then subtract those.
     
    Last edited: Jul 29, 2015
  2. Moved to Plugin Development.

    Use the report button and we can move it.
     
  3. Offline

    Scorpionvssub

    oohhh thought that was for something else haha thanks @bwfcwalshy
     
  4. Offline

    khave

    You're trying to get a string and compare it to an integer. That's not how it works. Do getConfig().getInt("Settings.level").
    Unless you're meaning his experience level? In that case it's player.getLevel()
    Also don't do "100" that makes it a String. Just use 100.
    If not for that your first code snippet was correct.
    I don't know where you're getting the valueOf or the getName method though.
    Code:
    Player player = getServer().getPlayer(getName());
                int level = player.getLevel(); //Get the level
                getConfig().set("Settings.level", level);
                if (level > 100) {// Check if it's over 100
    I don't know why you're saving it to a config and then getting it from there either.
     
  5. Offline

    Scorpionvssub

    @khave idk someone suggested it and so yea... X) but yea i told him i want a way around the config as its indeed just set grab and do 1 check with it and then the next person using the command can be set. haha Yours seems exacly what im after ill try thatr :)

    @khave or anyone, Can someone elabirate on this settotalexperience for me, i wanna take those 100 lvls but to me set is setting something and not "taking"or calculating current lvl - 100 any suggestiosn idea's etc?

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

    khave

    To set their level you just use the player.setLevel(), and to set their experience you just do player.setExperience() (Sets their experience to the level). To take away one hundred levels you would do player.setLevel(player.getLevel() - 100);
     
Thread Status:
Not open for further replies.

Share This Page