Page 1 of 1
Spawning entities in biter bases on chunk-creation
Posted: Thu Dec 15, 2016 3:16 am
by Pandemoneus
I have a mod idea that spawns so-called biter spires which provide free energy. I got this part done. The next step would be to make these entities spawn in biter bases on chunk-creation (I don't want more to spawn when the biters expand). However, I have no idea how to do that. As far as I can see it is related to autoplacing, but I have no idea how to do that in corellation with biter bases. Does anyone have an idea?
Re: Spawning entities in biter bases on chunk-creation
Posted: Thu Dec 15, 2016 9:16 am
by darkfrei
Re: Spawning entities in biter bases on chunk-creation
Posted: Thu Dec 15, 2016 11:28 am
by Pandemoneus
Sorry, but that was not helpful. I have looked through the API myself, that doesn't tell me how I can hook into the biter bases autoplacement.
Re: Spawning entities in biter bases on chunk-creation
Posted: Thu Dec 15, 2016 2:31 pm
by Klonan
Pandemoneus wrote:
Sorry, but that was not helpful. I have looked through the API myself, that doesn't tell me how I can hook into the biter bases autoplacement.
On the chunk generated, find all the biter bases in that newly generated chunk, and then spawn your entity in top of them, something like this:
Code: Select all
script.on_event(defines.events.on_chunk_generated, function(event)
local area = event.area
local surface = event.surface
for k, base in pairs (surface.find_entities_filtered{area = area, type = "unit-spawner"}) do
surface.create_entity{name = "your-entity", position = base.position, force = base.force}
end
end)
Re: Spawning entities in biter bases on chunk-creation
Posted: Thu Dec 15, 2016 3:51 pm
by Pandemoneus
Klonan wrote:On the chunk generated, find all the biter bases in that newly generated chunk, and then spawn your entity in top of them, something like this:
Code: Select all
script.on_event(defines.events.on_chunk_generated, function(event)
local area = event.area
local surface = event.surface
for k, base in pairs (surface.find_entities_filtered{area = area, type = "unit-spawner"}) do
surface.create_entity{name = "your-entity", position = base.position, force = base.force}
end
end)
Thanks, but currently there is no way to do it directly together with the biter base autoplacement, right? I thought it would be possible to modify or add to that.
Re: Spawning entities in biter bases on chunk-creation
Posted: Fri Dec 16, 2016 9:18 am
by Klonan
Pandemoneus wrote:Klonan wrote:On the chunk generated, find all the biter bases in that newly generated chunk, and then spawn your entity in top of them, something like this:
Code: Select all
script.on_event(defines.events.on_chunk_generated, function(event)
local area = event.area
local surface = event.surface
for k, base in pairs (surface.find_entities_filtered{area = area, type = "unit-spawner"}) do
surface.create_entity{name = "your-entity", position = base.position, force = base.force}
end
end)
Thanks, but currently there is no way to do it directly together with the biter base autoplacement, right? I thought it would be possible to modify or add to that.
No way currently, the game won't spawn entities which collide with one another in any case