Code: Select all
function get_usage(pole)
if not (pole and pole.valid and pole.type == "electric-pole" and pole.electric_network_statistics) then
return 0
end
local stats = pole.electric_network_statistics
local total_usage = 0
for prototype_name, _ in pairs(stats.input_counts) do
local flow = stats.get_flow_count {
name = prototype_name,
precision_index = defines.flow_precision_index.five_seconds,
count = false,
category = "input"
}
total_usage = total_usage + flow
end
return total_usage * 60 -- Convert from per tick to per second
end
For instance, if I place a single normal radar, 300kW is returned. Replace it with a radar with quality other than normal, 0kW is returned.
In stepping through, the "radar" prototype name is returned but the flow is 0 if higher than normal quality.