1

How can I use command blocks to test for whenever a player is standing on a certain block within a certain area, and then teleport them?

  • 1
    I got the answer from Stefnotch from youtube: Command: /execute @a ~ ~ ~ detect ~ ~-1 ~ sand -1 tp @a ~ ~-5 ~ – John Klubertanz Jul 5 '15 at 15:13
5

I got the answer from Stefnotch from youtube. The command is:

/execute @a ~ ~ ~ detect ~ ~-1 ~ sand -1 tp @a ~ ~-5 ~
  • Could you explain what each of the arguments in the command mean? Thanks – Spyfiend13 Dec 3 '15 at 18:22
  • the squigglies, or tildes (~) refer to relative coordinates, ~1 ~-1 ~ means the affect is applied to one up on the x coordinate, 1 down on the y coordinate and on the same z coordinate. @a means all players. the detect function of the /execute command means that the executor tests for a block from a certain point. the arguments after that is teh command executed – Chemical Comrade Nov 28 '16 at 6:35
2

You can use this command. Note that the location of the command block doesn't matter.

/tp @a[x,y,z,r] tx ty tz 

x, y, and z are the coordinates of the block where you want to test for players.

r is the circular radius that the player must be inside. The location you specified with x, y, and z is the central point of this radius.

tx, ty, and tz are the coordinates that you want to teleport the player to.

Some examples:

/tp @a[0,0,0,10] 1 2 3           

See if a player is within 10 blocks of 0, 0, 0. If so, teleport them to 1, 2, 3.

/tp @a[100,6,38] 1 2 3

See if a player is at 100, 6, 38. If so, teleport them to 1, 2, 3. The radius isn't specified, so the player has to be on the exact block.

Make sure you pay attention to the details. No space between "a" and "[". Commas between x, y, and z but not between tx, ty, and tz. Good luck!

  • but what if i want to have them teleport only if they're on a certain block? – John Klubertanz Jul 4 '15 at 14:02
  • @JohnKlubertanz Then test for the location above the block. ie. On top of 0 0 0 would be @e[0,1,0,r=1] – aytimothy Jul 4 '15 at 14:12
  • @MBraedley, Thanks for editing my answer and correcting my mistake! Sometimes I feel like I'm physically unable to press the comma and not press the space bar! – Nick B. Jul 4 '15 at 16:24
  • 1
    you guys don't understand. I dont want to test for players in a radius, because it could detect players in the air. What I want is a giant pad like a lift where if a player is physically standing on the pad, they get teleported down to the room below. – John Klubertanz Jul 5 '15 at 14:56
  • You could simply have the platform be FallingSand entites with {NoGravity} set to "1b" and then the player simply falls through the platform – Chemical Comrade Nov 28 '16 at 8:17
1

A more user-interface style would be to have buttons on the wall with signs above them that say things like "Level 2" or "Second Floor: Storage" and command blocks behind them or activated by a /testforblock command that have /tp commands such as

/tp @p x y z

/tp @a[team=Elevator] x y z

/tp @a[r=2] x y z

I used this system very much when i was building my first command block world called "Megalopolis". It involved players exploring a vast city and trading with villagers to get title deeds, keys and coins. When using this a lot on structures with evenly spaced elevators, copied commands and relative coordinates sped up programming significantly.

Obviously, you could use the detect function used in previous answers, but this is simple and rather more decorative.

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.