Hi,
I got a bug report on my mod of some hidden entities for my Bio farm that are not spawning when the farm are placed via blueprints.
Is there a flag I need to have/change to prevent this from happening?
Thanks.
Blue-prints and Hidden Entities
Re: Blue-prints and Hidden Entities
script.on_event({defines.events.on_build_entity, defines.events.on_robot_built_entity}, function(event)
if event.created_entity.name == "entity-ghost" and event.created_entity.ghost_name == "my-entity" then
--event.created.entity.surface.create_entity{............}
end
)
if event.created_entity.name == "entity-ghost" and event.created_entity.ghost_name == "my-entity" then
--event.created.entity.surface.create_entity{............}
end
)
Re: Blue-prints and Hidden Entities
Okay, so this is how the code currently looks:
Still getting the same results if I change:
to:
or
Thanks.
Code: Select all
local build_events = {defines.events.on_built_entity, defines.events.on_robot_built_entity}
script.on_event(build_events, On_Built)
local function On_Built(event)
local entity = event.created_entity
--- Bio Farm has been built
if entity and entity.name == "bi_bio_farm" then
writeDebug("Bio Farm has been built")
local surface = entity.surface
local force = entity.force
local position = entity.position
local b_farm = entity
local pole_name = "bi_medium-electric-pole_for_Bio_Farm"
local panel_name = "bi_solar-panel_for_Bio_Farm"
local lamp_name = "bi_light_for_Bio_Farm"
local create_pole = surface.create_entity({name = pole_name, position = position, force = force})
local create_panel = surface.create_entity({name = panel_name, position = position, force = force})
local create_lamp = surface.create_entity({name = lamp_name, position = position, force = force})
create_pole.minable = false
create_pole.destructible = false
create_panel.minable = false
create_panel.destructible = false
create_lamp.minable = false
create_lamp.destructible = false
group_entities(cantor(position.x,position.y), { b_farm, create_pole, create_panel, create_lamp })
end
end
Code: Select all
if entity and entity.name == "bi_bio_farm" then
Code: Select all
if (entity and entity.name == "bi_bio_farm") or (entity.name == "entity-ghost" and entity.name == "bi_bio_farm") then
Code: Select all
if entity.name == "entity-ghost" and entity.name == "bi_bio_farm" then
Re: Blue-prints and Hidden Entities
Your first/original code looks correct
When the ghost is revived (built by robots) or (built by player) it should add your lamp etc
When the ghost is revived (built by robots) or (built by player) it should add your lamp etc
Re: Blue-prints and Hidden Entities
The problem is not the event handler but creating the blueprint. The addition entites are included in it. Just add the flag "not-blueprintable" to your helper entities and it should work as expected.
Re: Blue-prints and Hidden Entities
Yip, that was my problem!gheift wrote:The problem is not the event handler but creating the blueprint. The addition entites are included in it. Just add the flag "not-blueprintable" to your helper entities and it should work as expected.
Thanks gheift and Nexela.