Editing
MinecraftCommands
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Target selectors === In most commands where a player may be specified as an argument, it is possible to "target" one or more players satisfying certain conditions instead of specifying players by name. To target players by condition, choose a target selector variable and, optionally, one or more target selector arguments to modify the conditions to be satisfied. For example, to change the game mode of all players on team Red to creative mode, instead of specifying them by name individually: :<code>/gamemode creative @a[team=Red]</code> <!-- please retain double newline above for section differentiation --> ==== Target selector variables ==== {| class="floatright wikitable" style="clear:none;margin-left:1em;" |+ Summary of target selector variables ! Variable !! Function |- | <code>@p</code> || nearest player |- | <code>@r</code> || random player |- | <code>@a</code> || all players |- | <code>@e</code> || all entities |} A target selector variable identifies the broad category of targets to select. There are four variables: ; <code>@p</code> : Targets the nearest player. If there are multiple nearest players, caused by them being precisely the same distance away, the player who most recently joined the server is selected. : [[#Target selector arguments|Target selector arguments]] may be used to reduce the set of players from which the nearest player will be selected. For example, <code>@p[team=Red]</code> will target the nearest player on team Red even if there are other players closer. : The <code>c</code> target selector argument can be used to increase the number of nearest players targeted (for example, <code>@p[c=3]</code> will target the three nearest players). When negative, <code>c</code> will reverse the order of targeting (for example, <code>@p[c=-1]</code> will target the ''farthest'' player). ; <code>@r</code> : Targets a random player (or entity with the <code>type</code> target selector argument). : [[#Target selector arguments|Target selector arguments]] may be used to reduce the set of players from which a random player will be targeted. For example, <code>@r[team=Red]</code> will only target a random player from team Red. : The <code>c</code> target selector argument can be used to increase the number of random players targeted. For example, <code>@r[c=3]</code> will target three random players. : When used without the <code>type</code> argument, <code>@r</code> always targets a random player. The <code>type</code> argument can be used to target non-player entities (for example, <code>@r[type=Zombie]</code> will target a random [[zombie]], <code>@r[type=!Player]</code> will target a random non-player entity, <code>@r[type=!Zombie]</code> will target a random non-zombie, etc.). ; <code>@a</code> : Targets all players, including dead players. No other selector will find dead players. : [[#Target selector arguments|Target selector arguments]] may be used to reduce the set of players targeted. For example, <code>@a[team=Red]</code> will only target players on team Red. ; <code>@e</code> : Targets all entities (including players). : [[#Target selector arguments|Target selector arguments]] may be used to reduce the set of entities targeted. For example, <code>@e[type=Cow]</code> will only target cows. <!-- please retain double newline above for section differentiation --> ==== Target selector arguments ==== {| class="floatright wikitable" style="clear:none;margin-left:1em;" |+ Summary of target selector arguments ! colspan="2" | Selection by Position |- ! Argument(s) !! Selection criteria |- | <code>x</code>, <code>y</code>, <code>z</code> | [[#Selecting targets by coordinate|coordinate]] |- | <code>r</code>, <code>rm</code> | [[#Selecting targets by radius|radius (max, min)]] |- | <code>dx</code>, <code>dy</code>, <code>dz</code> | [[#Selecting targets by volume|volume dimensions]] |- ! colspan="2" | Selection by Scoreboard Values |- ! Argument(s) !! Selection criteria |- | <code>score_''name''</code> | [[#Selecting targets by score|max score]] |- | <code>score_''name''_min</code> | [[#Selecting targets by score|min score]] |- | <code>tag</code> | [[#Selecting targets by tag|scoreboard tag]] |- | <code>team</code> | [[#Selecting targets by team|team name]] |- ! colspan="2" | Selection by Traits |- ! Argument(s) !! Selection criteria |- | <code>c</code> | [[#Selecting targets by count|count]] |- | <code>l</code>, <code>lm</code> | [[#Selecting targets by experience level|experience level (max, min)]] |- | <code>m</code> | [[#Selecting targets by game mode|game mode]] |- | <code>name</code> | [[#Selecting targets by name|entity name]] |- | <code>rx</code>, <code>rxm</code> | [[#Selecting targets by vertical rotation|vertical rotation (max, min)]] |- | <code>ry</code>, <code>rym</code> | [[#Selecting targets by horizontal rotation|horizontal rotation (max, min)]] |- | <code>type</code> | [[#Selecting targets by type|entity type]] |} After using a target selector, you can optionally use arguments to modify the set of targets selected. When used with <code>@a</code> or <code>@e</code>, arguments narrow down the number of targets from the full list to a specific few. When used with <code>@p</code> or <code>@r</code>, arguments narrow the number of targets down from the full list to a smaller set from which the nearest or random player is selected. Add argument-value pairs as a comma-separated list contained within square brackets after the target selector variable: : <code>@<variable>[<argument>=<''value''>,<argument>=<''value''>,β¦]</code>. Spaces are not allowed around the brackets, equal signs, or commas, and only commas may be used to separate argument-value pairs. Arguments are case-sensitive and unsupported arguments are silently ignored. For example, <code>kill @e[type=Creeper,r=20]</code> will kill all creepers in a 20-block radius, but <code>kill @e['''T'''ype=Creeper,r=20]</code> (the 't' in 'type' capitalized) will kill ''all'' entities (including players) in that radius because there is no longer a ''valid'' argument limiting the targets to just creepers. If the first few arguments (up to four) are specified simply as values without identifying the arguments, they are assumed to be, in order, <code>x</code>, <code>y</code>, <code>z</code>, and <code>r</code>. Thus, the following two commands are identical: :<code>/gamemode creative @a[x=10,y=20,z=30,r=4]</code> :<code>/gamemode creative @a[10,20,30,4]</code> ;{{anchor|Selecting targets by coordinate}}Selecting targets by coordinate : <code>[x=''X'',y=''Y'',z=''Z'']</code> β Selects targets based on distance to that exact position. Combine with selecting by radius to select only targets at that specific position. : The coordinates have to be integers and must be exact - [[#Tilde notation|tilde notation]] is not available for selector argument coordinates. ;{{anchor|Selecting targets by radius}}Selecting targets by radius : <code>[r=''R'']</code> β Selects only targets less than ''R'' blocks from the command's execution. : <code>[rm=''RM'']</code> β Selects only targets more than ''RM'' blocks from the command's execution. :If a coordinate (above) and either or both radius/i are both defined, the radius/i will center on the coordinate rather than the postion of the command's execution. By using a very distant coordinate and a very large radius, it is possible to simulate a near-linear edge to use to specify targets. ;{{anchor|Selecting targets by volume}}Selecting targets by volume : <code>[dx=''DX'',dy=''DY'',dz=''DZ'']</code> : Selects only targets within the volume defined as starting from the location where the command was executed and extending ''DX'' blocks in the "x" direction (i.e., east/west), ''DY'' blocks in the "y" direction (i.e., upwards/downwards), and ''DZ'' blocks in the "z" direction (i.e., north/south). If an initial coordinate is specified with the <code>x</code>, <code>y</code>, and <code>z</code> arguments, that will be used instead of the position of the command's execution for the lower northwestern corner (<code>dx</code>, <code>dy</code>, and <code>dz</code> still specify ''distances'' from that coordinate; they do ''not'' specify a separate coordinate). : It is possible to combine selection by radius and selection by volume, in which case the command will only select targets within the overlap of both regions (within certain radius/i of the volume's lower northwest corner and not outside the defined volume). ;{{anchor|Selecting targets by score}}Selecting targets by score : <code>[score_''name''=''SCORE'']</code> β Selects only targets with a score in objective ''name'' of no more than ''SCORE''. : <code>[score_''name''_min=''SCOREMIN'']</code> β Selects only targets with a score in objective ''name'' of no less than ''SCOREMIN''. : For example, <code>@a[score_points_min=30,score_points=39]</code> will select all players with a score in objective "points" between 30 and 39 (inclusive). {{see also|Scoreboard#Objectives}} ;{{anchor|Selecting targets by tag}}Selecting targets by tag : <code>[tag=''TAG'']</code> β Selects only targets that have been given the scoreboard tag ''TAG''. : <code>[tag=!''TAG'']</code> β Selects only targets that have ''not'' been given the scoreboard tag ''TAG''. : <code>[tag=]</code> β Selects only targets without ''any'' scoreboard tags. : <code>[tag=!]</code> β Selects only targets with ''any'' scoreboard tags. {{see also|Scoreboard#Tags_commands}} ;{{anchor|Selecting targets by team}}Selecting targets by team : <code>[team=''TEAM'']</code> β Selects only targets on team ''TEAM''. : <code>[team=!''TEAM'']</code> β Selects only targets ''not'' on team ''TEAM''. : <code>[team=]</code> β Selects only targets not on ''any'' team. : <code>[team=!]</code> β Selects only targets on ''any'' team. {{see also|Scoreboard#Teams}} ;{{anchor|Selecting targets by count}}Selecting targets by count : <code>[c=''C'']</code> β Selects only the specified number of targets. Usually in order of distance from the command executor. : When used with <code>@p</code> or <code>@r</code>, this argument defaults to 1, so using a higher number will ''increase'' the number of nearest or random targets returned. When used with <code>@a</code> or <code>@e</code>, this argument returns only the nearest targets. :If there are multiple nearest targets, caused by them being precisely the same distance away, targets are sorted by the time they have been on the server (since their most recent join for players or their creation for other entities) with the longest times selected first. For example, ''if equally distant'', <code>@a[c=1]</code> will select the player who has been on the server the longest and <code>@e[type=Creeper,c=3]</code> will select the three oldest creepers. : When used with a negative value, the order of targets is reversed. For example, <code>@p[c=-3]</code> will return the three ''farthest'' targets, and, if all potential targets are equally far away, <code>@e[c=-3]</code> will select the last three targets created. ;{{anchor|Selecting targets by experience level}}Selecting targets by experience level : <code>[l=''L'']</code> β Selects only targets with no more than ''L'' experience levels. : <code>[lm=''LM'']</code> β Selects only targets with no less than ''LM'' experience levels. ;{{anchor|Selecting targets by game mode}}Selecting targets by game mode : <code>[m=''M'']</code> β Selects only targets on the specified [[game mode]]. : <code>[m=!''M'']</code> β Selects only targets that are ''not'' on the specified [[game mode]]. : Permitted values for ''M'' are: :* <code>-1</code>: all game modes :* <code>0</code>, <code>s</code>, <code>survival</code>: survival mode :* <code>1</code>, <code>c</code>, <code>creative</code>: creative mode :* <code>2</code>, <code>a</code>, <code>adventure</code>: adventure mode :* <code>3</code>, <code>sp</code>, <code>spectator</code>: spectator mode ;{{anchor|Selecting targets by name}}Selecting targets by name : <code>[name=''NAME'']</code> β Selects only targets named ''NAME''. : <code>[name=!''NAME'']</code> β Selects only targets ''not'' named ''NAME''. ;{{anchor|Selecting targets by vertical rotation}}Selecting targets by vertical rotation : <code>[rx=''RX'']</code> β Selects only targets with a maximum vertical rotation of ''RX''. : <code>[rxm=''RXM'']</code> β Selects only targets with a minimum vertical rotation of ''RXM''. : Vertical rotation values vary from -90.0 facing straight up to 90.0 facing straight down (thus vertical rotation values increase with rotation ''downwards''). ;{{anchor|Selecting targets by horizontal rotation}}Selecting targets by horizontal rotation : <code>[ry=''RY'']</code> β Selects only targets with a maximum horizontal rotation of ''RY''. : <code>[rym=''RYM'']</code> β Selects only targets with a minimum horizontal rotation of ''RYM''. : Horizontal rotation values vary from -180.0 (facing due north), to -90.0 (facing due east), to 0.0 (facing due south), to 90.0 (facing due west), to 179.9 (just west of due north) before wrapping back to -180.0 (thus horizontal rotation values increase with rotation to the right, or clockwise viewed from above). ;{{anchor|Selecting targets by type}}Selecting targets by type : <code>[type=''TYPE'']</code> β Selects only targets of the specific entity type. : <code>[type=!''TYPE'']</code> β Selects only targets ''not'' of the specific entity type. : ''TYPE'' must be an [[Data values#Entity IDs|entity ID]] used to identify different types of entities internally (for example, <code>Creeper</code> for [[creeper]]s, <code>MinecartRideable</code> for regular [[minecart]]s, <code>PrimedTnt</code> for primed [[TNT]], etc.). Entity IDs are case-sensitive and invalid entity IDs will cause the command to fail. : When used with <code>@r</code>, can change its normal behavior of targeting only players to target other entities. <!-- please retain double newline above for section differentiation -->
Summary:
Please note that all contributions to Hegemon Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Hegemon Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
Edit source
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information