I would like to make a minecraft map where command blocks say would you like to go to lava parkour? Then if you say yes it will tp you if you so no nothing happens. I was thinking it's probably a /testfor @p/say"yes" or something I'm in the latest snapshot it is probably no something possible but I would like to try
2 Answers
Here's something little input together with the /tellraw
command. All you have to do is click on Teleport?
when the message shows up in chat. Here's the command:
/tellraw @a {"text":"","extra":[{"text":"Would you like to teleport?","clickEvent":{"action":"run_command","value":"/tp @a <x> <y> <z>"},"hoverEvent":{"action":"show_text","value":"Teleport?"}}]}
Remember to replace <x> <y> <z>
with the specific coordinate values. You can also add colors to the text, but I'll let you figure that one out. Note: In order for this message to appear in chat, the command block containing it must be activated in some way. Anyways, hope this helps!
Note I haven't had time to fully test this yet, so tell me if something is wrong. Thanks!
Another note: If players are required to be an OP, switch their gamemodes to creative, then after they teleport back to survival.
-
This will require that the person getting the message have permission to teleport themselves, won't it? Commented Jun 30, 2014 at 13:03
-
@BillyMailman I'm pretty sure players in survival, if commands are enabled, are able to teleport themselves without requiring OP. Commented Jun 30, 2014 at 13:06
-
2@DatEpicCoderGuyWhoPrograms seeing that
/tp
requiresop-permission-level
of 2 or more, non-OPs surely can't. Trigger-type objectives can be used (or are meant to be used) for exactly this kind of thing.– MrLemonCommented Jun 30, 2014 at 13:34 -
-
@kingbluesapphire Just because it's singleplayer, there a level-based restrictions on which players can use certain commands. For example, in order to summon in mobs, you must be in creative mode with cheats on. Commented Jun 30, 2014 at 17:59
Building on DatEpicCoderGuyWhoPrograms' Answer (and stealing his json for tellraw), you can use trigger
to circumvent needing OP permissions to teleport on click. They have to be enabled for a player (done via commandblock), who can then use the /trigger
command to modify his score once, then the trigger is disabled again.
Tutorial
Set up a trigger objective (once) using
/scoreboard objective add <name> trigger
Use two command blocks with
/scoreboard players enable <player> <name>
/tellraw @a {"text":"","extra":[{"text":"Would you like to teleport?","clickEvent":{"action":"run_command","value":"/trigger <name> set 1"},"hoverEvent":{"action":"show_text","value":"Teleport?"}}]}
The teleport itself is done via a command-block hooked to a clock, using
/tp @a[score_<name>_min=1] <x> <y> <z>
Replace all values in <>
with the appropriate values.
-
1Thanks for adding on some info to this, I didn't realize OP was needed until now. Commented Jun 30, 2014 at 14:40
-
Also, you just reached 1000 reputation! Congrats! Commented Jun 30, 2014 at 14:40