Page 1 of 1

How add storage to constant-combinator behavior

Posted: Thu Aug 08, 2019 11:08 pm
by WildBraas
I need simultaneously have a opinion storage an items and set output signals in custom entity.

If I deepcopy from storage/steel-chest, I get a inventory, but no behavior.set_signal.
If I deepcopy from constant-combinator, I get set_signal, but lost inventory!

May you route the way to solve this problem?

Re: How add storage to constant-combinator behavior

Posted: Thu Aug 08, 2019 11:31 pm
by DaveMcW
In control.lua:

Code: Select all

function on_built(event)
  local entity = event.created_entity or event.entity or event.destination
  if not entity or not entity.valid then return end
  if entity.name == "my-combinator" then
    entity.surface.create_entity{
      name = "my-chest",
      position = entity.position,
      force = entity.force,
    }
  end
end  

function on_destroyed(event)
  local entity = event.entity
  if not entity or not entity.valid then return end
  if entity.name == "my-combinator" then
    for _, chest in pairs(entity.surface.find_entities_filtered{name="my-chest", position=entity.position}) do
      chest.destroy()
    end
  end
end
  
script.on_event(defines.events.on_built_entity, on_built)
script.on_event(defines.events.on_robot_built_entity, on_built)
script.on_event(defines.events.script_raised_built, on_built)
script.on_event(defines.events.script_raised_revive, on_built)
script.on_event(defines.events.on_entity_cloned, on_built)
script.on_event(defines.events.on_player_mined_entity, on_destroyed)
script.on_event(defines.events.on_robot_mined_entity, on_destroyed)
script.on_event(defines.events.on_entity_died, on_destroyed)
script.on_event(defines.events.script_raised_destroy, on_destroyed)

Re: How add storage to constant-combinator behavior

Posted: Fri Aug 09, 2019 9:21 pm
by WildBraas
Thank you sir