0

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.

1 Answer 1

0

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
3
  • I already did something like this and I just have a question, can you be in multiple teams at once or and/or does it make you leave the team without the need to type /team leave. Like does it kick you out from every other team if you join another one Sep 21 at 9:29
  • Wiki doesn't specify, but I belive you can be at only one at a point and join should automatically change. You could test that yourself tho! But note that not using leave when the score had no match implies staying as it is (so having a score of 0 or negative will result in no change of teams rather than leaving the current team)
    – BunnyMerz
    Sep 21 at 16:18
  • 1
    @NotKatsuro3 I can confirm that an entity can only be in one team at a time. Attempting to add an entity to a different team will cause said entity to leave their previous team. Sep 25 at 4:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .