Is it possible to check if an area contains only one entity with command blocks. I've tried /testfor
, but it activates the redstone for one person, even if there are more...
1 Answer
/testfor @e
will output a signal strength based on how many entities it finds. For example, if 5 entities are found, the signal strength outputted will travel 5 blocks.
To test for exactly one entity, you can do something like this with and add on an AND gate:
Alternatively, you can use another command block with the 'testforblock' command in it, testing for if the first command block has succeeded exactly once. The setup should look something like:
/testforblock X Y Z command_block 1 {SuccessCount:1}
Where X Y Z are the coordinates of the first command block, and the comparator should come off of this second command block.
-
So if I add an and gate it will find only one player and no more? Commented May 17, 2015 at 16:44
-
@user3189338 Yep. The repeater activates when there's one player, and the torch deactivates when there's two players, so both are on only when there's exactly one player.– SirBenetCommented May 17, 2015 at 16:46
-
One more question, if I want to check that the players are between specific bounds, how would I do that? Commented May 17, 2015 at 16:48
-
There's probably a way of doing this without the use of redstone dust, since redstone dust is evil when used with command blocks. Commented May 17, 2015 at 17:01
-
@user3189338 Put the bounds in the @e selector arguments.– SirBenetCommented May 17, 2015 at 17:35