# How do I trigger command blocks when a player walks in an area

I'm currently making an adventure map and I want to know how to trigger command blocks when a player walks through a certain area, for example, if a player walked through a certain part of a cave it would say "Don't go down there" or something. Or it could trigger a jump scare (but that's not what I'm looking for.

I'm making it so when the player walks through an area it say's "I think it would be a good idea to go exploring." in a first person perspective.

To test for a player in some distance from a certain place, use:

/testfor @a[x=X,y=Y,z=Z,r=R,rm=RM]


Where X, Y and Z are the middle coordinates of the area to test for a player, R and RM specify the minimum and maximum distances from the specified coordinates, respectively.

To run a command, eg. /say Hello when the testfor command returns true, place the @a[] part into an /execute command:

/execute @a[x=X,y=Y,z=Z,r=R,rm=RM] ~ ~ ~ /say Hello

• I don't think it works, I probably did it wrong because I have no idea what your talking about as I'm not very good at command blocks, I only know simple commands. This is what I did: /testfor @a[x=-1,y=111,z=-11,r=4,rm=4] for the first command block and for the second: /execute @a[x=-1,y=111,z=-11,r=4,rm=4] ~ ~ ~ /say Hello – RezamatorYT Dec 9 '16 at 19:01
• Or if there was a way to make pressure plates invisible I would do that. – RezamatorYT Dec 9 '16 at 19:04
• @RezamatorYT the second value, rm is not inclusive - eg. r=4,rm=4 will never be true, but r=4,rm=5 should activate if something is in the specified distance. If no player is in the specified area, the command will act as if it was invalid. – RudolfJelin Dec 11 '16 at 19:41

Spawn an invisible ArmorStand on that place, give it a Name:

1.9.x:

summon ArmorStand ~ ~ ~ {Invisible:1,Invulnerable:1,CustomName:"sOp"}

Repeating command block: execute @e[type=ArmorStand,name=sOp] ~ ~ ~ execute @e[r=0] ~ ~ ~ tellraw @s {text:"I think it would be a good idea to go exploring.",color:green,bold:false}

You could put pressure plates down, then when stood on it could /say (Whatever) then you could use /setblock on whatever coordinates the pressure plate was to replace it with air.