Minecraft – How to test for a player at a given x and z but at any height

minecraft-commandsminecraft-java-edition

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

You could do this by using the cubic volume selectors (dx,dy,dz) rather than a radius.

For example, to test for players around (-50, 79) with any height (or rather, a height from -5000 to 5000):

/testfor @a[x=-51,dx=2,z=78,dz=2,y=-5000,dy=10000]

This tests for anyone with x from -51 (x) to -49 (x + dx), a z from 78 (z) to 80 (z + dz), and y from -5000 (y) to 5000 (y + dy)