My reference code:
script.on_event(defines.events.on_robot_built_entity, on_built, filter)
script.on_event(defines.events.on_built_entity, on_built, filter)
script.on_event(defines.events.script_raised_revive, on_built, filter)
script.on_event(defines.events.script_raised_built, on_built, filter)
script.on_event(defines.events.on_space_platform_built_entity, on_built, filter)
died
script.on_event(defines.events.on_entity_died, on_entity_died, filter)
script.on_event(defines.events.script_raised_destroy, on_entity_died, filter)
script.on_event(defines.events.on_robot_pre_mined, on_entity_died, filter)
script.on_event(defines.events.on_space_platform_mined_entity, on_entity_died, filter)
script.on_event(defines.events.on_pre_player_mined_item, on_entity_died, filter)