I've never dabbled in command blocks before, but I'm slowly learning. I am making a murder mystery mini game. I have a ton of problems but the one I am stuck on now is I want to teleport all the remaining alive players to a table, and around the table all facing the center. I don't want to teleport anyone who has died, and I have barely learned how to use @a for all to a singular spot.
-
2Are you using Bedrock Edition or Java Edition? I'm pretty sure that the commands would be the same for both in this instance, but there are still different edge cases. – MBraedley Sep 30 '20 at 16:19
-
Voting to close because you have not mentioned version. Please specify the version for a retract/reopen. – Penguin Feb 25 '21 at 05:50
3 Answers
I'm going to assume you are using Java Edition and are playing in version 1.13 or later. I am also going to assume the "dead" players are spectators.
tag @a[gamemode=!spectator] add unteleported //Give the "unteleported" tag to all players not in spectator mode
Run these 2 commands before each table meeting.
tag @a[tag=unteleported,limit=1,sort=random] add teleporting //Give the "teleporting" tag to one random unteleported player
tp @a[tag=teleporting,limit=1] <seat1> facing 12 65 12 //Teleport the player with the "teleporting" tag to the 1st 'seat' around the table (10 64 10), facing the center of the table
tag @a[tag=teleporting,limit=1] remove unteleported //Remove the "unteleported" tag from all players with tag "teleporting"
tag @a[tag=teleporting,limit=1] remove teleporting //Remove the "teleporting" tag from all players with tag "teleporting"
Repeat this second section for all <seat> coordinates.
- 2,600
- 1
- 13
- 30
I built a meeting table like so:

Next I built this structure high in the sky, directly above the meeting table. I made sure no blocks were above it:

Then, I took the x and z coordinates of the center of the meeting table and put it into the /spreadplayers command to get:
/spreadplayers -24.50 -19.50 1 2 false @a[gamemode=!spectator]
Then: /execute as @a[gamemode=!spectator] at @s run tp @s ~ ~-24 ~ facing -24.50 57.5 -19.50
Done!
How does it work?
/spreadplayers will teleport the selected targets randomly around an area. It will avoid water/lava, among other things. That is why the stone structure in the water is actually an outline of the meeting table. Each block represents a spot where the players could teleport to.
The spreadplayers command actually spreads the players onto this structure, and then I just teleport the players downwards and facing the center of the table.
The syntax of /spreadplayers is:
spreadplayers <center> <spreadDistance> <maxRange> <respectTeams> <targets>
You can begin to see why my /spreadplayers command looks the way it does:
center = -24.50 -19.50 //The center of the meeting table (and the stone structure)
spreadDistance = 1 block //I want the players to be spread at least 1 block apart
maxRange = 2 blocks //I want the spreadplayers command to try to spread players within 2 blocks.
respectTeams = false //Since I'm not using teams, I don't care about keeping them together
targets = @a[gamemode=!spectator] //I don't want to teleport dead players
- 2,600
- 1
- 13
- 30
to do this. you cant do it with ONE command block, you need to have as many random players as you want. or you do /spreadplayers or you choose about 50 different locations and put it in 50 command blocks. then you do [tp @r X Y Z].
- 23
- 2
- 7