I have a greenhouse mod that adds a few hidden entities.
When you build the green-house, I also place a electric pole, lamp and solar panel.
Some people have said that when they remove the greenhouse, some of these hidden entities remain. I've not been able to re-produce this, so was hoping someone coujld please look at the code and tell me if the're a better way of writing it.
Code: Select all
---------------------------------------------
function On_Built(event)
--- Bio Farm has been built
if event.created_entity.name == "bf_bio_farm" then
local surface = event.created_entity.surface
local force = event.created_entity.force
surface.create_entity({name = "bf_medium-electric-pole_for_Bio_Farm", position = event.created_entity.position, force = force})
surface.create_entity({name = "bf_light_for_Bio_Farm", position = event.created_entity.position, force = force})
surface.create_entity({name = "bf_solar-panel_for_Bio_Farm", position = event.created_entity.position, force = force})
end
end
---------------------------------------------
function On_Remove(event)
--- Bio Farm has been removed
if event.entity.name == "bf_bio_farm" then
res2 = game.get_surface(1).find_entities_filtered{name="bf_medium-electric-pole_for_Bio_Farm", area=GetArea(event.entity.position, 0.5)}
res = game.get_surface(1).find_entities_filtered{name="bf_light_for_Bio_Farm", area=GetArea(event.entity.position, 0.5)}
res3 = game.get_surface(1).find_entities_filtered{name="bf_solar-panel_for_Bio_Farm", area=GetArea(event.entity.position, 0.5)}
if #res then
-- If we've found it, destroy it.
res[1].destroy()
end
if #res2 then
-- If we've found it, destroy it.
res2[1].destroy()
end
if #res3 then
-- If we've found it, destroy it.
res3[1].destroy()
end
end
end