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 @a
This 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
Best Answer
To test for a player in some distance from a certain place, use:
Where
X
,Y
andZ
are the middle coordinates of the area to test for a player,R
andRM
specify the minimum and maximum distances from the specified coordinates, respectively.To run a command, eg.
/say Hello
when the testfor command returns true, place the @a[] part into an/execute
command: