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).

  • 2
    Don't feel stupid, one time I forgot that it was @p for closest player and used @c for closest... – ethanflips Jun 1 '16 at 19:51
  • You know what? I am just about to ask the same question and I saw your post. – Forcelydated Jun 2 '16 at 5:27

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, or x 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:

/tp @a[y=-64,dy=64] X Y Z

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:

Command block with shaded area beneath it

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:

/execute @a ~ 64 ~ /tp @a[y=-64,dy=64] X Y Z

The following image represents where players (represented by circles) need to be to match:

Origin at players rather than command block

You can either change the Y using /execute's syntax:

/execute @a ~ 240 ~ /tp @a[r=1,c=1] ~ ~-100 ~

Or change it using the y parameter of the nested selector:

/execute @a ~ ~ ~ /tp @a[y=240,r=1,c=1] ~ ~-100 ~
|improve this answer|||||

Have a command block on a fast clock with

testfor @a[y=240]

Have a comparator coming out of that command block and into another one. In that new command block put

tp @a ~ ~-100 ~

Of course you can change the values and if you want it only for specific players. As long as they start under 240 y or if they start above and fall to 240 y they will be teleported. If you have any questions, feel free to contact me.

|improve this answer|||||
  • Oh, it was that easy, I feel kinda stupid now lol – MrWhiteee Jun 1 '16 at 19:50
  • This will not work. All you've done is changed the origin to y240, but have not added any selection limiters. As such, all players are targeted as if nothing changed and is no different than /testfor @a – Skylinerw Jun 1 '16 at 21:20
  • @Skylinerw can you please explain the correction then... If it is wrong – ethanflips Jun 1 '16 at 21:21
  • @ethanflips It's a long explanation; I've added an answer explaining why you can't just change the origin (along with the solution(s)). – Skylinerw Jun 2 '16 at 5:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.