Event request: on_time_to_live_expired

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
Therax
Filter Inserter
Filter Inserter
Posts: 470
Joined: Sun May 21, 2017 6:28 pm
Contact:

Event request: on_time_to_live_expired

Post by Therax »

This event would be fired when an entity-ghost or combat-robot entity is destroyed due to its time_to_live expiring. This would close a gap in mods' ability to know when an entity ceases to exist.

In particular, I would appreciate this event to know when a circuit-connected ghost disappears. Currently removing a ghost by "mining" it with RMB, fires on_pre_player_mined_entity, and selecting it with a deconstruction planner fires on_pre_ghost_deconstructed, but no event is fired when a ghost times out.
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Event request: on_time_to_live_expired

Post by Rseding91 »

I can add that event however that doesn't cover every possible way an entity can be removed from the game.

When an entity is destroyed through entity.destroy() you will never get an event. The core game logic can destroy() entities for multiple different reasons that explicitly don't allow an event to be fired because mods can't be trusted to not do crazy things during events.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Therax
Filter Inserter
Filter Inserter
Posts: 470
Joined: Sun May 21, 2017 6:28 pm
Contact:

Re: Event request: on_time_to_live_expired

Post by Therax »

Rseding91 wrote:I can add that event however that doesn't cover every possible way an entity can be removed from the game.

When an entity is destroyed through entity.destroy() you will never get an event. The core game logic can destroy() entities for multiple different reasons that explicitly don't allow an event to be fired because mods can't be trusted to not do crazy things during events.
I think it's generally understood that calls through scripting to entity.destroy() never generate any sort of event, and a mod has to raise an appropriate event itself if applicable. I'm more concerned with core logic-initiated removal throwing events. As a general principle, I'd like to be able to claim that my mod handles all cases if it is the only installed mod and there are no console scripting shenanigans (if this is possible), with compatibility with other mods' behavior coming as a bonus on top of that basic guarantee. Ideally I'd like to be able to do that without having to poll for changes to the world in an on_tick handler.

Out of curiosity, what are some other cases where an entity is destroyed by the core logic that don't (and won't) throw events? AI-controlled entities being destroyed due to excessive pathfinding costs? Others?
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Event request: on_time_to_live_expired

Post by Rseding91 »

Canceling deconstruction will destroy() any ghosts that collide with that entity.

Building any entity will destroy() any ghost that collides with that entity.

Entity migration will destroy() any entity that is migrated to another type.

Cliffs destroy() each other as they're removed/exploded.

Cliffs destroy() resources they're built over.

Combat robots destroy() when timed out or when you build too many of them.

Inserters destroy() the item entity they pick up.

Several different entities destroy() themselves on timeout.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Therax
Filter Inserter
Filter Inserter
Posts: 470
Joined: Sun May 21, 2017 6:28 pm
Contact:

Re: Event request: on_time_to_live_expired

Post by Therax »

Thanks so much for the list! This seems workable for my purposes (detecting when wire connections are created and removed):

Canceling deconstruction will destroy() any ghosts that collide with that entity.
- Fires on_canceled_deconstruction and can check the collision_box of the entity in the event against an internal list of known ghosts.

Building any entity will destroy() any ghost that collides with that entity.
- As above, but check during on_built_entity / on_robot_built_entity.

Entity migration will destroy() any entity that is migrated to another type.
- This is a good one to know. Can check world state during on_configuration_changed.

Cliffs destroy() each other as they're removed/exploded.
- Cliffs aren't circuit connectable, so not an issue for me. In vanilla, could be detected via on_put_item or on_player_used_capsule with cliff-explosives without additional events. Mods that use the destroy-cliffs projectile action would have to raise their own event to be reliably detected.

Cliffs destroy() resources they're built over.
- Happens only during chunk generation?

Combat robots destroy() when timed out or when you build too many of them.
- This request covers when combat robots time out. Is there an on_entity_died if a combat robot falls out of the sky due to having to many inflight?

Inserters destroy() the item entity they pick up.
- For my purposes, item-on-ground entities cannot be circuit connected, but this is still good to remember.

Several different entities destroy() themselves on timeout.
- This request covers when ghosts timeout. Corpses are covered by on_character_corpse_expired. Combat robots are discussed above. Are there other interactable or otherwise gameplay-affecting entities that timeout (so excluding purely visual FX and flying-text)?
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground

Post Reply

Return to “Modding interface requests”