I'm making a Half-Life 2 Episode 1 mod, and I want to figure out how to make NPCs change their relationship to hate whatever hurts them, and then reset it after losing an enemy.

I know it's possible to do this in Hammer with the ai_relationship entity, and make the NPC activate it when it's damaged by the player (OnDamagedByPlayer in the I/O system), but how can I do this for every NPC?
For example, if a player attacks a npc_citizen, how can I make that citizen attack the player when it's shot by the player?

Or another example, there's 2 citizens and one metrocop in one room.
How do I make it so that, if the first citizen attacks the other citizen for whatever reason, the cop attacks the first attacker?
I have access to source code.