The old method of killing all biters works fine:
Code: Select all
for _, surface in pairs(game.surfaces) do
for _, entity in pairs(surface.find_entities_filtered({force="enemy"})) do
if entity.destroy() then num = num + 1 end
end
end
This is slow, though, so it's suitable for running the first time a map is loaded after installing a mod, but not suitable for frequent use.
The old method of preventing new biters doesn't seem to work, though:
Code: Select all
for _, type in pairs(data.raw) do
for _, prototype in pairs(type) do
if prototype.autoplace and prototype.autoplace.force == "enemy" then
prototype.autoplace.peaks = {}
end
end
end
Code: Select all
script.on_event(defines.events.on_chunk_generated, function(event)
clear_biters()
end)
Code: Select all
clear_biters(area)...
for _, surface in pairs(game.surfaces) do
for _, entity in pairs(surface.find_entities_filtered({force="enemy", area=area})) do
if entity.destroy() then num = num + 1 end
end
end
...
script.on_event(defines.events.on_chunk_generated, function(event)
clear_biters(event.area)
end)
Code: Select all
if area then
expanded_area = {}
expanded_area["left_top"] = {}
expanded_area["left_top"]["x"] = area.left_top.x - 16
expanded_area["left_top"]["y"] = area.left_top.y - 16
expanded_area["right_bottom"] = {}
expanded_area["right_bottom"]["x"] = area.right_bottom.x + 16
expanded_area["right_bottom"]["y"] = area.right_bottom.y + 16
end
Looking for alternate ways to kill off all the biters, there is LuaForce::kill_all_units(), but this doesn't kill worms or spawners, just the biters themselves.
Is there any simple solution for quickly killing off all the worms and spawners?
1) a fast way to go from LuaForce to a list of all entities, not just the units
2) a fast way to go from an area to all of the entities in that area (my guess is filtering the entities by area is not optimized)
3) a reliable way to prevent the worms or spawners from ever being created
4) another method I haven't thought of?
Thanks!