1

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 walks 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).

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

3

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
0

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}

0

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.

0

This worked for me in version 1.14.4 of the Java Edition, on a repeating Command Block.
The command picks every value that's between x and dx - same with every other axis - and will show whatever message you want:

/msg @a[x=~,dx=~,y=~,dy=130,z=~,dz=~] (message here)

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.