How can I teleport only people within a specific area?
Is there a way I can set an area, bigger than one block, to teleport players from? I'd like to randomly teleport people that are within this area to two or more destinations.
I'm making a minigame in which players all start in a hub, and a command blocks picks one of the players in the hub area randomly and teleports them to either the blue team or red team side. My problem when trying this was that it would teleport people no longer in the hub area, making it so that a person on the blue team could randomly get swapped to the red team or from red to blue.
How can I make the command only target people in a certain area?
I'm currently on Minecraft 1.10.2 for PC.
43 Answers
If I understood well, you want the /spreadplayers command, which teleports players to random places inside a specified area in a command:
/spreadplayers <x> <z> <spreadDistance> <maxRange> <respectTeams> <player> x, z: The middle of the area you want to teleport players (press F3 to see coordinates)
spreadDistacnce: The minimum distance between teleported players
maxRange: The maximum teleport distance from the x and z coordinates
respectTeams: True or false. When true, targets on the same team will be teleported to the same location.
player: The selector of what you want to teleport, eg. @p
Example:
/spreadplayers 0 0 1 10 false @aThis will teleport all players to random locations, but at least 1 block away, from x = -10 and z = -10 to x = 10 and z = 10.
Example 2 (requested in the comments):
/spreadplayers 100 100 0 5 false @r[x=0,y=60,z=0,r=10]This command will teleport a random player that was less then 10 blocks away from XYZ 0, 60, 0 to a random location within 5 blocks of X, Z 100, 100.
For more information about the /spreadplayers command, visit the Minecraft Wiki or the Minecraft Forum
There are two ways of doing this. Selectors (you're probably using @r) can have "Selector arguments". The ones you're interested in for selecting an area are:
x, y, z- the coordinates for the starting point of the search, useless without one of the two below:r- the max radius that a player can be from the starting point (like a sphere)dx, dy, dz- the max x, y, and z that a player can be from the starting point (like a cuboid)
Using a radius is the easiest method. If your hub is at 20, 64, -10 for example, you could change your commands to:
/tp @r[x=20,y=64,-10,r=15] X1 Y1 Z1Which would TP anyone within 15 blocks of that point to X1 Y1 Z1 (set this to the red/blue team's side).
With the cuboid selectors, your starting point should be the corner of the cuboid with the lowest coordinates on all axis (so lowest north-western).
dx, dy, dz should then be the positive width, height, and length of the cuboid, as such:
These are more complicated than a radius selector, which you might want to stick with, but will allow you a more accurate area if your hub is cuboid.
0Use the radius target selector. You should use something such as @r[r=ENTER HUB RADIUS HERE]. Use this target selector in a command, eg. /tp. Hook it up to a clock that starts when pressed from a button and it should teleport everyone to different team location one by one. Use multiple command blocks of you want more destinies.