1

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...

3

/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:

enter image description here


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:

enter image description here

/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.

|improve this answer|||||
  • So if I add an and gate it will find only one player and no more? – Jacques Marais May 17 '15 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. – SirBenet May 17 '15 at 16:46
  • One more question, if I want to check that the players are between specific bounds, how would I do that? – Jacques Marais May 17 '15 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. – MBraedley May 17 '15 at 17:01
  • @user3189338 Put the bounds in the @e selector arguments. – SirBenet May 17 '15 at 17:35

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.