0

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.)

9
  • Hmm... This actually might be possible with a scoreboard players operation command, but I'm not completely familiar with how that actually works, unfortunately
    – Unionhawk
    Commented Apr 21, 2016 at 16:38
  • += mode might work with a "money increase" score, but I still need to detect the killer and the killed. Commented Apr 21, 2016 at 16:42
  • Have you tried any commands yourself? Showing some effort first may be a good idea.
    – 54D
    Commented Apr 21, 2016 at 16:50
  • Nope. I'm still setting up some PvP maps. Commented Apr 21, 2016 at 18:02
  • So if a player were to kill ten people he could buy a rank for ten dollars and then if a player killed the ranked player they got twice the amount of money to buy a better rank, or something like that?
    – Jason_
    Commented Apr 21, 2016 at 20:15

2 Answers 2

1

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
1
  • Should work for the solo mode, but won't work for the team mode (but I'll figure it out) Commented May 12, 2016 at 15:12
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .