If you only want to teleport people who are in a certain group, you can use the new scoreboard command to create a 'group' of people (using teams), and then teleport only that team with this command (targets nearest player in the group specified)
/tp @p[team=<internal group name>,<other params here>] <x> <y> <z>
To set up your groups, you can create a group like this:
/scoreboard teams add <internal group name> <display name>
And then add people to this group like this:
/scoreboard teams join <internal group name> <user name>
The advantage of this system is also that you can use it actually to separate groups in the actual game. The scoreboard command has a feature that means that the display name
of a team will be displayed before the actual username, appearing like this in the chat:
[<display name>] <user name>: ...
More info on this system can be found in the wiki page linked above.
Changing the @p
in the first command above to a player name will stop it from working, because parameters that are inside the [
and ]
will only work for @p
, @a
, and @r
. So you cannot substitute the first command above to /tp <player name>[r=2] <x> <y> <z>
. It just won't work.
If you really want to use the r
parameter on a single person, try using the above method that uses teams, but only put one person in the team. Here is a quick way to do this. Type these into the command console:
/scoreboard teams add <internal player name> <external player name>
/scoreboard teams join <internal player name> <player name>
And then in the command block, to teleport that person if they are in a radius of 2, you could use:
/tp @p[team=<internal player name>,r=2] <x> <y> <z>
Alternatively, you could just specify the name of the player in the selector. Following the previous example, if you want to teleport a certain person if they are in a radius of 2, you could use:
/tp @p[name=<player name>,r=2] <x> <y> <z>
This was a very interesting challenge for me to work out. There are many parts to this problem, which are a lot harder to accomplish than one might think. There's identifying the player with the status effect, and identifying a set of random players who are not them (since /tp Unionhawk Unionhawk
is a valid result of /tp @p @r
, and does nothing).
But, finally, here is my setup, which works for a bounded number of players on a server. Some of its flaws include only allowing one game to be played on a given server, and using experience level to identify players. As such, /gamerule doMobLoot false
must be used, and /gamerule commandBlockOutput false
is strongly advised.
So there's quite a lot of things going on here, as you can see. But this is all accomplished using 4 commands and a hopper clock.
The Group 1 command blocks are there to detect when a player has the specified potion effect, remove it, and proceed to the matching Group 2 command block. I used /effect @p[c=n] 4 0
for that one, which removes the mining fatigue effect from player n on the server (going down the list of players on the server). When that command evaluates, the Group 2 command blocks give that player one level of experience using /xp 1L @p[c=n]
.
From there, the next time the hopper clock pulses, the "Group" 3 (you only need one) command block teleports a player with 1 level or more to a random player without any levels using /tp @p[lm=1] @r[l=0]
. When this command evaluates, the "Group" 4 command block clears the experience level of all players using /xp -9999L @a
.
Best Answer
If I understood well, you want the
/spreadplayers
command, which teleports players to random places inside a specified area in a command:x
,z
: The middle of the area you want to teleport players (press F3 to see coordinates)spreadDistacnce
: The minimum distance between teleported playersmaxRange
: The maximum teleport distance from the x and z coordinatesrespectTeams
: 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:
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):
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