How do I testfor a certain amount of players in a certain radius?

How do I testfor a certain amount of players in a certain radius? - Topless Man in Black Shorts Standing on Brown Field

So I am making a Spleef game on my server and I need to testfor 12 players within about 35 blocks from the command blocks.

I tried /testfor @a[r=35] leading into a /tp command to teleport the players into the Spleef arena. What I don't have is to make it only teleport 12 players and not any more or less. So if you can help me with this I'd appreciate it.



Best Answer

There is the count target selector argument.

/tp @p[x=<X>,y=<Y>,z=<Z>,r=<Radius>,c=<Count>] x y z

To detect if there is 12 players or more, there are 2 main ways to do it. One is simply with a comparator leading from a /testfor @a[x=<X>,y=<Y>,z=<Z>,r=<Radius>], which will emmit a redstone signal strength equal to the amount of players in that area and you can run a redstone wire to activate the teleport command, or do it with a scoreboard counter.




Pictures about "How do I testfor a certain amount of players in a certain radius?"

How do I testfor a certain amount of players in a certain radius? - Person Holding Ball Under Blue Sky
How do I testfor a certain amount of players in a certain radius? - Man in Black Tank Top Standing Beside Man in Black Shorts
How do I testfor a certain amount of players in a certain radius? - Man in Black Shorts Holding White Towel



How do you Testfor a player in a radius?

2. Type the Command
  • Test if Players are within 10 blocks. In this example, we will test to see if there are any players within a 10 block radius with the following command: /testfor @a[r=10] ...
  • Test if Mooshrooms are within 50 blocks. ...
  • Test if Nearest Player is at Level 20 experience.




  • Command Block Tutorials: Radius




    More answers regarding how do I testfor a certain amount of players in a certain radius?

    Answer 2

    Using /testfor in a command block while using r= for your radius. To test for a count with no more or no less you'll have to use dust equal to that ammount.

    • testfor @p[r=radius, c=maxCount] Circular radius centered on the command block

    • testfor @a[r=radius, c=maxCount] (Will match dead people supposedly)

    • testfor @a[x=px, y=py, z=pz, r=radius, c=maxCount] Radius from px,py,pz

    enter image description here

    Needless to say, you will need a clock. (I know there are faster clocks) The first commandblock (lower left) is your testfor, and the upper command block would be your tp @p[x=px, y=py, z=pz, r=radius, c=maxCount]

    The blocks in my left toolbar are the materials used for the commands setup, and on the right toolbar are for the clock.

    Answer 3

    You can easily use PLAYER ARGUMENTS. To do it in your case, you should put a command block with this command inside:

    /testfor @a[r=35,c=12]

    Then, you have to put a comparator next to the Command Block. Done!

    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: cottonbro, cottonbro, cottonbro, cottonbro