Decrease player experience over time

Discussion in 'Plugin Development' started by KyleZero1, Jun 30, 2012.

  1. Offline

    KyleZero1

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Hello, I need help to decrease the amount of exp a player has by 4 every 15 seconds.
    How would I go about doing this?
    I would prefer that the timer starts when the player logs in.
    If that doesn't work, then its fine
    Thank you very much!
  2. Offline

    KyleZero1

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Anyone? I really need this...
  3. Offline

    bartboy8

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Use a sceduled timer. Then in there just define a variable for the player. Im not quite sure how to decrease xp but im sure its not too hard.
  4. Offline

    Cirno

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Do what @bartboy8 said, use a sceduled timer. Then just set the XP decresed by 4. Like (not actual code)
    Code:
    setXP(player.getXP() - 4)
  5. Offline

    LucasEmanuel

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Untested code and just something i pulled out of my head, i could very well have done it wrong with the methods.
    But it should run every 15 seconds and you only have to initiate it once. This is way better performance wise compared to your idea of creating a new schedule for each player.


    Code:
    server.getScheduler().scheduleSyncRepeatingTask(new Runnable() {
        public void run() {
            for(Player player : server.getOnlinePlayers()) {
                player.setTotalExperience(player.getTotalExperience() - 4);
            }
        }
    }, 300L);
  6. Offline

    KyleZero1

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Edit: I got it working, here is the code
    Code:
    this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    public void run() {
    for(Player player : Bukkit.getServer().getOnlinePlayers()) {
    if(player.getExp() > 0) {
    player.giveExp(- 4);
    } else {
    player.setLevel(player.getLevel() - 1);
    if(player.getLevel() < 1) {
    player.setHealth(0);
    }
    }
     
    }
     
    }
    },20L, 1200L);

    This post has been edited 2 times. It was last edited by KyleZero1 Jul 1, 2012.
  7. Offline

    pzxc

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Lol -- doesn't that kill them immediately if they have no experience and are level one?
  8. Online

    -_Husky_-

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Just a question what does that L in 300L represent?
  9. Offline

    ferrybig

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    it means long, so it creates an number that is 300 and of type Long
  10. Online

    -_Husky_-

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    And a long into a second = ?
  11. Offline

    ferrybig

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    depends on what unit the long represends, somethimes you can use an long to detonate ticks, seconds or miliseconds
    Its like saying: what is 1 in seconds, whitout knowing if 1 is days or weeks or that

    This post has been edited 1 time. It was last edited by ferrybig Jul 1, 2012.
    -_Husky_- likes this.
  12. Offline

    LucasEmanuel

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    A long is simply another datatype in Java, like the Integer except it supports way bigger values.
    -_Husky_- likes this.

Share This Page