Solved Scoreboard won't increment score

Discussion in 'Plugin Development' started by multikus, May 8, 2014.

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

    multikus

    Hello,
    I have a tricky problem with scoreboards. Basically I want to add 1 point to the scoreboard every time a player dies. It adds 1 point, and then it stops. I hope someone can help me out...

    Code:java
    1. private Scoreboard board;
    2. private Objective o;
    3. private Score deaths;
    4.  
    5. //Have this code inside the onEnable method
    6. ScoreboardManager manager = Bukkit.getScoreboardManager();
    7. board = manager.getNewScoreboard();
    8. o = board.registerNewObjective("test", "dummy");
    9.  
    10. o.setDisplaySlot(DisplaySlot.SIDEBAR);
    11.  
    12.  
    13. @EventHandler
    14. public void onMove(PlayerMoveEvent event){
    15. Player player = event.getPlayer();
    16. player.setScoreboard(board);
    17.  
    18. deaths = o.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "Deaths:"));
    19. }
    20. @EventHandler
    21. public void onkill(PlayerDeathEvent event){
    22. deaths.setScore(1); //Also tried to do +1, nothing there either
    23. }
     
  2. Offline

    Garris0n

    I feel like it's pretty clear that "setScore(1)" sets the score to 1. How exactly is this not the expected outcome?
     
  3. Offline

    multikus

    Garris0n Well, I've checked threads about how to make a killcounter/deathcounter with scoreboards, and all of them used "setscore". Haven't found anything else...
     
  4. Offline

    Garris0n

    Yes, to set the score. Not to add anything to the score. Think about this:

    x = 1;

    See, now x is 1.

    Now if I say "x=1" again, x is still 1. Because I set it equal to 1. It doesn't become 2, it becomes 1, because I set it to 1. Now if I were to say "x = x + 1", x would become 2. And so on.
     
  5. Offline

    multikus

    Garris0n
    What should I then use to increment the number of deaths every time a player dies, shown on a scoreboard for every user?
     
  6. Offline

    Dubehh

    multikus

    ' SetScore(GetScore +1) ' something like that.
    And then update the scoreboard. :)
     
  7. Offline

    multikus

    Dubehh
    How didn't I come up with that... thanks :)
     
Thread Status:
Not open for further replies.

Share This Page