-- Remove red/green wires when using a deconstruction planner whose label -- or description contains the marker test: icons of green wire, red wire, trash bin local marker = "[item=green-wire][item=red-wire][virtual-signal=signal-trash-bin]" -- wire connector types to remove (TODO: depending on the icon that follows the marker) local remove_connector_id = { [defines.wire_connector_id.circuit_red] = true, [defines.wire_connector_id.circuit_green] = true, [defines.wire_connector_id.combinator_input_red] = true, [defines.wire_connector_id.combinator_input_green] = true, [defines.wire_connector_id.combinator_output_red] = true, [defines.wire_connector_id.combinator_output_green] = true, } -- remove red/green wires from wire connector if it has any local function clear_red_green_from_connector(connector) for _, connection in pairs(connector.connections) do -- only remove player wires, not script generated or "wireless" radar wires if connection.origin == defines.wire_origin.player then connector.disconnect_from(connection.target, connection.origin) end end end -- remove all red/green wires within the event area local function clear_red_green_area(event) local player = game.get_player(event.player_index) if not player then return end -- find entities within the deconstruction area local entities = player.surface.find_entities_filtered { area = event.area } -- then clear relevant connections for _, entity in pairs(entities) do for id, connector in pairs(entity.valid and entity.get_wire_connectors() or {}) do if remove_connector_id[id] and connector.valid then clear_red_green_from_connector(connector) end end end end -- on_player_deconstructed_area check if planner has the marker local function check_red_green_marker(event) local planner = event.record if not planner then return end -- look for marker in label or description if planner.label and planner.label:find(marker, 1, true) then clear_red_green_area(event) elseif planner.description and planner.description:find(marker, 1, true) then clear_red_green_area(event) end end -- register event handler script.on_event({defines.events.on_player_deconstructed_area}, check_red_green_marker)