How to add a player to the killer's team



  • I'm making a datapack where if you kill somebody they join your team, I already know how to track deaths and kills and I thought of making two scores, one is death count and the other is kills. If a kill happened, the game would just check which player has the score.

    The problem with this is there will be at the start a team for every player, and the teams might move a lot, and making as much as 16 execute command makes me think that there might be a better way. Also this way I would need to make ±16 functions just to add the player then reset the scoreboards of death/kill, and if two players would die at once it could screw up the entire system.



  • Unfortunately, Teams can't be handled programatically, you must call them individually, and regarding the killing problem, there shouldn't be any way to circunvent it. Your best bet would be predicates.

    With that being said, you can use scores to handle teams, and use a single function to attach teams to players based on their score and call this everytime a player chnages score. This would reduce to a single function with exactly [1 + team count] commands. Assigning a unique score to each player shouldn't be much of a hassle. Something along these lines should work for the team problem:

    ## Any_file.mcfunction
    execute as @a[scores={death=1..}] run function Match_Killer
    

    Match_Killer.mcfunction

    tag @r[scores={kills=1..}] add killer
    execute store result score @s team run scoreboard players get @a[limit=1,tag=killer] team
    scoreboard players remove @a[limit=1,tag=killer] kills 1
    tag @a[tag=killer,limit=1] remove killer
    scoreboard players remove @s deaths 1
    execute as @s run function Update_Team

    Update_Team.mcfunction

    team leave @s
    execute if score @s team matches 1 run team join team1 @s
    ...
    execute if score @s team matches 16 run team join team16 @s




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2