Solved Displaying the ScoreBoard

Discussion in 'Plugin Development' started by kmccmk9, Jul 16, 2013.

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

    kmccmk9

    Hello, I can't seem to get the scoreboard to show. What am I doing wrong? This is my code.
     
  2. Offline

    chasechocolate

    kmccmk9 it's a private paste, make it public for us to be able to view it.
     
  3. Offline

    kmccmk9

    Sorry it should be fixed now.
     
  4. Offline

    soulofw0lf

    from what i've seen at no point do you add players to teams or send them the scoreboard, which both things are needed.
     
  5. Offline

    kmccmk9

    Does this not do what you mentioned?
    Code:java
    1. team.addPlayer(player);
    2. team.setPrefix("ZS-");
    3. team.setAllowFriendlyFire(false);
    4. player.setScoreboard(board);
    5. player.sendMessage(ChatColor.YELLOW + "You have been adde to the team!");
     
  6. Offline

    soulofw0lf

    it does, i somehow missed that command entirely

    kmccmk9 have i also missed where you set the score?

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

    kmccmk9

    That I do not have. Although I was gonna add it in later so the command would be repeatable. Should I try adding that in that command function?
     
  8. Offline

    soulofw0lf

    you need to at least set an initial score or this is nothing to display
    here's a snipit from my load boards method i use in one of my minigames

    Code:java
    1. public static void loadBoards(){
    2. KeyStone.manager = Bukkit.getScoreboardManager();
    3. KeyStone.board = KeyStone.manager.getNewScoreboard();
    4. KeyStone.zealTeam = KeyStone.board.registerNewTeam("Zealots");
    5. KeyStone.zealTeam.setAllowFriendlyFire(false);
    6. KeyStone.zealTeam.setCanSeeFriendlyInvisibles(true);
    7. KeyStone.zealTeam.setPrefix(ChatColor.DARK_RED + " ");
    8. KeyStone.zealTeam.addPlayer(Bukkit.getOfflinePlayer("Zealots"));
    9. KeyStone.zealTeam.addPlayer(Bukkit.getOfflinePlayer("Zealot Lives"));
    10.  
    11. KeyStone.guardTeam = KeyStone.board.registerNewTeam("Guardians");
    12. KeyStone.guardTeam.setAllowFriendlyFire(false);
    13. KeyStone.guardTeam.setCanSeeFriendlyInvisibles(true);
    14. KeyStone.guardTeam.setPrefix(ChatColor.GREEN + " ");
    15. KeyStone.guardTeam.addPlayer(Bukkit.getOfflinePlayer("Guardians"));
    16. KeyStone.guardTeam.addPlayer(Bukkit.getOfflinePlayer("Guardian Lives"));
    17.  
    18. KeyStone.obj = KeyStone.board.registerNewObjective("Points", "Dummy");
    19. KeyStone.obj.setDisplayName(ChatColor.GOLD + "Total Points");
    20. KeyStone.obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    21. Score score = KeyStone.obj.getScore(Bukkit.getOfflinePlayer("Zealot Lives"));
    22. score.setScore(KeyStone.reinforcements);
    23. Score score1 = KeyStone.obj.getScore(Bukkit.getOfflinePlayer("Guardian Lives"));
    24. score1.setScore(KeyStone.reinforcements);
    25. }


    @kmccmk9 then after the boards are initially loaded all you have to worry about is setting players to teams to add them to it, instead of by command i just load mine on enable and clear players from it if they're not in the active game.

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

    kmccmk9

    Okay so I added this code: (Hope it works!)
    Code:java
    1. Score member;
    2. ((Score) player).setScore(0);
     
  10. Offline

    soulofw0lf

    kmccmk9 let me know how it works, i've never tried casting a player to a score before.
     
  11. Offline

    kmccmk9

    Ya it wouldn't let me without it.

    Didn't work. I have to do something like you did, although how do I just get the player's score? Because you are using some kind of database/list/storage system right?

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

    soulofw0lf

    1. Score score = objective.getScore(Bukkit.getOfflinePlayer(player.getName()));
    2. score.setScore(0);
    kmccmk9 just set their initial score to 0. it will auto update scores on kills i believe. otherwise you can get their score with score.getScore(); if you need to update it through a listener.
     
  13. Offline

    kmccmk9

    But what is this?
    KeyStone.obj.getScore

    I just want the score of player.
     
  14. Offline

    soulofw0lf

    @kmccmk9 i updated the post right after i posted it, Keystone.obj was just a static reference to the Objective obj; defined in the main class of my plugin.
     
  15. Offline

    kmccmk9

    Oh sorry I didn't see that. Okay so what happens if the player is online though?
     
  16. Offline

    soulofw0lf

    online players are still offline players i believe the reason they made the scoreboards only accept the offline player was so it wouldn't break if people logged out and weren't removed.
     
  17. Offline

    kmccmk9

    Ok great it works now thanks!
     
  18. Offline

    soulofw0lf

    np make sure you change the post to solved.
     
Thread Status:
Not open for further replies.

Share This Page