Page 1 of 1

Allow event for a cliff being destroyed

Posted: Sat May 07, 2022 9:48 pm
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

Re: Allow event for a cliff being destroyed

Posted: Mon Dec 04, 2023 2:55 pm
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.

Re: Allow event for a cliff being destroyed

Posted: Tue Feb 06, 2024 9:15 am
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.