Execute a function as an entity that is hurt by player with sword, bow, etc.

When the player hurts any entity with any weapon ranged or melee i want to run a function as the entity so all the commands is run for the entity and then i can do stuff like give the entity effects and so on. How to run a function as an entity?

Continue to help post