Change score based on score of killed player
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
Pictures about "Change score based on score of killed player"
How to add a score counter into your Unity 2D game| Easy Unity 2D Tutorial
More answers regarding change score based on score of killed player
Answer 2
This here is a very simple setup that will add the recently deceased player's value
score to the recent killer's money
score. "Recent" in this context means "in the last tick". The chances of two players being killed in the very same game tick are extremely low, therefore I won't take that into account.
First, set up a couple of objectives:
/scoreboard objectives add kills playerKillCount
/scoreboard objectives add deaths deathCount
/scoreboard objectives add money dummy
/scoreboard objectives add value dummy
Whenever a player chooses a class, run
/scoreboard players add @a money 0
/scoreboard players set @a[<class selector>] value <value for class>
The first command will add 0 money to every player. This important since players without any score (rather than 0) cannot be affected by operations.
Place a repeat/chain line of command blocks and have it run
/scoreboard players operation @a[score_kills_min=1,c=1] money += @a[score_deaths_min=1,c=1] value
/scoreboard players set @a[score_deaths_min=1] deaths 0
/scoreboard players set @a[score_kills_min=1] kills 0
The first command will simply fail if a killing and killed player don't exist in this tick.
Bonus: The value
score works on a player by player basis. This makes it easy to add a bounty system (e.g. bonus money for ending a killing spree) by simply adjusting a player's value
.
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Pixabay, RF._.studio, RF._.studio, Monstera