2

How to testfor something that everyone needs to qualify

spychicken123's Avatar spychicken1234/10/18 11:16 pm
2 emeralds 271 3
4/12/2018 10:52 pm
SUPERIONtheKnight's Avatar SUPERIONtheKnight
hi. i made a bunch of chain conditional command blocks in a row, each one with testfor @a[team=!red] and so on to detect if only one team exists so that team could win in the map im doing. for some reason however, when there is one person who is not on red (or any other team) it counts it and the next chain, conditional command block starts up. Can someone please tell me what i am doing wrong and/or how to fix it?
Posted by spychicken123's Avatar
spychicken123
Level 42 : Master Taco
26

Create an account or sign in to comment.

3

1
04/12/2018 4:18 amhistory
Level 29 : Expert Engineer
SUPERIONtheKnight
SUPERIONtheKnight's Avatar
NOTE: I assume you are using 1.12.2, if this isn't the case, let me know and I will update my answer.

As you have already stated, the following command will run if one or more players are not on the red team.
testfor @a[team=!red]
While there is a workaround, I recommend using the /scoreboard command as I find it simpler.

We will start by making a dummy scoreboard objective by running the following command once.
/scoreboard objectives add Test dummyThis is what we will use to store our scores. The part that says "Test" can be named whatever you want it to be as long as you update the other commands accordingly(Even naming it Bob works). The dummy part simply means that the scores will not update on their own. You can replace it with something like stat.sneakTime to detect when someone is sneaking, or you could use stat.chestOpened to detect when someone opened a chest. However we will need to use dummy for what you are wanting to do.

Next we need to set the score for each team to 0 every tick, This can be done by using fake players. If you don't know what a fake player is, They're basically like a variable, Their value is equal to whatever number we set it to. In this case, I used the fake player #Teams.
Repeating Unconditional/scoreboard players set #Teams Test 0
Because of the "#", you won't be able to see the actual value of the fake players. Don't worry, this is normal.

After that, you will need to add 1 to #Teams score depending on the number of players on each team. /execute is the perfect command to use in this case.
Edit: I messed up right here, so I fixed these commands.Chain Unconditional/execute @a[team=red,c=1] ~ ~ ~ scoreboard players add #Teams Test 1/execute @a[team=blue,c=1] ~ ~ ~ scoreboard players add #Teams Test 1/execute @a[team=green,c=1] ~ ~ ~ scoreboard players add #Teams Test 1/execute @a[team=purple,c=1] ~ ~ ~ scoreboard players add #Teams Test 1etc...
Now for the moment you have been waiting for. You can test if #Teams score is equal to 1 by using /scoreboard players test.
Chain Unconditional/scoreboard players test #Teams Test 1 1Chain Conditional/say hi
If everything went well, you should see "hi" printed in chat when there is only one team left. Obviously, this should be replaced with whatever it is you are wanting to do. I hope this helps you. :)
~SUPERIONtheKnight
2
04/12/2018 8:45 pm
Level 42 : Master Taco
spychicken123
spychicken123's Avatar
thanks!!!
1
04/12/2018 10:52 pm
Level 29 : Expert Engineer
SUPERIONtheKnight
SUPERIONtheKnight's Avatar
Np... :)

Also, I think I noticed something wrong with my commands. You might want to add ",c=1" in front of the team names in the execute command. The reason for this is because it's currently counting the number of players on each team. This means that if there is only one team left, it won't work if there are two or more players on the same team.

I have edited my above post to fix this issue and so you can see how to fix it. My apologies for this mistake. :P

~SUPERIONtheKnight
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome