Arqade Asked on January 28, 2021
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.
execute @a[tag=playing] ~ ~ ~ testfor @a[tag=playing,rm=0.0000000000001]
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 0
s 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
.
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:
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.
rm
ArgumentThis 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]
.
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]
).
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.
Correct answer by Penguin on January 28, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP