How can I detect which specific mob was killed by a player and increase a score accordingly?
I'm making a Tower Defense map and my score system is pretty simple, whenever you kill a zombie the 'Money' scoreboard gets 1 more score.
I used the command
/scoreboard objectives add Money stat.killEntity.Zombie Money
to set up the counter for that.
In my map there are different zombies, some have got more health then others. My problem is, all the different zombies give as much Money. So if the player kills a zombie of Lvl 1 or Lvl 12, the players always just gets 1 money. All the zombies are summoned with a '/summon' command and my solution to this was to give the different zombies different names and somehow make the scoreboard track down what zombie the player killed. (It will check the name of the zombie that has been killed)
Does someone know how? Or an easier or better way? I would highly appreciate it! I've got this problem for a while now and I cant make progress because of this. If someone can help me I'll credit him/her in my map.
Best Answer
If your map is not going to be multiplayer, you may want to consider tracking if each zombie spawned is alive by attempting to execute commands on them and checking if said commands succeed.
Another solution, which I think is probably the best, is to implement custom loot from the different zombies that you spawn, perhaps paper or gold that is renamed to different values, or just different drops from each enemy, that are then automatically cleared from the players' inventories in exchange for scoreboard points.
Pictures about "How can I detect which specific mob was killed by a player and increase a score accordingly?"



Minecraft: How to detect when a mob dies [1.16+]
More answers regarding how can I detect which specific mob was killed by a player and increase a score accordingly?
Answer 2
what is probably a bit better than your "different mobs" version: you could give them named armor (if you don't want them to be armored make them wear Zombie head items on their "real" head and name these) with 100% drop rate (0% for irrelevant armor parts so you don't need to mess around with them), then give score depending on the name of the heads the players collect and immediately clear the player's inventory for the specific item
a few advantages towards the multi-mob style:
- all the enemies behave like Zombies (what you probably originally wanted them to)
- you can have many levels not limited by the amount of hostile mobs in MineCraft
- you can make this per mob, i.e. you can put level 1 Zombies, level 1 Skeletons and level 1 Endermen into the same wave
not sure if you like this better than your version of doing it, but if you do my planned in-game name is CreatorCraft ;-)
EDIT: just figured out that hacatu's "custom loot" answer is just what I explained
Answer 3
If you want to track all zombies killing you, set them all into a specified team (eg. Zombie) using a |repeat|unconditional|always active| command block after using these commands:
/scoreboard teams add Zombie
/scoreboard teams option Zombie color white
/scoreboard objectives add Money teamkill.white
The command in the loop command block should be:
/scoreboard teams join Zombie @e[type=Zombie]
If you want this score to be visible at all times use:
/scoreboard objectives setdisplay teamkill.white sidebar
The money system could be used by using /testfor commands to detect the score, deduct the desired amount and then give an item.
Have fun!
Answer 4
I think FungusKing is on the right track, but their solution is the same as tracking stat.killEntity.zombie.
(sorry, this got too long to fit in a comment.)
You'd have to add each zombie to a specific team based on its difficulty and have a dummy scoreboard objective tracking teamkill for each one:
(run once)
/scoreboard teams add EasyZombie
/scoreboard teams add MediumZombie
/scoreboard teams add HardZombie
/scoreboard teams option EasyZombie color white
/scoreboard teams option MediumZombie color gold
/scoreboard teams option HardZombie color red
/scoreboard objectives add EazyKill teamkill.white
/scoreboard objectives add MediumKill teamkill.gold
/scoreboard objectives add HardKill teamkill.red
(run on repeat)
/scoreboard teams join EasyZombie @e[type=Zombie,tag=easy]
/scoreboard teams join MediumZombie @e[type=Zombie,tag=medium]
/scoreboard teams join HardZombie @e[type=Zombie,tag=hard]
(this assumes that you are tagging them elsewhere)
When a player has a score over zero in any of those objectives, increase their money accordingly and clear their score:
(run on repeat)
/scoreboard players add @p[score_EasyKill=1] Money 1
/scoreboard players set @p[score_EasyKill=1] EasyKill 0
/scoreboard players add @p[score_MediumKill=1] Money 5
/scoreboard players set @p[score_MediumKill=1] MediumKill 0
/scoreboard players add @p[score_HardKill=1] Money 10
/scoreboard players set @p[score_HardKill=1] HardKill 0
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, MÃdia
