If you think this does not fit the theme it's fine, but if you change your mind here is an example of a storage tank that fills with sulfuric acid every time an enemy tries to damage it with acid. It is also immune to acid damage (but not physical or other). The harder the hit the more acid is generated.
The implementation is straight-forward (it does not involve any workarounds or hacks) and should not hit the performance too much because the event filtering for the correct damage type is done by the Factorio engine, not in lua.
data.lua:
local recipe = {
type = 'recipe',
name = 'spit-collector-recipe',
enabled = true,
ingredients = { {'storage-tank', 1} },
result = 'spit-collector-item',
}
local item = {
type = 'item',
name = 'spit-collector-item',
localised_name = 'Spit collector',
stack_size = 50,
place_result = 'spit-collector-entity',
icon = "__base__/graphics/icons/storage-tank.png",
icon_size = 64,
icon_mipmaps = 4,
subgroup = "storage",
}
local entity = table.deepcopy(data.raw['storage-tank']['storage-tank'])
entity.name = 'spit-collector-entity'
entity.is_military_target = true -- to make it a high priority target for biters
entity.item_to_place_this = { 'spit-collector-item' }
entity.minable.result = 'spit-collector-item'
entity.max_health = 1000
entity.resistances = {{ type = 'acid', percent = 100 }}
data:extend{item, entity, recipe}
control.lua:
function on_entity_damaged(event)
if not event.force or event.force.name ~= 'enemy' then
-- Prevent players from filling the container themselves
return
end
-- fill the tank with acid, scaling with the damage amount
event.entity.insert_fluid{
name = 'sulfuric-acid',
amount = event.original_damage_amount
}
end
script.on_event(defines.events.on_entity_damaged, on_entity_damaged,
{
{
filter = 'name',
name = 'spit-collector-entity',
},
{
filter = 'damage-type',
type= 'acid',
mode = 'and',
}
})