You should use a dummy variable and target selector arguments.
Run once
Have a dummy score, call it healthDif
.
/scoreboard objectives add healthDif dummy
Run every tick, in order
Set each players healthDif
score to their own health score:
/execute @a ~ ~ ~ scoreboard players operation @a[c=1] healthDif = @a[c=1] health
Subtract the other player's healthDif
score from your own:
/execute @a ~ ~ ~ scoreboard players operation @a[c=1] healthDif -= @a[rm=0] health
Now players with a positive healthDif
score will have more health than the other player. Target with @a[score_healthDif=1]
Note this will only work for two players. In order for it to work with more, you have to take a few extra steps.
Run once
First you'll need a dummy variable to store miscellaneous variables. Call it vars
. Note: If you already have a variable for this (you likely do), you can skip this step.
/scoreboard objectives add vars dummy
Run every tick, in order
Put these between the two commands from before.
First, set the #nplayers
to 0:
/scoreboard players set #nplayers vars -1
Now, have each player increment #nplayers
:
/execute @a ~ ~ ~ scoreboard players add #nplayers vars 1
Finally, multiply each players healthDif
score by this number
/scoreboard players operation @a healthDif *= #nplayers vars
This way, you can have any amount of players, and the system automatically adapts!
If you are playing on Minecraft version 1.9+, all you need to do is check that they have 32 points:
/scoreboard players test @p objectivename 32 [2000000000]
Then have a chain command block after it with conditional on with this command in it:
/give @p minecraft:TOOLHERE 0 [amount]
and the next chain command block with conditional on with this command in it:
/scoreboard players remove @p objectivename 32
- The first command block sees that they have 32 kills
- The second will give them a diamond sword
- The third will remove 32 kills from that player
so it can be done much simpler
Best Answer
You can use
/scoreboard players operation
to add all scores up and put them into one score. These two commands put the sum of all scores in the scoreboard "hello" into the score "sum" for the real or imaginary player "Horst":/scoreboard players set Horst sum 0 /scoreboard players operation Horst sum += * hello
Scoreboard "sum" has to exist already, but Horst doesn't. This iterates one every entry in the scoreboard "hello" and adds its value to Horst's score, which is initially 0. You can also replace
*
with a target selector.