2

I want players to be able to click text to run an OP command even if that player is not an OP. For example something like:

Console: Do you want to enable Fly? [If you do, Please click here]

*Player1 clicks that text*

Console: /fly Player1

Is something like this possible?

Vemonus
  • 63,784
  • 66
  • 267
  • 403
EnderDragonEP
  • 33
  • 1
  • 4
  • Have you made any attempt to solve this yourself? Arqade works better when askers show effort to solve their own problems; we see that you have a problem you've worked on, and answerers respond to that. You also get a more specific answer that's tailored exactly to the part you're stuck, and Arqade gets a very specific question. Everybody wins! – Frank Aug 23 '17 at 02:36
  • Yes, I did try this myself in my test world, but I really can solve this out myself.... So I came here for help :( I use scoreboard and trigger command to test it but I just... stuck for about 3 hours. I see Xisuma's one player sleep video before, so I know some basic commands. I have a small Server, not too many peoples play it, I just want my players can fly to build something but I don't want players to use fly all the time, So I decided to try it. and.... I am sorry for my broken English. – EnderDragonEP Aug 25 '17 at 20:04
  • I really thank all of you guys correcting my broken English and help me to solve this out! I really appreciate it! – EnderDragonEP Aug 25 '17 at 20:09

2 Answers2

6

It is a bit of a chore but you can use tellraw command along with a scoreboard.

First create a trigger objective (manually type this in chat):

/scoreboard objectives add TellTrigger trigger

Then you have to enable the trigger for the players who should be able to access your command. You can put this command into a repeating / unconditional / always active command block to allow anyone access:

/scoreboard players enable @a TellTrigger

You could also be more selective with the target selector if you have teams or some other selection method. (ex: @a[team=red])

If using the always repeating command block, I recommend disabling command block output to prevent chat spam using command:

/gamerule commandBlockOutput false

The trigger command can now be used:

/trigger TellTrigger set 1

Use that command as a clickEvent in a tellraw command. Here is a tellraw generator you can use to create it.

Here is a tellraw command you can use:

/tellraw @a ["",{"text":"Do you want to enable flight?  "},{"text":"[Click Here]","color":"aqua","clickEvent":{"action":"run_command","value":"/trigger TellTrigger set 1"}}]

Note: Players with the trigger enabled can just type /trigger TellTrigger set 1 and it will do the same thing as clicking the tellraw. They would have to know the objective name though, so it is unlikely.

Note 2: When a player clicks the tellraw, it disables their access to trigger. If you are not using the repeating command block, you will have to re-enable for them to use it again.


That was just the setup. Now you have to create a chain of command blocks to detect the score, set fly mode for player, and set that players objective score back to 0. If you have only specific players trigger enabled, you can also re-enable their trigger in this chain.

The first block will detect the objective score, it starts everything. It is a repeating / unconditional / always active command block running this command:

/testfor @a[score_TellTrigger_min=1,score_TellTrigger=1]

The next block runs the desired higher authority command. It is a chain / conditional / always active command block with:

/fly @a[score_TellTrigger_min=1,score_TellTrigger=1]

The next block is used to re-enable access to trigger. If you are using the repeat command block to enable access, you can skip this block. It is a chain / conditional / always active command block with:

scoreboard players enable @a[score_TellTrigger_min=1,score_TellTrigger=1] TellTrigger

The final block resets the objective score to 0 so that it will not continue to be detected by the first command block. It is a chain / conditional / always active command block with:

scoreboard players set @a[score_TellTrigger_min=1,score_TellTrigger=1] TellTrigger 0

If there is still confusion, Dragnoz has a youtube video with a similar method: Here

You can also do an internet search with string minecraft tellraw trigger and it brings up several different examples.

IronAnvil
  • 5,663
  • 1
  • 14
  • 31
0

I can give you an idea of how it should look like, but /tellraw would execute the command as if the player typed it, so it's not possible to override the permissions they (don't) have. If you want them to use fly they would still need the proper permissions.

There may be a workaround for that using other stuff, but in /tellraw directly it's not possible.

Anyway, here is how you would do it:

/tellraw @p {
    "text":"Your message",
    "clickEvent":{
        "action":"run_command",
        "value":"/say Hello world!"
        }
    }

This shows as "Your message" and lets you say "Hello world!" when clicking on it.

Or in your case if the command was valid:

/tellraw @p [
    "",
    {"text":"Do you want to enable Fly? ["},
    {"text":"If you want, Please click here",
     "clickEvent":{
        "action":"run_command",
        "value":"/fly player1"
         }
    },
    {"text":"]"}
]

As you can see you can even have more than one text here giving you the opportunity to make players choose from commands or build a text with different things, colors, etc.

/tellraw @p {one text parameter}   
/tellraw @p ["",{multiple},{text},{parameters}]
dly
  • 15,249
  • 8
  • 53
  • 81
  • I try this before, It just let players forced to use command, but it did not work with out permission. I only use this to fool my players to suicide themselves XD – EnderDragonEP Aug 25 '17 at 20:24
  • They know fly command but don't know how to use trigger command! And now I know how to use it, I can even add a /scoreboard players disabled Fly @a to disabled trigger command! – EnderDragonEP Aug 25 '17 at 20:27