Page 1 of 1
Blue-prints and Hidden Entities
Posted: Sun May 14, 2017 4:34 pm
by TheSAguy
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.
Re: Blue-prints and Hidden Entities
Posted: Sun May 14, 2017 7:59 pm
by Nexela
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
)
Re: Blue-prints and Hidden Entities
Posted: Sun May 14, 2017 8:20 pm
by TheSAguy
Okay, so this is how the code currently looks:
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
Still getting the same results if I change:
Code: Select all
if entity and entity.name == "bi_bio_farm" then
to:
Code: Select all
if (entity and entity.name == "bi_bio_farm") or (entity.name == "entity-ghost" and entity.name == "bi_bio_farm") then
or
Code: Select all
if entity.name == "entity-ghost" and entity.name == "bi_bio_farm" then
Thanks.
Re: Blue-prints and Hidden Entities
Posted: Sun May 14, 2017 8:25 pm
by Nexela
Your first/original code looks correct
When the ghost is revived (built by robots) or (built by player) it should add your lamp etc
Re: Blue-prints and Hidden Entities
Posted: Sun May 14, 2017 9:22 pm
by gheift
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
Posted: Sun May 14, 2017 9:54 pm
by TheSAguy
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.
Yip, that was my problem!
Thanks gheift and Nexela.