0

I'm attempting to make a fully customized map that I want to only be single player. I'm going to be using custom sounds with my voice, and wanted to determine whether or not a group of people are playing multiplayer so I can present them with a custom clip of me saying "this map will only work in Single Player" or something similar.

I've thought about making a simple command block that triggers after x amount of time using chain command blocks, with the following command;

execute unless @a[limit=1] run playsound ..

The problem with this, however, is I'm not entirely certain that the limit selector will work this way. In theory, of course, it should, but being unable to test multiplayer myself makes this a little difficult.

Another, more sure-fire, way would be to do three scoreboards and match them all up together to create a tally system, but not only would that be countless hours of tedious brain-knocking before eventually making a flawless system, but it wouldn't be necessarily flawless and could mess up at any given moment.

Would there be any way to find how many players there are in a world--and if so, to run a command if there are x people?

1
  • If you need a test server for multiplayer stuff, just send me a mail and I can quickly set one up and put an AFK player into it. And no, that selector does not work that way. @a[limit=1] is the same as @r (except that it doesn't randomise every time) and that succeeds /execute unless. – Fabian Röling Mar 9 '20 at 23:46
3

Create a scoreboard objective:

/scoreboard objectives add players dummy

and run this in a repeating command block:

/execute store result score map players run execute if entity @e[type=player] 

to run your command:

execute if score map players matches 2.. run <command>

^ this only runs if there are 2 or more players in the world.

3
  • I'm a little confused on where map comes in there. I'm fairly certain it's supposed to be a player, but I'm not quite sure what it means here. – EarthToAccess Mar 10 '20 at 5:41
  • You are correct to think that it should be a player. However, it doesn't have to be a real player. You can type in any name you want, and the game will create what's knows as a "fake player". The only difference between a real player and a fake player is that the fake player doesn't physically exist in the world, making it easier to store data. – MegaCrafter10 Mar 10 '20 at 11:13
  • I actually didn't know about that, that is incredibly useful to me now lmao – EarthToAccess Mar 12 '20 at 5:22
0

Rather than attempt to scoreboard, you could use a spawn detector.

Basically, when a new player logs in, they spawn in the spawn region. Then, when they spawn in - Increment a counter or mechanism somewhere. When a second player logs in, that happens again and you can use that to detect more than one players have joined.

Don't forget to /setspawn after the player joins otherwise deaths may count as another login.


A way to do this is to have the entire spawn chunk covered in tripwire connected to tripwire hooks. Then, feed the tripwire into your counting mechanism.

1
  • That won't work for my map, sadly. – EarthToAccess Mar 10 '20 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.