Count number of players with command blocks? [duplicate]
I'm trying to activate some command blocks only if there's more than one player online in my vanilla server. Is there a way to accomplish this with command blocks?
You probably want to use the testfor command with some type of selector.
The easiest thing to do would be to use the @a
selector with a redstone comparator. The @a
selector will return the count by means of the signal strength, which can be compared to a known strength. If you want to check for more than one (2 or more), then it's as simple as C=rr>
where C
is the command block, =
is the comparator, r
is redstone dust, and >
is the repeater. (Thanks to @MBraedley for the suggestion)
You could also probably use the c
selector here, for count, but I'm not 100% sure how that works in a conditional.
The name
selector would also do it if you want to be sure there are other people around with names that are not yours, but that won't work if you need it to not trigger if only one non-you person is on the server.