Minecraft Java Edition – How to Test for a Kill Made by an Entity

minecraft-commandsminecraft-java-edition

I am making a map based on spellcasting. There are 5 unique classes, and there can be only 1 player per class. The spells are retextured invisible snowball with particle effects that carry the launcher "class" score:

/execute @e[type=Snowball,score_Lifetime=1] ~ ~ ~ /scoreboard players operation @e[type=Snowball,c=1] class = @p class

I want to check and add a point in the "kills" scoreboard for a player that kills another player with a snowball power, for example the 1st class summons a creeper where the snowball lands.

Best Answer

I know this question is old, but since I have an answer I might as well post it.

You can add the snowball (or an entity summoned by the snowball) to a particular team depending on the snowball's class. You can then create a scoreboard objective tracking 'killedByTeam.that_team's_color' for every player. Any given player's kill count will be the sum of all scores in the corresponding objective.

so for example, if you've got a class sorcerer with a class score of 3, you could do this:

Run once at the beginning:

/scoreboard teams add Sorcerer
/scoreboard teams option Sorcerer color gold
/scoreboard objectives add sorcererKill killedByTeam.gold
/scoreboard players set @a sorcererKill 0

Run in a repeating command block:

/scoreboard teams join Sorcerer @e[type=Snowball,score_class=3,score_class_min=3]

(or something to that effect to select an entity summoned by the snowball)

Then when you want to check the sorcerer's kill count:

/scoreboard players operation @p[score_class=3,score_class_min=3] kills += * sorcererKill

(if you're planning to check this score more than once, you'll also want to run /scoreboard players set @a sorcererKill 0 at this time.)

this may not work in cases where the spell sets off a long chain reaction or includes something like fall damage that isn't attributed to an entity, but it sounds like you know your way around the scoreboard, so you can probably adapt this setup to cover those cases.

Hope this helps!