Hello, I'm searching for a way to count the mobs killed by players in a mob grinder.
I generate regular statistics for my players: who has killed what and how often.
But after the XP grinder was set up, the numbers (for skeletons in this case) exploded. And as it is not a real kill when you punch a nearly dead mob with bare hands, I would like to reduce the numbers.
The area where these mod kills occur is well limited to the drop shaft, so it should be possible to test for it in a command block. In case the player position is more useful, it is also limited to reach distance to that drop shaft. The kill itself is also counted as a scoreboard objective per player, so this information is also available.
But I have no good idea how to combine this information and how to arrange the command blocks.
I see a potential problem in your example: If the player is exploring the world (far away => grinder and command block unloaded) and then kills some Skeletons, both scores get incremented (lets say to 10). When coming back to the grinder, this 10 is subtracted from the first score which is not correct behavior.
A valid selector based on player location would be in my case:
In my opinion I need something that triggers my counting command block on each Skeleton kill (instead of using the clock). And my command block then increments the second objective (like in the example above). The objective kill_skeleton2 is defined with dummy source.
I also prefer to have both objective counts unmodified, therefore doing the subtraction on a third objective. This would allow to show also the grinder kills separately.
To prevent wrong counting I placed a reseting command to an area where a player has to pass by to get to the grinder. It my case there is a tunnel leading to the grinder and I placed the area to its end. So one regularly updated command block has to do:
/scoreboard players set @p[x=X2,y=Y2,z=Z2,r=3,score_kill_skeleton1_min=1] kill_skeleton1 0
The counting part is similar to the suggestion and uses two command blocks connected via a comparator, a detector and a counter:
The location X1,Y1,Z1 is near the drop shaft and X2,Y2,Z2 is the end of the tunnel and the only entrance to the grinder.
I decrement the detection objective "kill_skeleton1" in the first detection command block to prevent timing glitches when two command blocks handle the same objective. Therefore the second counting command block is only used to increment the final objective "xp_skeleton". The reset and the first detection command block are clocked by a standard redstone clock.