Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
mods/Krastorio2_1.0.23/lib/private/control-scripts/creep-generator.lua:99
-- Add this function to pull all "enemy" races, my mode add new enemy forces with enemy_ prefix.
function get_all_enemy_forces()
local enemy_race = {}
for name, force in pairs(game.forces) do
if string.find(force.name, 'enemy') then
table.insert(enemy_race, force.name)
end
end
return enemy_race
end
-- Push in the creep stack for creep generation a surface and position under a biter nests
-- @event, on_biter_base_built or on_chunk_generated
function pushCreepToGenerate(event)
local nest = event.entity or false
if nest then
if isFarEnough(nest.position) then
global.last_nest_position = nest.position -- set new last nest finded
table.insert(global.creeps_to_generate, {name = nest.name, surface = nest.surface, position = nest.position})
end
else
local nests = event.surface.find_entities_filtered
{
type = "unit-spawner",
area = event.area,
force = get_all_enemy_forces()
}
for _, nest in pairs(nests) do
table.insert(global.creeps_to_generate, {name = nest.name, surface = event.surface, position = nest.position})
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment