0

I have Minecraft 1.12.2 (for Java Editon), and I'm trying to make a contraption that will keep spectators of certain levels within a certain area. I already have something that works, but it only works with one player. My command is show below:

/testfor @a[x=79,y=53,z=-102,dx=25,dy=25,dz=25,m=3]

The command checks if there is anyone within the zone. However, it doesn't check which players leaves the zone, but only the last person who left it. I need a command that will check if any spectators leave the zone. There are also multiple levels, 12 to be exact. Each level will need its own spectator zone and I don't want them to interfere with each other. I have tried /testfor @a[!x=79,!y=53,!z=-102,dx=25,dy=25,dz=25,m=3] but it doesnt work. Any help would be appreciated!

1 Answer 1

1

First, create a dummy scoreboard objective. I've called it spectatorInBounds here.

/scoreboard objectives add spectatorInBounds dummy

Once you have that, make a repeating command block with the command:

/scoreboard players reset @a spectatorInBounds

Then, for each 'zone' you have, add a chain command block with the command:

/scoreboard players set @a[x=X,y=Y,z=Z,dx=DX,dy=DY,dz=DZ,m=3] spectatorInBounds 1

Finally, to check for a spectator that is out of bounds:

/execute @a[score_spectatorInBounds=0] ~ ~ ~ [. . .]
1
  • Note that using /scoreboard players reset actually is different than /scoreboard players set @s 0. When using the former it removes the value entirely, not sets it to 0! Whether it is still registered as 0 in target selectors though I don't quite know, reply if you do! May 24, 2020 at 3:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .