Page 1 of 1
Event for Deconstruction an Entity
Posted: Sun Sep 11, 2022 12:10 pm
by Rumo
Hello,
is there any Event triggering when i deconstruct/remove an entity?
Thanks for your help.
Re: Event for Deconstruction an Entity
Posted: Sun Sep 11, 2022 2:15 pm
by Stringweasel
Yes, there are. It would help reading the docs
https://lua-api.factorio.com/latest/def ... nes.events
For example you typically listen to these events
Code: Select all
script.on_event(defines.events.on_player_mined_entity, your_function)
script.on_event(defines.events.on_robot_mined_entity, your_function)
script.on_event(defines.events.on_entity_died, your_function)
script.on_event(defines.events.script_raised_destroy, your_function)
Re: Event for Deconstruction an Entity
Posted: Sun Sep 11, 2022 2:28 pm
by Rumo
Hey,
thanks for the help.
I read the docs and tried some trigger but nothing happens
But then i will try it again.
Re: Event for Deconstruction an Entity
Posted: Mon Sep 12, 2022 4:21 am
by Pi-C
Rumo wrote: Sun Sep 11, 2022 2:28 pm
I read the docs and tried some trigger but nothing happens
Are you sure that the event handler is really active? Add this to your control.lua:
Code: Select all
local c_name = "show-active-events"
if not commands.commands[c_name] then
commands.add_command(c_name, c_name, function(command)
local player = game.players[command.player_index]
local events = {}
for event_name, event in pairs(defines.events) do
if script.get_event_handler(event) then
events[event] = event_name
end
end
local msg = serpent.block(events)
player.print(msg)
log(msg)
end
else
error("Command \""..c_name.."\" already exists, change c_name!")
end
It will add a command that you can run from the chat console with {code]/show-active-events[/code] to get the list of events your mod is listening to.
Re: Event for Deconstruction an Entity
Posted: Mon Sep 12, 2022 7:00 am
by Stringweasel
Or it could be that you code isn't running
Does Factorio recognise your mod? Are you placing your code in `control.lua`? How are you testing if it's running or not?