4

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

Thank you.

7

Tellraw allows for a "selector" part, which takes any selector you want and displays a name. You should do:

/tellraw @a {"text":"","color":"blue","extra":[{"selector":"@p"},{"text":" has won the game!"}]}

This will only work in 1.8 snapshots and above. There is no way to do this in older versions.

0

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

  • I know that, but what I was looking for is how to apply that in a tellraw command, because with the /say command, the ouptput is "[@]JasonSPQR has won the game!" and i don't want that "[@]" – JasonSPQR Jun 5 '14 at 13:30
  • i'm not sure how to prevent the @ from appearing... – jc3833 Jun 6 '14 at 4:04
  • Rename the command block to the name of your game, then it will be [game] Person won – Yet Another User Jun 7 '14 at 18:10
0

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.