I did something like this once. I had a command block on a timer that would look for players not on a team and then teleport them to a room. Any player in that room would be assigned to either red or blue team, using a t flip flop to determine what team to put them on. The flip flop would be switched for every person assigned, so it would go red blue red blue and so on. As soon as they were assigned I'd teleport them out to the team base with another command block.
This was a LONG time ago and I can't remember any more details than that, and there might be more efficient ways to do it now. I just wish mojang would include a scripting language to command blocks because trying to tie the programming into redstone and everything is way harder than it should be and variables can't be moved between blocks. That's why I had to teleport players to a separate room to assign stuff to them.
If each player has individual scores, the first step would be to add them all up into one cohesive team score. One way to do this would be to use a fake player for each team.
Setup:
/scoreboard objectives add teamScore dummy
Run whenever you want to update the scores:
/scoreboard players set red teamScore 0
/scoreboard players operation red teamScore += @a[team=red] enemyKills
/scoreboard players set blue teamScore 0
/scoreboard players operation blue teamScore += @a[team=blue] enemyKills
This will create two scores in teamScore
. One named red
with the combined enemyKills
scores of everyone on the red
team, and one named blue
with the combined enemyKills
scores of everyone on the blue
team.
To test if a team has won:
/scoreboard players test red teamScore 100
will test if the red team has won, while
/scoreboard players test blue teamScore 100
will test if the blue team has won.
Obviously, you don't have to use red
and blue
for the team names, and you could do this for more teams if necessary. And you don't need to use enemyKills
for your scoreboard objective, the names were just arbitrarily chosen and could be any valid name.
Hope this helps! If you find anything unclear, just comment below.
Best Answer
Setup a scoreboard for both teams:
Change OBJNAME to any name you want it to be. Don't change "dummy".
If team A wins, add 1 to the objective 1. Team B, add 1 to objective 2.
Change the OBJNAME to either team A/B as you made above. Don't change number 1.
To see when a team wins, you need command blocks with
testfor
command:Put that again in another command block with its other OBJNAME. Put a comparator on that command block and then another one to do whatever you want when a team gets to 3.