Scoreboard [Need Help]

Discussion in 'Plugin Development' started by Josh014, Oct 5, 2013.

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

    Josh014

    Hey,
    I'm using the scoreboard feature to get a players killstreak. I made this code but it shows the players name in the bar instead of "kills:" name in the bar. And I want that every player has his own scoreboard.

    I made this code,

    PlayerDeathEvent code:
    Code:java
    1. @EventHandler
    2. public void Killstreak(PlayerDeathEvent event){ //killStreak
    3. //Scoreboard
    4. ScoreboardManager manager = Bukkit.getScoreboardManager();
    5. Scoreboard board = manager.getMainScoreboard();
    6. //objecive
    7. Objective streak = board.getObjective("killStreak");
    8. Player player = event.getEntity().getPlayer();
    9. Player killer = event.getEntity().getKiller();
    10. if(player instanceof Player){
    11. if(killer.hasPermission(new Permisssions().KillStreak)){
    12. Score killerS = streak.getScore(Bukkit.getOfflinePlayer(ChatColor.WHITE + "Kill Streak" + ChatColor.RED + ":"));
    13. int kills = killerS.getScore();
    14. int add = 1;
    15. int killsStreakTotal = kills+add;
    16. killerS.setScore(killsStreakTotal);
    17. killer.sendMessage(ChatColor.BLUE + "You are on a kill streak of " + ChatColor.GOLD + killsStreakTotal + "" + ChatColor.BLUE + "!");
    18. killer.setScoreboard(board);
    19. }
    20. }
    21. }


    PlayerJoinEvent code:
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent e) {
    3. Player p = e.getPlayer();
    4. ScoreboardManager manager = Bukkit.getScoreboardManager();
    5. Scoreboard board = manager.getNewScoreboard();
    6. Objective objective = board.registerNewObjective("killStreak", "deathCount");
    7. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    8. objective.setDisplayName(ChatColor.RED + p.getName());
    9. Score k = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.WHITE + "Kill Streak" + ChatColor.RED + ":"));
    10. k.setScore(0);
    11. p.setScoreboard(board);
    12. }


    How can I get for each player his own scoreboard for his kills, deaths and kill streak?

    Edit:
    When a player leaves or dies, only his kill streak will be reset to 0.

    chasechocolate
    I saw your Scoreboard tutorial and maybe you could help me with this?

    Does no one know this? :confused:?

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

    CraftBang

    It's something with hashmapping :

    (I didn't figure out yet how to use this)
    and saving them:


    But you should also remake it so it works with kills.
    Try to search around here in topics for killstreaks.
    I also found this:
    http://forums.bukkit.org/threads/having-kills-saved.175574/#post-1856194

    Maybe try to mix up the codes and you could figure it out!
    (And if you figured it out, please post it on the forums so also other people can learn from this ) !

    I use this for kills :
    //kills thingey
    @EventHandler(priority = EventPriority.HIGHEST)
    public void onPlayerDeath(PlayerDeathEvent event) {
    if (event.getEntity().getKiller() instanceof Player) {
    Player killer = event.getEntity().getKiller();
    Player victim = event.getEntity();
    if (!kills.containsKey(killer.getName()))
    kills.put(killer.getName(), 0);
    if (!kills.containsKey(victim.getName()))
    kills.put(victim.getName(), 0);
    kills.put(killer.getName(), kills.get(killer.getName()) + 1);
    }
    }
    //kills thingeydone

    And in the class I create this hashmap :

    public HashMap<String, Integer> kills = new HashMap<String, Integer>();

    Just need to figure out how to save it to a file.

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

    niber

    Saving a hashmap to a text file will be the easiest way to go. I wrote a warping plugin today where I did that. I don't have the code with me as I am not on my laptop but I am sure you can figure this out. It consists of a piece of code to write the file (You execute this in the onDisable function) and a piece of code to read the file (onEnable function).
     
  4. Offline

    Josh014

    CraftBang
    niber
    Alright... I never worked with HasMaps :3 I watched the video you sent to me but still I'm a bit confusing about HasMaps. Is there another way to do the kill streaks?
     
  5. Offline

    Josh014

    Bump ;o
     
  6. Offline

    CraftBang

  7. Offline

    Josh014

    CraftBang alright thank you :D. I will keep an eye on it :).
     
Thread Status:
Not open for further replies.

Share This Page