Team allow friendly fire not working

Discussion in 'Plugin Development' started by Tim4209, Jul 8, 2013.

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

    Tim4209

    Does anyone know why this code don't work?
    Player 1 is in team Test
    Player 2 is in team Test
    Test team has setAllowFriendlyFire set to false.
    Player 1 can attack player 2 and player 2 will recieve damage
    how can i fix this code so there in the same team and can't attack eachother
    using setAllowFriendlyFire?



    Code:
            public Scoreboard board;
       
        public void onEnable() {
            initConfiguration();
            getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
            this.board = Bukkit.getScoreboardManager().getNewScoreboard();
            for (Player player : getServer().getOnlinePlayers()) {
                setTeam(player);
            }
        }
       
        public void setTeam(final Player player) {
            final String teamName = config.getString("Players." + player.getName().toLowerCase() + ".Faction").toLowerCase();
            if (!(teamName == null)) {
                player.sendMessage("Found team from config: " + teamName);
                Team team = board.getTeam(teamName);
               
                if (team == null){
                    team = board.registerNewTeam(teamName);
                    team.setAllowFriendlyFire(false);
                    player.sendMessage("Created new team: " + teamName);
                }
     
                team.addPlayer(player);
                player.sendMessage("You are now in team: " + board.getPlayerTeam(player).getName());
               
            }
        }
    
     
  2. you using more than 1 scoreboard, for player A, only himself is inside his team,
     
  3. Offline

    LinearLogic

    Code:java
    1. if(p1Team.hasPlayer(p2)) {
    2. p1.sendMessage("Player 2 is in the same Team.");
    3. }

    Just add event.setCancelled(true);

    In your setTeam(...) method, you create a new scoreboard, and then a new team from that scoreboard. But you call setTeam(...) for each player, meaning that no two players will actually end up on the same team.

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

    Tim4209

    I think ferry pointed that out and I fixed it on the 2nd one do u see that mistake on the 2nd one?

    bump

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

    LinearLogic

    Code:java
    1. public void setTeam(final Player player) {
    2. final String teamName = config.getString("Players." + player.getName().toLowerCase() + ".Faction").toLowerCase();
    3. if (!(teamName == null)) {
    4. player.sendMessage("Found team from config: " + teamName);
    5. Team team = board.getTeam(teamName);
    6.  
    7. if (team == null){
    8. team = board.registerNewTeam(teamName);
    9. team.setAllowFriendlyFire(false);
    10. player.sendMessage("Created new team: " + teamName);
    11. }
    12.  
    13. team.addPlayer(player);
    14. player.sendMessage("You are now in team: " + board.getPlayerTeam(player).getName());
    15.  
    16. }
    17. }

    Seems you're only disabling friendly fire for teams that don't yet exist. This means setAllowFriendlyFire(false); will never be run on teams that are registered in the config.
     
  6. Offline

    Tim4209

    I'm testing with only 1 team and I kinda found it pointless to go though the config and create each team when there not needed as long as 1 player is on its created so there should never be a problem

    Has anyone tested set allow friendly fire in 1.5.2 wonder if its broke

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

    LinearLogic

    It works in both for me. Make sure you're maintaining references so the players are actually being added to the same team (print out the team members to confirm).
     
  8. Offline

    Tim4209

    Even like this its still working for me, i'm doing reloads and putting everybody on the same team and it shows that everybody is in the blue team and when we attack each other it doesn't stop it.

    Code:
        public void onEnable() {
            initConfiguration();
            getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
            this.board = Bukkit.getScoreboardManager().getNewScoreboard();
            Team blue = board.registerNewTeam("Blue");
            blue.setAllowFriendlyFire(false);
            for (Player player : getServer().getOnlinePlayers()) {
                blue.addPlayer(player);
            }
            for(OfflinePlayer p : blue.getPlayers()) {
                getServer().broadcastMessage(p.getName() + " is in the Blue Team!");
            }
        }
    Solved had to add

    Code:
    player.setScoreboard(board);
    after i add them to the team.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page