function AddPowerPole(event) local e = event.entity if e and e.valid and e.type == "electric-pole" then storage.representativePoles[e.unit_number] = e end end function RemovePowerPole(event) local e = event.entity if e then storage.representativePoles[e.unit_number] = nil end end function GetNetworks() local networks = {} for _, pole in pairs(storage.representativePoles) do if pole.valid then local net = pole.electric_network_id if net then networks[net] = pole end end end return networks end function ScanNetworks() storage.representative_poles = {} for _, surface in pairs(game.surfaces) do for _, pole in pairs(surface.find_entities_filtered{type = "electric-pole"}) do if pole.valid and pole.electric_network_id then storage.representativePoles[pole.unit_number] = pole end end end end function SendPowerStats() if options.enablePower then local powerPart = {} powerPart[#powerPart+1] = "---power-stats---\n" for _, pole in pairs(GetNetworks()) do if pole.valid and pole.type == "electric-pole" then local input = pole.electric_network_statistics.input_counts local output = pole.electric_network_statistics.output_counts local surfaceName = pole.surface.name for item,value in pairs(input) do powerPart[#powerPart+1] = ("%s:%d:in:%s:%d"):format(surfaceName, pole.electric_network_id, item, value) end for item, value in pairs(output) do powerPart[#powerPart+1] = ("%s:%d:out:%s:%d"):format(surfaceName,pole.electric_network_id, item, value) end end end helpers.send_udp(udpAddress,table.concat(powerPart,"\n"),serverIndex) end end