First, create the following folder
📂BP
└📄manifest.json
└📚pack_icon.png
└📂functions
└📄hurt_by_player.mcfunction
Enter your command in hurt_by_player.mcfunction
example: summon ender_crystal
Then enable the addon you created and use the block with hurt_by_player.mcfunction.
And if you perform a certain action, you can execute the hurt_by_player.mcfunction.