There are 3 types on entities:
"bi-rail-hidden-power-pole" :
This is the hidden power pole that gets created when you place the power rail.
It should only connect to other "bi-rail-hidden-power-pole" or the "bi-power-to-rail-pole" entity.
"bi-power-to-rail-pole":
Can connect to both regular power poles or the "bi-rail-hidden-power-pole"
All other poles:
(type == "electric-pole")
Can't correct to the "bi-rail-hidden-power-pole" entity.
So this is what I'm doing:
Check 1: Was a "bi-rail-hidden-power-pole" built:
Code: Select all
if entity.valid and entity.name == "bi-rail-hidden-power-pole" then
for _,neighbour in pairs(entity.neighbours.copper) do
if neighbour.name ~= "bi-rail-hidden-power-pole" and neighbour.name ~= "bi-power-to-rail-pole" then
entity.disconnect_neighbour(neighbour)
end
if neighbour.name == "bi-rail-hidden-power-pole" or neighbour.name == "bi-power-to-rail-pole" then
entity.connect_neighbour(neighbour)
end
end
end
If any other poles are built, disconnect it from the "bi-rail-hidden-power-pole"
Code: Select all
--- Disconnect any other power lines from the rail-hidden-power pole
if entity.valid and entity.type == "electric-pole" then
if entity.name ~= "bi-rail-hidden-power-pole" and entity.name ~= "bi-power-to-rail-pole" then
for _,neighbour in pairs(entity.neighbours.copper) do
if neighbour.name == "bi-rail-hidden-power-pole" then
entity.disconnect_neighbour(neighbour)
end
end
end
end
Now if I place other poles first, then lay the power rail (that creates the "bi-rail-hidden-power-pole" entity), they do connect!
That should not happen.
It's okay to connect to the "bi-power-to-rail-pole" or other "bi-rail-hidden-power-pole", but not other power poles
I can't seem to get this to work if the power rail is built after other poles in the area...
Thanks.