At the moment, I have been dedicating time into learning command blocks. I am stumped on something at the moment.

I am trying to make it so when you shift on coal blocks in certain co-ordinates it'll take 3 seconds then set to air and give you the coal blocks. But, I am wanting it so there's a duration of cool-down between this.

I am trying to testfor players outside of the area and give them a tag to remove them from this. So, I'd have people outside with the tag "outside' while people in that areas tag gets removed

The main problem being, how do I test for players outside of said co-ordinates.

Edit: I know there is an alternative way to do this, I just want to try something new.

  • I'm sure you can define an area for this, so long as it is within a radius of a point, or within an x by y area. – Ben Mar 27 '18 at 3:33

Using target selector arguments, you can target players who are inside a defined bounding area. You can use this target selector to add a tag to players who are inside this area. You can then add a tag to all players who do not have the inside tag.

Add a tag to all players within area:

scoreboard players tag @a[x=X,y=Y,z=Z,dx=DX,dy=DY,dz=DZ] add Inside


scoreboard players tag @a[x=X,y=Y,z=Z,r=R] add Inside


scoreboard players tag @a[r=R] add Inside

Then add a tag to all players who do not have this tag:

scoreboard players tag @a[tag=!Inside] add Outside

You can then target players inside or outside the bounds:
@a[tag=Inside] or @a[tag=Outside]

You will have to remove both tags, each cycle, so it updates players status as they enter/exit the bounds. You can do this with a repeating chain of four command blocks with commands:

scoreboard players tag @a remove Inside
scoreboard players tag @a remove Outside
scoreboard players tag @a[x=X,y=Y,z=Z,r=R] add Inside
scoreboard players tag @a[tag=!Inside] add Outside

However, I suspect this solution is adding some extra steps you don't need.

You said want to target players within the bounds while excluding players outside the bounds. The target selectors used in the first half of this solution already target only those players without the need for tags at all.

  • Nearly what I wanted, but I need it to the point to where you leave the bounds it takes away the tag InBounds. (Inside) Because, after the coal blocks get turned away, I need to remove the tag. With stat.sneakTime, I am making it detect the length they sneak in the said area when you have the time. I don't want it detecting the sneak length with people outside the area. I have a command block with "/scoreboard players set @a[tag=!inBounds] sneak 0" and when they leave the area with the coal, it still adds to their sneak total. – Sammy Guavs Mar 27 '18 at 4:25
  • I had mentioned needing to remove the tags each cycle in the original answer but I edited the answer to expand that section. I mention a chain of command blocks. You can then add your sneak reset command to a 5th command block in that chain. Make sure all command blocks are set to Unconditional. – IronAnvil Mar 27 '18 at 15:32

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.