How can I display stats like death count using titles?

I'm making a dungeon-crawler adventure map, and at the end I would like the system to tell the player, either within the chat or on screen (using /title
) these criteria:
- Number of deaths
- Number of rooms entered (out of X)
- Number of mobs killed
- Number of times fell in lava/from a high place
Things like that. I know that there's a way so that the player can press tab or have it displayed on the right of the screen, but I would like it so it's kind of a credits thing.
Best Answer
As you already have the objectives set up and working, it's fairly simple to output them. You'll need to use the JSON format to get the player's score, like this:
["",{"score":{"name":"*","objective":"ObjectiveName"}}]
Where ObjectiveName is the name of the objective you want to get the player's value of.
/title
already accepts JSON data, so all you need to do is:
/title @p title ["",{"score":{"name":"*","objective":"ObjectiveName"}}]
/say
doesn't accept the JSON format, so you should use /tellraw
instead, which does:
/tellraw @p ["",{"score":{"name":"*","objective":"ObjectiveName"}}]
If you want it as part of a sentence, you could change the JSON part to something like:
["You have died ",{"score":{"name":"*","objective":"ObjectiveName"}}, " times."]
Pictures about "How can I display stats like death count using titles?"



How do you get a death scoreboard?
If the player has their F3 menu open on Java Edition, the coordinates will remain on the screen after the death screen appears. This can allow players to write down their coordinates and backtrack to them if needed.This is How Easy It Is to Lie With Statistics
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Sharad Bhat, Julia M Cameron, George Milton, Julia M Cameron