script.on_init(function () global = {} global.next_ID = 1 global.last_tick = 0 global.trees = nil for chunk in game.surfaces[1].get_chunks() do trees_of_area_to_table ({{(chunk.x*32), (chunk.y*32)},{(chunk.x*32+32), (chunk.y*32+32)}}) end end) script.on_event(defines.events.on_chunk_generated, function (event) local area = event.area trees_of_area_to_table (area) end) script.on_event(defines.events.on_tick, function (event) local cur = global.trees; while cur do cur.age_ticks = cur.age_ticks + 1 cur = cur.next; end if (game.tick % 600 == 0) then log ("game.tick = " .. game.tick .. " Trees: " .. global.next_ID) end end) function trees_of_area_to_table (area, surface) local surface = surface or game.surfaces[1] --find_entities_filtered{area=…, position=…, name=…, type=…, force=…, limit=…} local trees = surface.find_entities_filtered{area=area, type="tree"} if not trees then return end for i, tree in pairs (trees) do global.trees = {next=global.trees, age_ticks = 0, entity = tree} global.next_ID = global.next_ID+1; end end function printAll(text) if type(text) == "table" then text = serpent.block(text, {comment = false}) end for player_index, player in pairs (game.players) do game.players[player_index].print (text) end end