Spawning entities in biter bases on chunk-creation

Place to get help with not working mods / modding interface.
Pandemoneus
Fast Inserter
Fast Inserter
Posts: 127
Joined: Fri May 08, 2015 2:25 pm
Contact:

Spawning entities in biter bases on chunk-creation

Post 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?
My RSO+Bob's+Angel's modpack: Farlands (outdated)
Mods (current): Resource Labels
Mods (old): Biter Spires
Pandemoneus
Fast Inserter
Fast Inserter
Posts: 127
Joined: Fri May 08, 2015 2:25 pm
Contact:

Re: Spawning entities in biter bases on chunk-creation

Post 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.
My RSO+Bob's+Angel's modpack: Farlands (outdated)
Mods (current): Resource Labels
Mods (old): Biter Spires
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5412
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Spawning entities in biter bases on chunk-creation

Post 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)
Pandemoneus
Fast Inserter
Fast Inserter
Posts: 127
Joined: Fri May 08, 2015 2:25 pm
Contact:

Re: Spawning entities in biter bases on chunk-creation

Post 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.
My RSO+Bob's+Angel's modpack: Farlands (outdated)
Mods (current): Resource Labels
Mods (old): Biter Spires
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5412
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Spawning entities in biter bases on chunk-creation

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

Return to “Modding help”