Skip to content

Instantly share code, notes, and snippets.

@Dinnerbone
Created September 17, 2012 09:49
Show Gist options
  • Save Dinnerbone/3736487 to your computer and use it in GitHub Desktop.
Save Dinnerbone/3736487 to your computer and use it in GitHub Desktop.
New Minecraft target selector syntax!

Syntax

All target selectors start with @. The following character is the selector type. For example, @p means 'closest player'.

Target selectors may have additional, optional arguments. You can specify these in [ ], using the syntax a=0. For example, @p[a=0,b=5,c=-500].

There is a special short syntax for just specifying x, y, z and r arguments; simply list their values separated by a comma, without x=. For example: @p[100,64,-100,5] for 5 range, x=100, y=64 and z=-100. Each of these are optional and skippable by leaving them empty. For example, to just specify y coordinate: @p[,64].

Global Arguments:

  • x - X coordinate for search center. Default is senders coordinate, or 0.
  • y - Y coordinate for search center. Default is senders coordinate, or 0.
  • z - Z coordinate for search center. Default is senders coordinate, or 0.
  • r - Range, number above 0. Default 0 ("No range limit")
  • m - Game mode, number above 0. Default -1 ("No mode limit")
  • c - Max count of results. Default 0 ("No count limit"). Numbers below 0 will make it return the last x amount of entries.

Selectors:

  • p - Closest player.
  • a - A list of all players.
  • r - A random player.

All selectors are lists, but only p has a default count limit of 0 (unlimited). When using lists in a string context (for example, /say Hello @a) it will list all players as strings. When used as a command argument, it will iterate the command for each player in the list.

Examples

@p[r=5]

Closest person within 5 blocks. If there's nobody within 5 blocks, the command will fail.

@a[x=100,y=64,z=-100,c=10,r=5]

Closest 10 players within 5 blocks of 100,64,-100.

@p[0,64,0,c=-2]

The furthest 2 players from 0,64,0.

@a[,,,10,c=5]

The closest 5 players within 10 blocks of your current position.

@Durandle
Copy link

you guys do know that the move command is redundant /move 10 2 10 is the same as /tp ~10 ~2 ~10 since 1.4.4 or earlier

@Durandle
Copy link

@king92197
the problem probably is that you haven't specified a location to send everyone to the command "/tp @A[180,84,23,64]" translates to "teleport everyone in radius of 64 blocks from location 180,84,23 to ..." see the problem?

@ZeroErrors
Copy link

I found something that would be useful,
If you were to have wildcard's for the coordinates for example @A[,0,,2] this will get all the players with a y value of 2 or less.
You could use something like '/tp @A[,0,,2] 0 65 0' and teleport everyone that is at y=2 or less so they don't fall into the void.

@tschoffelen
Copy link

"number above 0. Default 0". Shouldn't that be 'number 0 or higher' or something like that?

@MTandi
Copy link

MTandi commented Feb 18, 2013

An implementation of selected player variables can add a lots of new possibilities and minimize amount of command blocks needed for some commands.

For example we can use one command block in re-spawn area to send players in different places depending on class.
/tp @r[0,0,0,5] 10 10 Class*10
Where "Class" is score from scoreboard (or their Level). It acts like "~" in tp command. Players with class 1 will be teleported at z=10, with class 2 at z=20 etc.

It will be also possible to arrange players on pedestal in order of their kills or experience at the end of the match.

If we need 3 players to stay in correct order depending on their role, we can use:
/testfor @A[0,0,Role*10,5].
And it will output signal strength of 3 if all players stay in their places.

And lots more.

@Sidneys1
Copy link

Updated fork here (as of MC 1.8). No pull request feature on Gist, Dinnerbone needs to update this.

@SkadetteTayne
Copy link

how do you make a command block only say something once when the person gets within your specified range of the command block?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment