Kill count scoreboard

Discussion in 'Plugin Development' started by PHILLIPS_71, Apr 14, 2013.

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

    PHILLIPS_71

    I'm wanting to make a scoreboard that will count the amount of mobs you kill and also cout your deaths i know there is a tutorial on this but the setDisplaySlot does not work at all and setting the display name also does not work this is a test one so it not perfect i'm only using this just to stuff around with then later change it.

    This is the CB i'm using craftbukkit-1.5.1-R0.2-20130405.175708-7

    The error coming up in red are
    First line: setDisplaySlot the . between DisplaySlot.SIDEBAR
    Second line: . between objective.setDisplayName and "ScoreBoard"
    Code:
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    objective.setDisplayName("ScoreBoard");
    The whole code
    Code:
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
     
    public class core extends JavaPlugin implements Listener {
     
        public void onEnable()
        {
            getServer().getPluginManager().registerEvents(this, this);
        }
     
    ScoreboardManager manager = Bukkit.getScoreboardManager();
    Scoreboard board = manager.getNewScoreboard();
    Objective objective = board.registerNewObjective("test", "mobkills");
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    objective.setDisplayName("ScoreBoard");
    Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Kills:"));
     
     
     
    }
    
     
  2. Offline

    Tzeentchful

    PHILLIPS_71 You have to send it to the player(s) you want it to be displayed to.
    Code:java
    1. for(Player current : Bukkit.getOnlinePlayers()){
    2. current.setScoreboard(board);
    3. }
     
  3. Offline

    PHILLIPS_71

    Tzeentchful
    Ahh yeah i forgot that but im still getting those errors you know why? this is what i have now

    Code:
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
     
    public class core extends JavaPlugin implements Listener {
     
        public void onEnable()
        {
            getServer().getPluginManager().registerEvents(this, this);
        }
     
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        Scoreboard board = manager.getNewScoreboard();
     
        Objective objective = board.registerNewObjective("test", "mobkills");
        objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
        objective.setDisplayName("ScoreBoard");
        Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Kills:"));
     
        for(Player current : Bukkit.getOnlinePlayers()){
            current.setScoreboard(board);
        }
    }
    }
    
     
  4. I see what you did there, you didn't put the code inside a method, but you just copy paste it
     
  5. Offline

    PHILLIPS_71

    ferrybig
    i did have a method but is was wrong what is the method then?
     
  6. Offline

    Tzeentchful

    Code compiles fine for me. What does the error say when you hover over it?
     
  7. Offline

    PHILLIPS_71

    Tzeentchful
    Syntax error on token "setDisplaySlot" identifier expected after this token
     
  8. you put the code directly insid ethe class, I dont see a methode where you placed the code in? inside java, code that modifes variables mostly need to put inside methodes, it wont work when put directly inside a class without a methode
     
  9. Offline

    PHILLIPS_71

    ferrybig
    I had a method then i removed it as it did not work then i made this thread.
     
  10. Offline

    Tzeentchful

    Your coed is't in any method. it's just in limbo in you class.

    This should work.
    Code:java
    1.  
    2. public void onEnable() {
    3. getServer().getPluginManager().registerEvents(this, this);
    4. showScoreboard();
    5.  
    6. }
    7.  
    8. public void showScoreboard(){
    9. ScoreboardManager manager = Bukkit.getScoreboardManager();
    10. Scoreboard board = manager.getNewScoreboard();
    11.  
    12. Objective objective = board.registerNewObjective("test", "mobkills");
    13. objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
    14. objective.setDisplayName("ScoreBoard");
    15. Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Kills:"));
    16.  
    17. for(Player current : Bukkit.getOnlinePlayers()){
    18. current.setScoreboard(board);
    19. }
    20. }
    21.  
     
    PHILLIPS_71 likes this.
  11. Offline

    PHILLIPS_71

    Tzeentchful
    Ahh works thanks so much but the only thing is it is not showing the scoreboard

    i have changed some minor things
    Code:
        public void showScoreboard(){
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
     
            Objective objective = board.registerNewObjective("test", "dummy");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName("ScoreBoard");
            Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Kills:"));
            score.setScore(1);
     
            for(Player current : Bukkit.getOnlinePlayers()){
                current.setScoreboard(board);
            }
        }
     
  12. Offline

    Tzeentchful

    It's most likely because it only being run in the onEnable. Try adding a join event listener and run the showScoreboard() method in it.
     
  13. Offline

    PHILLIPS_71

    Tzeentchful
    Ok i have never done that before how do i do it?
     
  14. Offline

    Tzeentchful

    Well i see you already have "implements Listener" in your class deceleration.
    there is a great set of tutorials on bukkit features like this that go over this stuff in depth.
    here is how you do a player join event listener.
    Code:java
    1.  
    2. @EventHandler
    3. public void onJoin(PlayerJoinEvent event) {
    4. showScoreboard(event.getPlayer());
    5. }
    6.  


    I changed the showScoreboard() method a bit so it only does it for the player who joined
    Code:java
    1.  
    2. public void onEnable() {
    3. getServer().getPluginManager().registerEvents(this, this);
    4.  
    5. for(Player current : Bukkit.getOnlinePlayers()) {
    6. showScoreboard(current);
    7. }
    8. }
    9.  
    10.  
    11. }
    12. public void showScoreboard(Player player) {
    13. ScoreboardManager manager = Bukkit.getScoreboardManager();
    14. Scoreboard board = manager.getNewScoreboard();
    15.  
    16. Objective objective = board.registerNewObjective("test", "mobkills");
    17. objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
    18. objective.setDisplayName("ScoreBoard");
    19. Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Kills:"));
    20. player.setScoreboard(board);
    21. }
    22.  


    You might want to store the scoreboard for each player in a hash map or something so you can easily get it later.
     
  15. Offline

    PHILLIPS_71

    Tzeentchful
    Still not working for some reason but thanks for giving me the links i'm looking at it now

    This is what i have let me know if its wrongs thanks for all the help.
    Code:
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
     
    public class core extends JavaPlugin implements Listener {
     
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
     
            for(Player current : Bukkit.getOnlinePlayers()) {
                showScoreboard(current);
            }
        }
     
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            showScoreboard(event.getPlayer());
        }
     
     
     
        public void showScoreboard(Player player) {
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
     
            Objective objective = board.registerNewObjective("test", "mobkills");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName("ScoreBoard");
            Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Kills:"));
            player.setScoreboard(board);
        }
    }
    
     
  16. Offline

    PHILLIPS_71

    Anyone have any idea why?
     
  17. Offline

    macguy8

    PHILLIPS_71
    I'm not sure, but I'm ~50% sure you need to set a value for your score (score.setScore(1)) for it to show up

    EDIT: If you don't want to start it at one, use score.setScore(0)
     
  18. Offline

    PHILLIPS_71

    macguy8
    I have tried that this is what i have now

    Code:
        public void showScoreboard(Player player) {
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
            player.setScoreboard(board);
     
            Objective objective = board.registerNewObjective("test", "totalKillCount");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName("ScoreBoard");
            Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Kills:"));
            score.setScore(0);
        }
    
     
  19. Offline

    nitrousspark

    Bukkit.getOfflinePlayer(ChatColor.GREEN + "Kills:") ?
     
  20. Offline

    PHILLIPS_71

    nitrousspark
    I have that already.


    Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Kills:"));
     
  21. Offline

    nitrousspark

    but it makes no sense
     
  22. Offline

    PHILLIPS_71

  23. Offline

    PHILLIPS_71

    I have stuffed around with it a little more and still not working anyone have any idea what could be wrong?
     
  24. Offline

    kreashenz

    PHILLIPS_71 Go take a look at xScores source, it has exactly what you need done.
     
  25. Offline

    PHILLIPS_71

  26. remove the "Bukkit.getOfflinePlayer" part , even though it says it needs it it doesnt , also try the 1.8 or 1.7.9 API.

    removeing that should make it work since you cant display a player on the scoreboard , only their name.

    So its basically just a String inside there.
     
Thread Status:
Not open for further replies.

Share This Page