Blue-prints and Hidden Entities

Place to get help with not working mods / modding interface.
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1456
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Blue-prints and Hidden Entities

Post 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.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Blue-prints and Hidden Entities

Post 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
)
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1456
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Blue-prints and Hidden Entities

Post 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.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Blue-prints and Hidden Entities

Post 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
gheift
Fast Inserter
Fast Inserter
Posts: 188
Joined: Tue Mar 03, 2015 9:20 pm
Contact:

Re: Blue-prints and Hidden Entities

Post 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.
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1456
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Blue-prints and Hidden Entities

Post 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.
Post Reply

Return to “Modding help”