XP

Discussion in 'Plugin Development' started by JHA™, Jan 17, 2013.

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

    JHA™

    Hey Guys,
    I already asked someone about this and they were sort of unsure and I wanted to save them the time of helping me if they weren't positive. Iam making a plugin and it will kind of have a shop sort of thing but via XP. So when you run a command you would lose XP. I was wondering if you could do anything to do this. I tried adding negative XP but that doesn't work. I was suggested a algorithm but I would like to be positive before I make one because the levels seem to be done in no sort of order at all. Thanks,
    ~JHA
     
  2. Offline

    william9518

    they are done as percentage values. so 0 would be no xp, 0.99 would be 1 xp to lvl up.
    1 would be leveled up. Then it reverts back to 0. How MC deals with gaining less XP at higher level is probably something like xp / level or soemthing like that
     
  3. Offline

    JHA™

    When I give someone XP it is done by Orbs.
    Code:
    e.getEntity().getKiller().giveExp(17);
    I don't know of any other methods. And I also am trying to take away XP from the player when they run a command. Thanks anyway.
     
  4. Offline

    william9518

    so do this:
    e.getEntity().getKiller().setExp(e.getEntity().getKiller().getExp() - ([REMOVING XP COMMAND INT] / 100));
    That is a calculation. Gets the xp
     
  5. Offline

    danthonywalker

    Oh, your trying to get orbs from a EntityDeathEvent.

    Why not just do player.giveExp(Integer); or player.giveExpLevel(Integer)?
     
  6. Offline

    fireblast709

    william9518 danthonywalker no he is trying to remove absolute xp points (so no floats, just integers. Also, from the total amount, not the xpbar)
     
  7. Offline

    JHA™

    This:
    I found out how this is done and thought I would share since some of you were un-sure.
    First you need both of these.

    Code:
    Player player = (Player)sender;
    int xp = player.getLevel();
    Code:
        if ((commandLabel.equalsIgnoreCase("jumphigh"))){//Is command typed is equal to but ignore caps jumphigh
            if(((player.hasPermission("test.jumphigh")) || (player.isOp()))) {//And player has permission test.jumphigh or you are op
                if(!(xp<10)){//If your xp level is not less than the price of the item.
                    player.setLevel(xp-10);//Then subtract the price for command
                    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1200, 10));//Give them potion
                }else{
                    player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 0));//If they don't qualify then give them this potion effect
                    player.sendMessage("You cannot afford this.");//And this message
                }
            }
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  8. Offline

    william9518

    thx, but always return false if command encounter prpblem, and true if it worked. If u dont return, probl ms occur.
     
  9. Offline

    ImTheFool

Thread Status:
Not open for further replies.

Share This Page