I'm planning to add Power rail to my mod.
I'm going to have a small hidden power pole build when a rail is placed.
I need that power pole ("rail-hidden-power") to only connect to others like it or a special "Power-to-Rail-pole" pole.
I think I have the code correct below, but would lie for someone to review to confirm I'm not messing anything up.
Only connect "rail-hidden-power" to each other and "power-to-rail" poles
Code: Select all
if entity.valid and entity.name == "rail-hidden-power" then
for _,neighbour in pairs(entity.neighbours.copper) do
if neighbour.name ~= "rail-hidden-power" and neighbour.name ~= "power-to-rail-pole" then
entity.disconnect_neighbour(neighbour)
end
if neighbour.name == "rail-hidden-power" or neighbour.name == "power-to-rail-pole" then
entity.connect_neighbour(neighbour)
end
end
end
Code: Select all
if entity.valid and entity.type == "electric-pole" then
if entity.name ~= "rail-hidden-power" and entity.name ~= "power-to-rail-pole" then
for _,neighbour in pairs(entity.neighbours.copper) do
if neighbour.name == "rail-hidden-power" then
entity.disconnect_neighbour(neighbour)
end
end
end
end