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

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.



Best Answer

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.




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

How do I detect a player in a x,y,z,radius, remotely? - Person Holding Game Pad
How do I detect a player in a x,y,z,radius, remotely? - From above of young sportive female athlete in activewear on blue sports ground
How do I detect a player in a x,y,z,radius, remotely? - Aerial view of distant person playing tennis on aged weathered tennis courts on lush green meadow



What is the command for nearest player?

@p (Nearest Player) The nearest player will always be the player closest to the location where the command is run. If a command block has executed the command, the nearest player to the command block will be targeted.

How do you connect Redstone with command blocks?

To activate the command block, just activate the redstone device that is attached to the command block. In this example, the redstone device is a lever. So you would activate the command block by toggling the lever.



Getting Started with RADIUS Single Sign-on




More answers regarding how do I detect a player in a x,y,z,radius, remotely?

Answer 2

you can do this with /testfor @a[x=X,y=Y,z=-Z,r=R]

XYZ and are coordinates and R is the radius.
Just put the command in a commandblock and update it frequently using redstone. A Comparator that has ben put at the commandblock will be activated if the statement is true and deactived if its false.

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Geometric Photography, EVG Kowalievska, Harrison Haines, Ryutaro Tsukata