1

I am using a mod with the custom map I am making. The mod adds some commands, but they are far from perfect. For example, the command syntax goes like this:

/modcommand foo <PlayerName> DoThis

In a command block I put

/modcommand foo feldspar15523 DoThis

And everything works as expected. However, if I do this:

/modcommand foo @p DoThis

The mod thinks that the player's name is literally @p. My idea was to make it so that when I trigger the block, it first makes another Command Block that has the name of the nearest player in it in the right place. Here is what I need in pseudocode:

/setblock ~ ~+5 ~ minecraft:chain_command_block 1 replace {Command:"/modcommand foo "+ @p +" DoThis"}

1 Answer 1

1

This is impossible. Minecraft doesn't have variables like strings. The best you can do is to output the command in chat, like this:

/tellraw @s [{"text":"/setblock ~ ~5 ~ chain_command_block 1 replace {Command:\"modcommand foo "},{"selector":"@p"},{"text":" DoThis\"}"}]

If you have the log output open, you can then copy the command into chat and run it. A modded client could also automatically execute it, but not a regular Vanilla client.

6
  • I think I got it. Would it work to place a sign that has that command with the name in it and have the user run the command on right click? Jun 18, 2018 at 18:21
  • Before I wrote that answer, I tried to put together a clickEvent with a selector in it in tellraw, but sadly the value of that only allows a single string, not another JSON object. And if it was possible, people would certainly already abuse it to no end. :D Jun 18, 2018 at 18:32
  • I am making a custom altar that runs the command from the mod. The command is only supposed to be for cheating, but I am making an altar that runs the command. Selectors don't work in the cheat command. What would work is have the trigger from the altar trigger a command block that places a sign that runs two commands on click: /modcommand foo <Nearest player's name> DoThis and /setblock ~ ~ ~ air. I am sorry I was not very clear. Jun 18, 2018 at 18:41
  • Your initial question was clearer than that comment. What mod? Jun 18, 2018 at 18:42
  • Avatar mod 2:minecraft.curseforge.com/projects/… The exact command is /avatar bending add <Name> all. Jun 18, 2018 at 18:44

You must log in to answer this question.

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