Updated:
1. Round zones with distance
/execute positioned 100 64 200 as @a[distance=..5] run title @s actionbar "You are in the plaza"
distance=..5 means 5 blocks or less from the given point.
2. Boxes with dx, dy and dz
/execute as @a[x=100,y=60,z=200,dx=10,dy=5,dz=10] run title @s actionbar "You are in the room"
x, y and z are one corner and dx, dy and dz are the size from there, so this box covers x 100 to 110, y 60 to 65 and z 200 to 210. Any part of the hitbox inside counts. Always give x, y and z, or the box starts where the command runs.
3. Run once on entry (repeating)
/execute as @a[x=100,y=60,z=200,dx=10,dy=5,dz=10,tag=!in_room] run title @s title "Welcome"
/tag @a[x=100,y=60,z=200,dx=10,dy=5,dz=10,tag=!in_room] add in_room
The tag stops the title from repeating while the player stays inside.
4. Detect leaving (repeating)
/execute as @a[tag=in_room] unless entity @s[x=100,y=60,z=200,dx=10,dy=5,dz=10] run title @s actionbar "You left the room"
/execute as @a[tag=in_room] unless entity @s[x=100,y=60,z=200,dx=10,dy=5,dz=10] run tag @s remove in_room
Tagged players outside the box have just left. Removing the tag lets step 3 fire again next time.
5. Example: safe zone (repeating)
/effect give @a[x=100,y=60,z=200,dx=10,dy=5,dz=10] resistance 1 4 true
/effect give @a[x=100,y=60,z=200,dx=10,dy=5,dz=10] regeneration 1 1 true
6. Zones from markers
/summon marker ~ ~ ~ {Tags:["zone"]}
/execute at @e[type=marker,tag=zone] as @a[distance=..6] run effect give @s glowing 1 0 true
One command then works for every marker, and moving a zone means moving its marker.
Troubleshooting
- Nobody selected: check the corner coordinates and that dy is tall enough.
- Fires outside the area: dx is a size, not the other corner.
- Title repeats: make sure the tag is added in step 3.
Check your command
The Command Error Doctor checks common syntax mistakes in your browser.