How can I test for a player at a given x and z but at any height?
I am trying to test for if a player is at a certain x and z, but not a certain height, and I can't find anything that says how to do it. Here's what I have:
/testfor @a[x=-50,z=79,r=1]
The problem is, it's only true if the player is standing on the command block, and I need it to be true if the player is anywhere directly above the command block, like five blocks above. What am I doing wrong?
Best Answer
Unspecified origin parameters will default to the sender's location, being the command block. You can change the origin to be that of the player so that the x, y, and z parameters default to their position instead of the command block.
/execute @a 50 ~ 79 /testfor @a[c=1,r=1]
Pictures about "How can I test for a player at a given x and z but at any height?"



How do you test a player in Minecraft in a certain area?
2. Type the CommandHow do you detect if a player is in a certain area?
Enter /position in Minecraft to see your current world position in the top left corner of Minecraft. You can also use the player world position block in your code. This way, no matter where you are in the game world, your code can use your position to do things near you.Detect When A Player Is At A Block/Blocks Minecraft
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: MART PRODUCTION, MART PRODUCTION, Harrison Haines, MART PRODUCTION
