1

How To Test For Number of Players Online?

avrona's Avatar avrona1/1/17 1:20 pm
1 emeralds 647 6
1/21/2017 6:27 pm
Pepijn's Avatar Pepijn
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.
Posted by avrona's Avatar
avrona
Level 40 : Master Explorer
37

Create an account or sign in to comment.

6

1
01/21/2017 6:27 pm
Level 57 : Grandmaster Cyborg
Pepijn
Pepijn's Avatar
(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!)

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
01/21/2017 5:43 pm
Level 23 : Expert Engineer
Heklo
Heklo's Avatar
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
01/01/2017 1:52 pm
Level 40 : Master Explorer
avrona
avrona's Avatar
Ok, nevermind still doesn't work. How do I then test for the value of playersOnline?
1
01/01/2017 1:48 pm
Level 40 : Master Explorer
avrona
avrona's Avatar
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
01/01/2017 1:40 pm
Level 40 : Master Explorer
avrona
avrona's Avatar
Ok, thanks. Now one more thing: How to start a chain of chain command blocks with a button?
1
01/01/2017 1:28 pm
Level 23 : Expert Engineer
Heklo
Heklo's Avatar
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.
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome