I am trying to make a minecraft minigame map and I am trying to detect how many players are in the world so I can set up a scoreboard, I have the scoreboard setup correctly which I know because I have done multiple testing in other creative worlds and that world. So I setup a command,
testfor @a[c=1] in one command block and testfor @a[c=2]. When I put a comparator next to the command block and powered both of them they both came on which confuses me, then, I did the command testfor @a[c<1,c=2] however that doesn't work either, can anyone help me!
Hmm. How about... just... setting up a scoreboard that goes up every time there's a player? Like a testfor command hooked up to a comparator which leads to a scoreboard command that adds to something that shows how many players are ingame. Then just make sure the testfor thing is only activated when checking because a player leaves the system will get confused. So I recommend after detecting the amount of players it clears it.
Well how would I do that? I mean how would the system know when it was a different player every time, I get the part where you say I can add the amount of players using scoreboard but what code would help me detect players and not get confused? Sorry, I'm a little bit of a noob at command blocks.
The 'count' parameter is only to modify to maximum number of players to select, not minimum. If you're using 'c=2' and there's fewer than 2 players (as well as more than 2), the command will still output.
Well how would I do that? I mean how would the system know when it was a different player every time, I get the part where you say I can add the amount of players using scoreboard but what code would help me detect players and not get confused? Sorry, I'm a little bit of a noob at command blocks.
Before adding to a score, you'd have to set the score to 0. Here's a quick example, which will provide the total number of players:
Prerequisites:
Objective to hold the value:
/scoreboard objectives add PLAYERS dummy
Detection Commands:
The following commands must be run in numerical order. A fake player will be used to store the score.
1. Setting the fake player's score to 0.
/scoreboard players set #NUM PLAYERS 0
2. Causing all players to individually add 1 to #NUM's "PLAYERS" score. If there are 2 players, then each player will increase the number by 1, for a total of 2.
3. In order to detect a fake/offline player's score, you must use /scoreboard's 'test' feature. The following tests if #NUM's score is 2 or higher, which would mean there are two or more players.
I am trying to make a minecraft minigame map and I am trying to detect how many players are in the world so I can set up a scoreboard, I have the scoreboard setup correctly which I know because I have done multiple testing in other creative worlds and that world. So I setup a command,
testfor @a[c=1] in one command block and testfor @a[c=2]. When I put a comparator next to the command block and powered both of them they both came on which confuses me, then, I did the command testfor @a[c<1,c=2] however that doesn't work either, can anyone help me!
Before adding to a score, you'd have to set the score to 0. Here's a quick example, which will provide the total number of players:
Prerequisites:
Objective to hold the value:
Detection Commands:
The following commands must be run in numerical order. A fake player will be used to store the score.
1. Setting the fake player's score to 0.
2. Causing all players to individually add 1 to #NUM's "PLAYERS" score. If there are 2 players, then each player will increase the number by 1, for a total of 2.
3. In order to detect a fake/offline player's score, you must use /scoreboard's 'test' feature. The following tests if #NUM's score is 2 or higher, which would mean there are two or more players.
CommandStats is another method that can be used.
Minecraft-things: http://skylinerw.com
More Minecraft-things: https://sourceblock.net
Guides for command-related features (eventually moving to Source Block): https://github.com/skylinerw/guides
I primarily hang out in the /r/MinecraftCommands discord, where there's a lot of people that help with commands: https://discord.gg/QAFXFtZ
Their corresponding subreddit: https://www.reddit.com/r/MinecraftCommands/