I am trying to create a way for players on my vanilla server to teleport to each other without giving them op. My current idea is to have a list of clickable player names that appear in the chat with a unique click event. I currently have the following command in my datapack:
execute as @a[sort=nearest] run tellraw @p {
"text":"","color":"gold",
"clickEvent":{"action":"run_command","value":"/trigger objective set 1"},
"extra":[{"selector":"@s"}]
}
This works and outputs all the players in the chat. My issue is that I cannot differentiate between the players. If I could replace /trigger objective set 1
with /trigger objective set i
this would work. From my experience there is no way to do this.
The one solution that I came up with would be to embed an execute command in the click event to run \trigger object add 1
the same number of times the execute ran before. It might look something like this:
/execute as @a[sort=nearest] if entity distance <= @s distance run /trigger object add 1
Basically it would ideally loop until it hit the player that was clicked. This would allow me to reverse engineer the score to teleport the correct player to the correct target.
Is there a way that I could somehow do this, or would this be impossible because @s
would technically be the player clicking and not the player clicked.