6

I'm using a command like this:

/execute @e[type=ArmorStand] ~ ~ ~ tellraw @a[score_goto=-1]
  {
    "selector": "@e[type=ArmorStand,r=1]",
    "clickEvent": {
      "action": "run_command",
      "value": "/tp @p ~ ~ ~"
    },
    "color":"blue"
  }

To try and make each armor stand in the world say their name (in blue), and, if the player clicks the armor stand's name in-chat they will be teleported to that armor stand.

Currently, it looks like this:

Chat shows two blue armour stand names, Command_Hub and Command_Tester

And, when I click either of the two names, I'd like to be teleported to that armor stand, hence the

"clickEvent":{"action":"run_command","value":"/tp @p ~ ~ ~"}

part within the command.

However, because run_command apparently only inserts the command into the player's chat, I just get teleported to wherever I currently am when I click any name.

So, I tried:

"clickEvent": {
  "action": "run_command",
  "value": [
    "/tp @p @e[type=ArmorStand,name=",
    {"selector": "@e[type=ArmorStand,r=1"},
    "]"
  ]
}

Thinking that maybe the JSON in value would be parsed, producing my desired value of

"value": "/tp @p @e[type=ArmorStand,name=Name_Of_This_Armor_Stand]"

but no luck.

Everything I've tried just doesn't seem to work, can someone please help me find a way to make a tellraw clickEvent teleport the player to the entity which executed the tellraw command?


TL;DR

Please help me find a way to make a tellraw clickEvent teleport the player to the entity which executed the tellraw command?

13
  • As an aside, you are aware that only ops will be able to do this, right? The run_command uses whatever privileges the user has, and only ops can tp.
    – MBraedley
    Jan 24, 2016 at 16:39
  • @MBraedley Yes, it's my single-player world though. I don't plan on inviting many people at all. Thanks though :) Jan 24, 2016 at 16:46
  • 2
    Can't think of a simple way to do this; I think you'd probably have to give each ArmorStand something unique (e.g: a name) then run a separate command for each ArmorStand. As a side note, because of the inconsistent way Mojang implemented relative coordinates, something like /tp @p ~ ~2 ~ will always teleport @p 2 blocks up from @p, rather than 2 blocks up from the executer of the command like how relative coordinates in other commands would work.
    – SirBenet
    Jan 24, 2016 at 17:25
  • @colorfusion Can't think of a simple way to do this - nether can I, that's why I'm asking here; I think, by this point, "simple" is completely out of the question. Also, my armor stands already have names, and an execute command is already running tellraw for each armor stand. I disagree that Mojang's implementation of the tp command is inconsistent; it works exactly as one'd expect. It's just in this case, I need a way for the tellraw-er to run a command, as opposed to the player. Jan 24, 2016 at 17:31
  • 1
    This is tough. You need to inject a variable into the clickEvent:{value:}, but there isn't a way to do that.
    – MBraedley
    Jan 24, 2016 at 19:19

2 Answers 2

2

Do this for all of your armor stands. I believe this is the only way for it to work. It is going to be more command blocks, but I think its the only working one.

/execute @e[type=ArmorStand,name=(insertname)] ~ ~ ~ tellraw @a[score_goto=-1]
  {
    "selector": "@e[type=ArmorStand,r=1]",
    "clickEvent": {
      "action": "run_command",
      "value": "/tp @p @e[type=ArmorStand,name=(insertname)]"
    },
    "color":"blue"
  }
4
  • I also think it might be the only working method, but I was trying to avoid having to do this. I'd like to be able to automate the creation of these 'waypoints', and creating a new command block for each one is a tedious business. Mar 29, 2016 at 17:29
  • I am sorry @theonlygusti but it is the only way I know of. but i figured i try and help
    – Lectric
    Apr 1, 2016 at 22:34
  • If you can think of a way to summon command blocks with a certain command and the name of the armor stand then this answer could become useful. Apr 2, 2016 at 10:41
  • I am sorry to say I dont think it would work without manually implanting the name in the command block. I could be wrong but i do not know how it would work.
    – Lectric
    Apr 8, 2016 at 15:50
-1

You can do this on non-op players using scoreboards and the trigger command.

First, setup an objective with the triggercriteria:

scoreboard objectives add OBJName trigger

Now enable players to use the trigger command (more below):

scoreboard players enable PLAYER OBJName

Now that it is enabled, instead of doing the tp command directly use this command:

/trigger OBJName set 1

This will set the non-op's score of OBJName to 1. Now you can use an execute command to teleport the player:

execute @a[score_OBJNaNe_min=1] ~ ~ ~ tp @p @e[type=Armorstand,name=x]

This tests for players with a score of 1 in OBJName, then teleports them to the @e entity. To TP to an Armorstand, it needs the customname nbt tag set and that value to replace X in the above command

Next, you most likely want to setup protection. When you use the tellraw, you should enable the player then disable when you don't want them to be able to use it.

When you say the tellraw, also execute this:

scoreboard players enable PLAYER OBJName

Then, when they click the tellraw do your stuff then use this

scoreboard players disable PLAYER OBJName
4
  • 1
    Thanks for the answer, but this isn't actually what I asked for. I want to know how I can teleport the player to the armor stand which executed tellraw. All of what you just told me, I already knew anyway. Jan 24, 2016 at 18:25
  • @theonlygusti I'm on mobile so I accidentally pressed submit. Updated with Armorstand stuff
    – Judge2020
    Jan 24, 2016 at 18:26
  • 1
    No, really, this post does not answer my question at all. I learned nothing from your attempt at answer, how can I teleport the player to one of several armorstands (variable number) using this method? I'd downvote, but don't yet have the rep on this site. Jan 24, 2016 at 18:56
  • 1
    The reason this won't work is because the number of armorstands can change, and I need to run the same command for each armour stand; I can't just have each armour stand create a different player scoreboard objective , and then update that scoreboard objective within a tellraw clickEvent, and then I can't check all of those variable number of different scoreboard objectives using another line of command blocks. It just won't work. Jan 24, 2016 at 18:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .