Hidden objects not always getting placed/removed
Posted: Wed Nov 02, 2016 3:03 pm
I've got a mod up and running that adds lit versions of the four power poles (small, med, large, substation) to the game. It works great once the poles are placed, however during playtesting I discovered two intermittent issues:
1. The hidden light doesn't always get added when FARL places the pole[/list]
2. The hidden light doesn't always get removed when a bot deconstructs the pole
I'm registering for bot construction/deconstruction events:
When constructed I do the following:
When deconstructed I do the following:
Anyone have ideas as to why this sometimes works for FARL construction and robot deconstruction, but sometimes doesn't work? In both cases the pole is created/removed, but the hidden light isn't.
Thanks!
1. The hidden light doesn't always get added when FARL places the pole[/list]
2. The hidden light doesn't always get removed when a bot deconstructs the pole
I'm registering for bot construction/deconstruction events:
Code: Select all
script.on_event(defines.events.on_robot_built_entity, BuiltEntity)
script.on_event(defines.events.on_robot_pre_mined , MinedEntity)
Code: Select all
function BuiltEntity(event)
if (event.created_entity.name == "lighted-small-electric-pole") or
(event.created_entity.name == "lighted-medium-electric-pole") or
(event.created_entity.name == "lighted-big-electric-pole") or
(event.created_entity.name == "lighted-substation")
then
local e = event.created_entity
local s = e.surface
local X = e.position.x
local Y = e.position.y
local l = s.create_entity{name = "hidden-small-lamp", position = {X,Y}, force= game.forces.neutral}
l.destructible = false
end
end
Code: Select all
function MinedEntity(event)
if (event.entity.name == "lighted-small-electric-pole") or
(event.entity.name == "lighted-medium-electric-pole") or
(event.entity.name == "lighted-big-electric-pole") or
(event.entity.name == "lighted-substation")
then
local b = event.entity
local X = b.position.x
local Y = b.position.y
lamp = b.surface.find_entity("hidden-small-lamp",{X, Y})
if lamp ~= nil then
lamp.destroy() end
end
end
Thanks!