I would really like to know if it's possible to track "how high" the player is and link it to another command.
For example, if the player is above or crossed height level of 240, it would trigger a set of commands (tp ~ ~-100 ~
as an example).
minecraft-commandsminecraft-java-edition
I would really like to know if it's possible to track "how high" the player is and link it to another command.
For example, if the player is above or crossed height level of 240, it would trigger a set of commands (tp ~ ~-100 ~
as an example).
Best Answer
You must change the origin to that of the player using
/execute
and then modify the Y value, while providing a selection limiter such as a radius.Without the limiter, it will select all players in existence, as an origin change (only modifying
x
,y
, orx
parameters) does not equate to a limiter. The origin is used to sort targets by distance before running commands affecting them.Without
/execute
, the X and Z coordinates will be that of the command block, which would prevent usage anywhere except at the same X and Z of the command block. For example, given the following command:This would only teleport players at the command block's X and Z, but with a modified Y. Example image, where the black square is the command block and the shaded area is where a player must be to match:
However, with
/execute
, the origin will be that of the targets. This allows usage anywhere in the world since the targets will always match their own X and Z coordinates.For example, using the following command:
The following image represents where players (represented by circles) need to be to match:
You can either change the Y using
/execute
's syntax:Or change it using the
y
parameter of the nested selector: