Is there a way to display a player name in /tellraw command?
like the title says, I'm looking for a way to display a player name in a /tellraw command which is run by a command block. Example:
/tellraw @a {"text":"","extra":[{"text":"A player has won the game!","color":"blue"}]}
And the output is something like this:
A player has won the game!
But I want the output to be something like
JasonSPQR has won the game!
Using the @p parameter
Best Answer
you could perhaps make the game work with the scoreboard feature, then in the case of the game being a deathmatch kind of thing, or something where you have a limited number of kills or something like that, you could make the command block check the scoreboard for a certain score, when that score is met, you could then use a comparator to have the command block output a redstone signal and contact another command block, which says [player with score=x] wins, and you could do other things similar to this for a race, in which case, you'd have a line of command blocks buried beneath the finish line, the command blocks would be running the /testfor command, then from those command blocks, you'd run a compator to a repeater, from the repeaters, you'd run a redstone wire to a command block saying [player] wins or [player] has crossed the finish line
Pictures about "Is there a way to display a player name in /tellraw command?"



How to get /tellraw command to say player names
More answers regarding is there a way to display a player name in /tellraw command?
Answer 2
Use the Scoreboard Command like one of the other answers said:
/tellraw @a {"text":"","color":"blue","extra":[{"selector":@p[score_wins_min=1},{"text":" has won the game!"}]}
And then a Comparator going into a repeater going into a Command Block:
scoreboard players set @a wins 0
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Andrea Piacquadio, Pixabay, Mike B, George Becker
