[Solved] Find unpowered roboports

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
xoft
Inserter
Inserter
Posts: 22
Joined: Thu Aug 25, 2016 4:08 pm
Contact:

[Solved] Find unpowered roboports

Post by xoft »

I'd like to ask the smart people here about how to solve an issue I am currently stumped on:
I've been placing a regular electric grid with roboports all over Vulcanus. However, due to the terrain, some roboports ended up not connected to the electric network. With the grid having 2500+ roboports, it is now difficult to manually find the ones not connected. Is there a simple way to do this? Can I search for an entity with a specific property? I'm okay with even a console command, if anyone can cook one up.
Thanks.

Map sample:
06-25-2026, 17-31-11.png
06-25-2026, 17-31-11.png (639.84 KiB) Viewed 257 times
Last edited by xoft on Thu Jun 25, 2026 7:04 pm, edited 1 time in total.
berggen
Long Handed Inserter
Long Handed Inserter
Posts: 52
Joined: Tue Sep 01, 2020 7:12 pm
Contact:

Re: Find unpowered roboports

Post by berggen »

Code: Select all

/c for _, p in pairs(game.surfaces) do game.print(p.name) for _, v in pairs(p.find_entities()) do if v.electric_buffer_size and not v.is_connected_to_electric_network() then v.order_deconstruction(game.player.force) end end end
(from https://www.reddit.com/r/technicalfacto ... _entities/)

You could alternatively print the location of v for each or something :)
xoft
Inserter
Inserter
Posts: 22
Joined: Thu Aug 25, 2016 4:08 pm
Contact:

Re: Find unpowered roboports

Post by xoft »

Thank you. I iterated that code into the following version. Instead of marking for deconstruction, it adds a map tag; it also finds roboports that are connected to isolated power grids, simply by searching for roboports with less than 50 % charge:

Code: Select all

/c
local surface = game.player.surface
local force = game.player.force

for _, roboport in pairs(surface.find_entities_filtered{type = "roboport"}) do
	local maxEnergy = roboport.prototype.electric_energy_source_prototype.buffer_capacity
	local chargeFraction = roboport.energy / maxEnergy

	if (chargeFraction < 0.5) then
		force.add_chart_tag(
			surface,
			{
				position = roboport.position,
				text = string.format(
					"[UNPOWERED-ROBOPORT] %.0f%%",
					chargeFraction * 100
				)
			}
		)
	end
end
To remove the map tags later on:

Code: Select all

/c
local surface = game.player.surface
local force = game.player.force

for _, tag in pairs(force.find_chart_tags(surface)) do
	if (string.find(tag.text or "", "^%[UNPOWERED%-ROBOPORT%]")) then
		tag.destroy()
	end
end
Post Reply

Return to “Gameplay Help”