Minecraft – Change score based on score of killed player

minecraft-commandsminecraft-java-edition

I'm making a PvP server with player classes and money, and I want to award players money based on the class of the player they killed. (Both are scores.)

Best Answer

Note: this only works by using colored nametags and teams. If you cannot allow those, or are already using them, this solution will not work

These examples use two classes, but they are rather tesselable:

Create the teams:

/scoreboard teams add c1
/scoreboard teams option c1 color red (you can change the 'red')
/scoreboard teams add c2
/scoreboard teams option c2 color blue (you can change the 'blue')

Create the scoreboard variables:

/scoreboard objectives add killc1 teamkill.red (same as above)
/scoreboard objectives add killc2 teamkill.blue (same as above)
/scoreboard objectives add constants dummy
/scoreboard players set ten constants 10
/scoreboard players set twenty constants 20
(if not yet done:)
/scoreboard objectives add money dummy

At the end of the game, run these commands in order to update the money:

/scoreboard players operation @a killc1 *= ten constants
/scoreboard players operation @a killc2 *= twenty constants
/execute @a ~ ~ ~ scoreboard players operation @p money += @p killc1
/execute @a ~ ~ ~ scoreboard players operation @p money += @p killc2