How to get a command block to say the name of a named mob
//ads -- adsterra.com -- native banner
?>
I'm making a horse racing track and I want the game to say "[name of horse] has finished the race!" when a horse crosses the finish line. I can get it to say the name of every horse in the area, but not just the one that activates the block.
Best Answer
If you're activating the command block with a pressure plate you could use the @e
selector combined with sort=nearest
and limit=1
like this:
/tellraw @a ["",{"selector":"@e[sort=nearest,limit=1]"},
{"text":" has finished the race!"}]
If players are riding the horses you could also add type=horse
in the selector:
/tellraw @a ["",{"selector":"@e[sort=nearest,limit=1,type=horse]"},
{"text":" has finished the race!"}]
Pictures about "How to get a command block to say the name of a named mob"
How do you get a command block to say something with a name?
How to Enter the CommandHow do you give a command block a mob name?
Steps to Use a Name TagHow to Make Mobs Named Dinnerbone Fly | 1.17.1 Command Blocks Java
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: RODNAE Productions, Angela Roma, Monstera, Tara Winstead