I am creating and adventure map and I have this shop to where players can teleport to by pressing a button.

So when they press the button it activates two command block:

/tp @p 1016 56 -4060 # Teleports closest player to the shop

/setblock 1015 57 -4063 command_block 0 destroy {Command:"/tp @p[r=3] 1019 56 -4068"} 
# This is supposed to create a command block connected to a button in the shop that lets the player go back to their last position. 

However, the last command never runs and the Command Block is not created. If I remove the radius limitation, though, it creates the command block, but instead of it having "/tp @p[r=3] 1019 56 -4068", it has "/tp Edoreld @p[r=3] 1019 56 -4068", where Edoreld is my username. What I would like for it to do is not to expand my username. Is that possible?


Solution 1:

Okay I tried to rebuild this like you described. I did not tried the first tp command I hope this one is working.

Everything I describe here is running in a clean Minecraft 1.8 on a offline map with cheats activated.

The setblock command should look like this:

setblock -30 79 214 command_block 0 replace {Command:"/tp @p[r=3] -28 79 214"}

If you use the command like that it should working as you described. But I do not know what you actully made wrong... The commandblock should be created also with the @p[r=3] or only a @p inside. It is not possible that the @p is changed to the playername.

This commandblock is configured with the command from above.

Example

This will create a other commandblock two blocks to the left. With the command /tp @p[r=3] -28 79 214 as configured in the first command.

Example

Keep in mind that you have to stay three blocks near the commandblock that is spawing (the right one)!

Otherwise you are not teleported because of the radius limitation you programmed into the commandblock. If three blocks are not enough you have to increase the number or programm a exact block teleport (if it is possible that other players are selected with a bigger radius).