0

How can I tell if only one person is found by a selector?
For example, this would be useful to see if there is only one person with a playing tag, and you would know when everyone has died but one so they can win.

0

Command

execute @a[tag=playing] ~ ~ ~ testfor @a[tag=playing,rm=0.0000000000001]

Explained

What we did was look for a player, then use that player to find another one of the same criteria, but with a rm argument which means the minimum distance (range) from the player we executed from. We put in a decimal with a bunch of spammed 0s and then a 1 to find someone other than the player we're executing from. Without this, the player we execute from would detect him/herself. This block returns true if 2 or more players have the tag playing.

Not Gate

We then take a comparator output from out command block and run it into a redstone torch, and above the torch have the command we want to run after. Follow Picture: Not Gate
When two players are found, the comparator will turn on and turn off the torch. When two players are not found, the comparator will turn off and the torch will turn on, activating the command block above the torch.

Work With rm Argument

This section only applies to the specific situations where an rm argument is already being used. If your selector that you wanted to use doesn't include rm, ignore this.
If you're already using the rm argument, we need a slightly modified approach. (For this example I will change the example selector from @a[tag=playing] to @a[tag=playing,rm=5].) Note you will have to put an armor stand on the command block and name it or tag it, I will name the armor stand testsel. So, instead of doing something like testfor@a[rm=5], we would do execute@e[type=armor_stand,name=testsel]~~~testfor@a[rm=5].

Command

From here we can change our previous command to:

execute @a[tag=playing,rm=5] ~ ~ ~ execute @a[tag=playing,rm=0.0000000001] ~ ~ ~ testfor @e[type=armor_stand,name=testsel,rm=5]

That command finds two people, outside the range of 5 and with the tag playing from the command block (@a[tag=playing,rm=5]).

Explained

That command first executes off of someone at last of 5 distance and the tag playing. Then, we find someone else with the tag playing. We then look and see if our armor stand that was on top of our block is at least 5 distance away.

| improve this answer | |
  • How else do you suggest a not gate? – Penguin Nov 8 at 0:29
  • @ExpertCoder14 just last reply quick: With the addition of delays a while back, it isn’t bad since the “unpredictable” aspect can be shut out with delays. This is how you can do many things, such as wait for certain things in the game to run and render before continuing a command chain. Because of this, the unpredictable aspect is pretty much eliminated. I haven’t found a way to do this but like a day ago I requested it as a command and no one in comments has an altern – Penguin Nov 8 at 5:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.