I see two main ways to do this, neither of which are that great. If it's not necessary, I'd recommend not doing this.
First way would be to set the score individually for each level, like this:
/scoreboard players set @a[l=0,lm=0] XPScore 0
/scoreboard players set @a[l=1,lm=1] XPScore 1
/scoreboard players set @a[l=2,lm=2] XPScore 2
...
The main problem with this method is that you'll need a ton of command blocks. I'd probably go with supporting 127 levels if this is just vanilla/survival.
Next method is a bit more complicated, but would cut down the command blocks needed from 127 to around 30 whilst still supporting the same max level.
First, you'd set everyone's XP score to 0:
/scoreboard players set @a XPScore 0
Then, in this exact order, run these commands:
/scoreboard players add @a[lm=64] XPScore 64
/xp -64L @a[lm=64]
/scoreboard players add @a[lm=32] XPScore 32
/xp -32L @a[lm=32]
/scoreboard players add @a[lm=16] XPScore 16
/xp -16L @a[lm=16]
/scoreboard players add @a[lm=8] XPScore 8
/xp -8L @a[lm=8]
/scoreboard players add @a[lm=4] XPScore 4
/xp -4L @a[lm=4]
/scoreboard players add @a[lm=2] XPScore 2
/xp -2L @a[lm=2]
/scoreboard players add @a[lm=1] XPScore 1
/xp -1L @a[lm=1]
This should set everyone's XPScore to their XP. Problem is that it also sets their XP to 0, so afterwards you need to clone their XPScore to another objective, I'll call mine "XPTemp":
/execute @a ~ ~ ~ /scoreboard players operation @p XPTemp = @p XPScore
Then you need to set their XP level back to what it was before using pretty much the reverse of what was above.
/xp 64L @a[score_XPTemp_min=64]
/scoreboard players remove @a[score_XPTemp_min=64] XPTemp 64
/xp 32L @a[score_XPTemp_min=32]
/scoreboard players remove @a[score_XPTemp_min=32] XPTemp 32
/xp 16L @a[score_XPTemp_min=16]
/scoreboard players remove @a[score_XPTemp_min=16] XPTemp 16
...
1st: /scoreboard objectives add [name] health [display name]
Add any name to name and display name
2nd: /scoreboard objectives setdisplay belowname [name]
Set the name you want to display at the scoreboard at name
(Your health will show up as 0 until you lose some...it's a bug)
Best Answer
This nostalgic contraption was hard to make, is not very pretty, but works.
First of all, create 3 scoreboard objectives: a death count, a player kill count and a dummy objective. Let's call them
ActualDeaths
,PlayerKills
andDeaths
:Now, onto the command blocks:
I will be referring to the command blocks on the screenshot according to the colorful blocks I assigned to them, so for example, the one on the far right is the "blue" command block (and the two command blocks on the left-most are GREEN and PURPLE, not lime and magenta).
Anyways, let's get to the commands:
The blue command block is powered by a redstone clock, and simply tests if anyone has killed a player:
The yellow command block is powered by the same redstone clock as the blue one, and tests if anyone has died:
The purple command block resets the
ActualDeaths
scores, so that the comparators leading from the yellow command block are reset:The red and green command blocks run their commands only if both the blue and yellow command blocks have passed their
/testfor
commands at once (that's why the piston is there). Here's what they do:The red command block adds 1
Deaths
scoreboard point to every player that has a score ofActualDeaths
at least1
(in other words, it gives the point to anyone that has died in the last few gametics):The green command block resets the
PlayerKills
scoreboard, so that the blue command block's comparator is reset:That's it! Be aware that it may not be perfect and it might fail counting in all deaths in cases like two players dying in the same tick, since the only way I was testing this was by shooting myself to death by arrows.