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>
Yes, you can. It's pretty simple, use the following code:
/tp @p[x=0,y=0,z=0,r=0] *tp coordinates*
Where the values x, y, z define the center of the search (the player nearest to these coordinates would get teleported) and r defines the radius of the search. If you don't want to limit the radius omit r.
Do not use decimal values for the search center, this will not work.
See here for more info.
Best Answer
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
.