Code: Select all
/c game.player.surface.create_entity{name="small-worm-turret", position={50,0}}
/c script.on_event(defines.events.on_entity_died, function(event) game.print(event.cause) end)
More info discussed here - viewtopic.php?f=23&t=48353&p=419260&hil ... se#p419260
I feel like this is a basic functionality that needs to be in the game and a lot of custom scenarios can be built on this if the cause parameter is made available to entities with die animation that gets destroyed. According to the post above it used to work as of [0.17.17].
Currently, the on_entity_damaged event does provide the cause for all entities including the turrets. But it is a huge performance hog with the events being raised every time something gets damaged. I want it only once that is when a turret dies.
For my use case, I need to know who killed the turret so some action can be taken.