How do I test if all minecraft players on a server are in a radius?
This has got me. I need a command that tells me if all players on a server are in a radius of a command block. If one of them isn't in the radius, the command will be false. Any ideas? Thanks!
Solution 1:
Use a command block with the command /testfor @a[rm=RADIUS]
. point a comparator from the command block into another block, and on that block, place a redstone torch. This tests if anyone is outside of the radius, and inverts the signal, providing the output you want.
Solution 2:
A block-updateless method would be to use 1.9's new command blocks with the "conditional" setting, as well as using /testforblock
to check the success of a command.
Image example:
-
Look for players outside the area. This has been reduced to 1 player, as otherwise the command is processed equal to the number of players outside the area. All we need to know is if there's at least 1.
/testfor @a[rm=10,c=1]
-
Check the
SuccessCount
value of the Repeating command block. Replace the XYZ values with that of the Repeating command block. If the value was 0, that means no players were found./testforblock X Y Z minecraft:repeating_command_block -1 {SuccessCount:0}
-
Conditional. Command to run based on there being no players outside the area.
/say No players outside the area.
To further reduce server strain, you can disable output tracking on the command blocks. Do so by clicking the "O" button in the interface so that it turns into an "X":