How do I make a Scoreboard that shows per-player stats?

Discussion in 'Plugin Development' started by gabrielmaennl55, May 18, 2014.

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

    gabrielmaennl55

    Hello I'm sure I asked this question before but
    How do we make scoreboards that lets say displays on the sidebar
    And it shows The players personel stats? Like eg Health and EnemyHealth and Stamina or Mana?
    Stuff like that but it's like a Per-Player scoreboard?
    If anyone could tell me how to do this that'll be great Thanks!
     
  2. Offline

    thomasb454

    On PlayerJoinEvent get the player, set the scoreboard to that player & using the same player get the stats and apply them to the scoreboard?
     
  3. Offline

    gabrielmaennl55

    Hmm ok
    May I sorta have an egsample? Or like how would I create the scoreboard? thomasb454
     
  4. Offline

    thomasb454

  5. thomasb454
    How would i set a scoreboard to a player?
     
  6. Offline

    TGRHavoc

  7. TGRHavoc
    Ok and do i make the scoreboard in an event handler when a player joins? or on the OnEnable AND event handler or Just onEnable

    TGRHavoc
    Also would i have to create a new team for each player?

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

    TGRHavoc

    gabrielmaennl555
    I would create a new scoreboard when the player joins (Makes sure that it is only displayed to them)
     
  9. Offline

    gabrielmaennl55

  10. TGRHavoc
    I made this but it dosnt work
    Code:java
    1. //SCOREBOARD HANDLER=======================================================
    2. @EventHandler
    3. public void playerJoin(PlayerJoinEvent event)
    4. {
    5. Player player = event.getPlayer();
    6.  
    7. {
    8. ScoreboardManager manager = Bukkit.getScoreboardManager();
    9. Scoreboard board = manager.getNewScoreboard();
    10. Objective objective = board.registerNewObjective("health", "dummy");
    11.  
    12. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    13. objective.setDisplayName("Health");
    14. Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Kills:")); //Get a fake offline player
    15. score.setScore((int) player.getHealth());
    16. player.setScoreboard(board);
    17.  
    18.  
    19. }
     
  11. Offline

    gabrielmaennl55

    Anyone help?
     
  12. Offline

    Phantom_64

    Example: (Shows number of players online)

    Code:java
    1. private Scoreboard sb;
    2.  
    3. public Scoreboard getScoreboard() {
    4.  
    5. return this.sb;
    6.  
    7. }
    8.  
    9. public void setupScoreboard() {
    10.  
    11. sb = getServer().getScoreboardManager().getNewScoreboard();
    12. final Objective obj = sb.registerNewObjective("online players", "dummy");
    13. obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    14. obj.setDisplayName("Number of Players Online");
    15.  
    16. }
    17.  
    18. @Override
    19. public void onEnable() {
    20.  
    21. setupScoreboard();
    22.  
    23. }
    24.  
    25. @EventHandler
    26. public void onJoin (PlayerJoinEvent e) {
    27.  
    28. Player p = e.getPlayer();
    29.  
    30. p.setScoreboard(getScoreboard());
    31. getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(p).setScore(Bukkit.getOnlinePlayers().length);
    32.  
    33. }
     
  13. Offline

    TGRHavoc

    gabrielmaennl55
    Remove the "{" that is floating.... There's no need for it.
     
  14. TGRHavoc
    Oops that was a mistake i removed it but still no result :(
     
  15. Offline

    Maurdekye

    gabrielmaennl55 you would need to create a new scoreboard for each individual player that joins. You would also need a list of some sort to keep track of the scoreboards associated with different players.
     
  16. Offline

    TGRHavoc

    gabrielmaennl555
    Are you getting any stack traces? If so post them. And if you're wanting the values on the scoreboard to change at all, then I would do what Maurdekye said and use a hashmap to store the player's name (or UUID) and the scoreboard.
     
  17. TGRHavoc
    Theres no errors in the console

    Or any messages that have to do with the plugin :( I mustove done something wrong

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

    TGRHavoc

    gabrielmaennl555
    What is it doing? Is it displaying the wrong values? Or, it is just not displaying at all?
     
  19. Offline

    Maurdekye

    gabrielmaennl555 add some print statements around the code, and make sure it's actually being run. Too many times I've had to solve problems for people where the code I've suggested wasn't the problem with theirs.
     
  20. Offline

    gabrielmaennl55

    Nothing*

    Maurdekye Print statements?

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

    TGRHavoc

    gabrielmaennl55
    Yea, System.out.println("Message Here") or Bukkit.getLogger().info("Message Here")
    They both print to the console.
     
    gabrielmaennl55 likes this.
  22. Offline

    Maurdekye

    gabrielmaennl55 You mean to say you don't know what a print statement is?
     
  23. Offline

    gabrielmaennl55

    Maurdekye TGRHavoc
    Ofcourse I know what it means XD
    It prints messages into the console it's just that I have never needed to use it for anything and I forgot the format
    Thanks anyway tho ill do that tomorrow when I wake up then ill reply back here to see if the messages are there
     
  24. Maurdekye TGRHavoc
    Yep it reads but scoreboard still dosnt work
    Code:
    [06:40:54 INFO]: gabrielmaennl5[/110.20.247.133:53493] logged in with entity id --- at ([world] -143.6006600715836, 66.0, 249.27563217782256)
    [06:40:54 INFO]: READING ON PLAYER JOIN!
    [06:40:54 INFO]: READING ON PLAYER JOIN!
    [06:41:17 INFO]: [WorldEdit] Using inbuilt NmsBlock for this version.
    
    bump

    This seems to work but how would i Update the players Health and add a new objective for Enemy Health?
    Code:java
    1. //SCOREBOARD HANDLER=======================================================
    2. @EventHandler
    3. public void playerJoin(PlayerJoinEvent event)
    4. {
    5. Player player = event.getPlayer();
    6.  
    7.  
    8. ScoreboardManager manager = Bukkit.getScoreboardManager();
    9. Scoreboard board = manager.getNewScoreboard();
    10. Objective obj = board.registerNewObjective("health", "dummy");
    11. Objective obj1 = board.registerNewObjective("enemy", "dummy");
    12.  
    13. obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    14. obj.setDisplayName((ChatColor.GREEN + "SP"));
    15. Score score = obj.getScore(Bukkit.getOfflinePlayer(ChatColor.BLUE + "Health:"));
    16. score.setScore((int) player.getHealth());
    17. player.setScoreboard(board);
    18.  
    19. }


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

    TGRHavoc

    gabrielmaennl555
    Code:
    Score enemyHealth = obj.getScore(Bukkit.getOfflinePlayer("Enemy Health"));
    enemyHealth.setScore(Integer);
    To update score you do what you did to set them.
    Code:
    Score enemyHealth = obj.getScore(Bukkit.getOfflinePlayer("Enemy Health"));
    enemyHealth.setScore(Integer);
    enemyHealth.setScore(NewInt); //Sets the score for enemy health to "NewInt"
     
  26. TGRHavoc
    And how would i keep updating the one that displays the Health?
     
  27. Offline

    TGRHavoc

    gabrielmaennl555
    The same way you would when updating the enemys' health....
     
  28. TGRHavoc
    Ok sorry

    TGRHavoc
    Also would i put it in the same PlayerJoinEvent?

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

    TGRHavoc

    gabrielmaennl555
    You would put it in a event that gets fired when the player is damaged (Hint: EntityDamagedEvent (I think))
     
Thread Status:
Not open for further replies.

Share This Page