Allow event for a cliff being destroyed

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
-DeadlyKitten
Inserter
Inserter
Posts: 40
Joined: Sat Dec 14, 2019 3:26 am
Contact:

Allow event for a cliff being destroyed

Post by -DeadlyKitten »

This is a request for a way to see when a cliff is being destroyed.

currently the only events raised are when the cliff exposive is thrown

on_pre_robot_exploded_cliff and
on_player_used_capsule

or after the cliff is dead already

on_robot_exploded_cliff (no way to tell when a player thown explosive lands)

what I am looking for is something from right before the cliff is destroyed kind of like how on_entity_died is before the death and on_post_entity_died is after

currently this is doable only by listing for where the capsle is thrown and checking every tick for if the target cliff still exists, easy to get desyncs or memory leaks.

Edit: I have confirmed using https://mods.factorio.com/mod/0-event-trace that no event is raised at all for destruction of a cliff if the explosive is thrown by the player

User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 451
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: Allow event for a cliff being destroyed

Post by raiguard »

You can use script.register_on_entity_destroyed to detect this for now. I'll look into a more proper solution for 2.0.
Don't forget, you're here forever.

Natha
Fast Inserter
Fast Inserter
Posts: 178
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: Allow event for a cliff being destroyed

Post by Natha »

What you also could do is to add a script trigger event to the capsule:

Code: Select all

table.insert(data.raw.projectile["cliff-explosives"].action[1].action_delivery.target_effects, {
  type = "script",
  effect_id = "cliff-explosives"
})
And then use the event:

Code: Select all

script.on_event(defines.events.on_script_trigger_effect, function(event)
  if event.effect_id == "cliff-explosives" then
    -- stuff
  end
end)
I figured out, that the on_script_trigger_effect event is called before on_entity_destroyed, so you could use this to temporarily save all relevant entity data (all entities in blast radius) in a table either when on_script_trigger_effect or on_player_used_capsule is called and access them in on_entity_destroyed, because you will not be able to retrieve entity position or other data in there.

Post Reply

Return to “Modding interface requests”