How to detect what mob hit a player 1.12

I'm making horror map. And i got some problems.

I need that when a player takes damage from a specific mob, a block is placed. This block will start another system. For example: if player have damage from zombie, iron block placing in some place. If player have damage from skeleton, redstone block placing in some place. I hope you help me. And sorry for my bad english.


Solution 1:

This can be done with advancements. You can have an advancement trigger of type entity_hurt_player (archive) and in its damage.source_entity.type condition check for the entity type, like skeleton. The example given in the wiki even does this:

{
  "criteria": {
    "example": {
      "trigger": "minecraft:entity_hurt_player",
      "conditions": {
        "damage": {
          "source_entity": {
            "type": "skeleton",
            "direct_entity": {
              "type": "arrow"
            }
          },
          "taken": {
            "min": 4.0
          }
        }
      }
    }
  }
}

Then you just need to use a function as reward that places a block, it will automatically be executed as the player and at the position of the player.