My (laggy) code ATM.
Code: Select all
function thingFallsApartMaybe()
local nauvisSurface = game.get_surface("nauvis")
local chunkIterator = nauvisSurface.get_chunks
for chunk in chunkIterator() do
--log("x: " .. chunk.x .. ", y: " .. chunk.y)
--log("area: " .. serpent.line(chunk.area))
local x = chunk.x + math.random(chunk.area.left_top.x, chunk.area.right_bottom.x)
local y = chunk.y + math.random(chunk.area.left_top.y, chunk.area.right_bottom.y)
local area = chunk.area
local entities = nauvisSurface.find_entities(area)
if entities then
if next(entities) ~= nil then
log(entities[math.random(#entities)].name)
end
end
end
end
script.on_nth_tick(60 * 1, thingFallsApartMaybe) --1 seconds