1
What is the command to test the number of player currently online on a world?
Thanks for any help.
Note: It's for a 1.RV-Pre1 world.
Thanks for any help.
Note: It's for a 1.RV-Pre1 world.
Create an account or sign in to comment.
6
1
(If you want to test without having to summon an entity, this applies to the FIRST set of commands Heklo posted and won't work with the second set!)
In most situations it's easier to use an entity like Heklo described (since you can test for it using target arguments instead of one specific command), but I decided to post this alternative just in case.
scoreboard players test playersOnline playersOnline <min number> <max number>
In most situations it's easier to use an entity like Heklo described (since you can test for it using target arguments instead of one specific command), but I decided to post this alternative just in case.
1
Click to reveal
/scoreboard objectives add playersOnline dummy
Summon an invulnerable pig called playersOnline and run these 2 on a chain in this order:
Click to reveal
/scoreboard players reset @e[name=playersOnline] playersOnline
Click to reveal
/execute @a ~ ~ ~ scoreboard players add @e[name=playersOnline] playersOnline 1
From here you could test for it by doing this:
Click to reveal
/testfor @e[name=playersOnline,score_playersOnline=5,score_playersOnline_min=5]
If 5 players are online, it will result positive. Or you could use the following format to skip a testfor command and just spam [command] when 5 players are online:
Click to reveal
/execute @e[name=playersOnline,score_playersOnline=5,score_playersOnline_min=5] ~ ~ ~ [whatever command here]
1
Ok, nevermind still doesn't work. How do I then test for the value of playersOnline?
1
Ok, nevermind. I just forgot to put in a command into the 2nd block. It works now. Hopefully this part of the project will be finished quickly now.
1
Ok, thanks. Now one more thing: How to start a chain of chain command blocks with a button?
1
Click to reveal
/scoreboard objectives add playersOnline dummy
Run these 2 on a chain in this order:
Click to reveal
/scoreboard players reset playersOnline playersOnline
Click to reveal
/execute @a ~ ~ ~ scoreboard players add playersOnline playersOnline 1
The score of playersOnline in objective playersOnline will be equal to the number of players online.