How do I detect a player in a x,y,z,radius, remotely?

I'm making a "floating piston", so when the player moves into a specific area, the dirt acts as an activator of a circuit.

How can I make the execute (wired up to a pulse clock) work inside a range, and/or coordinates, as in execute @p[x=~10,y=~,z=~15,r=5] ~ ~ ~ setblock 400 15 400 dirt I would have 4 command block, one for each colour.

I did this earlier with /testfor @p[r=3] , a pulsar per commandblock, and a comparator+repeater, just beneath where it was supposed to go, but I figured it would look neater if I moved all the command blocks away from the gamezone itself, because there were little space. Easier to troubleshoot and edit aswell.

It did work for execute @p ~ ~ ~ setblock 400 15 400 dirt , but as soon as I add dataValues to the player, the UUID fails, saying the expresion is wrong.

I might use scoreboards to do some stuff aswell, but it's a bit messy yet, so I prefer avoiding using them yet.

The purpose of the game is making a Stadium where you select your "color" (which will all give you different benefits), on each side of the stadium. When you are finished choosing your color, you get into the arena, and you fight against the other player (with the same color-selecting, just on the opposite side of the arena).

Color-selection, where the middle zone, currently red(wool), shows the present selected color

I could do it with buttons, but hey, it looks cooler with just moving over the coloured glass.

Thanks in advance.


I have two possible solutions for you.

First Solution

If you are trying to select a player using the selector relative to where the player is located from a specific coordinate, the selector code doesn't except the '~' character like many commands do to communicate relative coordinates. Instead use dx, dy, & dz. As an example, using the numbers from your execute command

execute @p[x=X,y=Y,z=Z,dx=10,dy=0,dz=15] ~ ~ ~ setblock 400 15 400 dirt 0 replace

This will select a player remotely, as you described above, if your command block is far away (within 16 loaded chunks I believe), and will set up a "volume" or a "box" that is x=~10, dy=~0, and dz=~15 that has an origin (starting corner) at the specific coordinate x=X, y=Y, & z=Z, where X, Y, & Z are positive or negative integers: decimal numbers are not excepted.

As long as the location/zone where the player needs to be detected isn't moving to some other location in the world, this should work just fine.

Second Solution

If the player walking over blue stained glass, for example, could be used to trigger your event instead, here's how you might accomplish that.

execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:stained_glass 11 setblock 400 15 400 dirt 0 replace

The documentation from the official minecraft wiki looks like this

execute <entity> <x> <y> <z> detect <x2> <y2> <z2> <block> <data> <command …>

where <data> is where you would enter the data value of the color of glass you wish to use to trigger a specific event (11 being blue). <x2> <y2> <z2> are just the coordinates of the block you'd like to detect. In the example I used ~ ~-1 ~ which just detects for a blue stained glass block below all players (which the all players @a selector can be replaced with whatever selector you happen find best to use).

Hopefully this helps.

As a Warning

Based on what I have read from the wiki, it may cause the execute command to fail if a player who does not have permission to execute the specified command is selected. Which means, if your players are meant to be in survival or adventure mode, you may have to use the execute command on an invisible entity (such as an armor stand with NBT tags set to {Marker:1,Inivisible:1}) to detect whether a player has entered the specified area, and then trigger the event that way.