How can I detect a player's score against other players?

How can I detect a player's score against other players? - Aerial View of Soccer Field

I'm creating a PvP map in Minecraft and I'd like to track how many times a player has hit other players on a scoreboard. I'm not tracking kills; I'm tracking hits. How can I do this?

I'm not tracking the number of times player1 has hit player2, I'm tracking how many times player1 has hit anyone. Also, I'm only using projectiles. I am fine with using any projectile needed in order to track this.



Best Answer

Disclaimer: I did not test this, but precluding Minecraft weirdness/bugs, this method should work.

@Kcats was on a very good track regarding stat.damageDealt, but there is one more step to it than just looking at this.

First, set up some scoreboard objectives:

/scoreboard objectives add damageDealt stat.damageDealt
/scoreboard objectives add hits dummy

Now make a fast clock (setblock/fill clock works best) and run the following in order

/scoreboard players add @a[score_damageDealt_min=1] hits 1
/scoreboard players set @a damageDealt 0

By using a second objective, we can decouple hits from damage done. If a player has dealt any kind of damage to anything in the last clock period, it is counted as a hit.

Due to the way this is set up, there are some quirks however:

  • A hit that doesn't deal any damage due to armor or resistance effects or whatnot does not count.
  • If you set someone on fire, poison or wither someone, every tick of damage probably counts as a hit (here's where I'm unsure of the exact workings of the stat.damageDealt).



Pictures about "How can I detect a player's score against other players?"

How can I detect a player's score against other players? - Football Players
How can I detect a player's score against other players? - Gathering Football Players
How can I detect a player's score against other players? - Young African American female football player trying scoring goal in training in sunny day





How to detect a player using command blocks! | /execute command tutorial for 1.16 Minecraft Java




More answers regarding how can I detect a player's score against other players?

Answer 2

Tracking projectile hits are very hard to track... as there is no tag for a projectile that hit a player / entity. I'm guessing the only way would be using wither skulls to detect whether an arrow is in a 1 block radius of a player

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Mike, Joe Calomeni, Pixabay, RF._.studio