How would I have a command block detect when a specific mob is hit?

I'm making a map, and I require that whenever certain animals are hit a string of events will occur. I tried looking around to see if I could synthesize some form of a working answer but it seems to be flying over my head. Essentially what I want is some form of command that will detect the player nearest to the hit mob, and then I could use chain command blocks for my additional needs. I know I need to use a chain command block, and I know this has to do something with HurtTime, but I just can't piece it all together.


Normally, entities have a HurtTime of 0s. You can see this by using /data get entity @s HurtTime, using yourself as an example. When an entity is hit, its HurtTime gets set to 10s and decreases every tick until it has reached 0s again.

You can test for nbt in selectors like this:

execute as @e[nbt={HurtTime:10s}] at @s run particle angry_villager ~ ~2 ~

(Repeating command every tick)


You can tag the player nearest to the hit mob like this:

execute as @e[nbt={HurtTime:10s}] at @s run tag @p add closest_to_mob

(Repeating command every tick)