Minecraft Java Edition – How to Place Players in Team Based on Kill Count

minecraft-commandsminecraft-java-edition

I'm trying to make two teams that are the "good guys" and the "bad guys".
I'd like it to be like a reputation system where you get good karma for killing bad guys and bad karma for killing anyone but the bad guys.

So far I'm using the following commands:

/scoreboard teams add Team1 Fugitives

/scoreboard teams option Team1 color red

and

/scoreboard teams add Team2 Rescuers

/scoreboard teams option Team2 color blue

I'd like use a command or a command within a command block to do something like the following.

if(playerkillsplayer = true){
variable + 1
}

if(playerkillsFugitive = true){
variable - 1
}

if(variable > 0 ){
team ==  Team1
}

if(variable < 1){
team == Team2
}

How can I do this?

Best Answer

Before you begin,

Use a scoreboard to detect kills:

/scoreboard objectives add kills playerKillCount

One for karma:

/scoreboard objectives add karma dummy Karma

One for deaths:

/scoreboard objectives add death dummy deathCount

And one for a time since last kill:

/scoreboard objectives add timeSinceKill dummy

Finally, have a clock with the following command:

/scoreboard players add @a timeSinceKill 1

Now that the scoreboards are set up, let's begin.

For the first section of code:

if(playerkillsplayer = true){
variable + 1
}

Have the following three commands in a 20 tick clock, making sure that the third command is activated last:

/scoreboard players add @a[score_kills_min=1] karma 1
/scoreboard players set @a[score_kills_min=1] timeSinceKill 0
/scoreboard players set @a kills 0

For the second section:

if(playerkillsFugitive = true){
variable - 1
}

Note: If you want people to be able to reverse their lost karma for killing a good person, change variable - 1 to variable - 2 I'm going to assume you want for people to be able to reverse, otherwise change the 2 to 1 in the commands.

Now have the following commands on a clock powered in the following order:

A limitation is that if another one killed another person in the last 1/10 of a second, it will be activated twice. However, this is very unlikely.

/execute @a[score_death_min=1] ~ ~ ~ scoreboard players remove @p[score_timeSinceKill=2] karma 2
/scoreboard players set @p death 0

Finally, the last two sections:

if(variable > 0 ){
team ==  Team1
}

if(variable < 1){
team == Team2
}

For the first section, on a clock have

/scoreboard teams join Team1 @a[score_karma_min=1]

Second, have a command on a clock:

/scoreboard teams join Team2 @a[score_karma=0]