script.on_nth_tick(60, function(event) -- event has fields: tick, nth_tick -- At 10 seconds, create a biter, some trees, and command the biter to attack the trees if event.tick == 10 * 60 then local surface = game.surfaces["nauvis"] global.biter = surface.create_entity({name = "small-biter", position = {x = 5.0, y = 0.0}, force = game.forces["player"]}) -- Create some trees global.trees = {} for i = 1,3 do global.trees[i] = surface.create_entity({name = "tree-04", position = {x = 10.0 + i, y = 0.0}, force = game.forces["neutral"]}) end -- Create unit group global.unit_group = surface.create_unit_group({position = {x = 5.0, y = 0.0}, force = game.forces["player"]}) global.unit_group.add_member(global.biter) -- Attack the trees local commands = {} for _, e in ipairs(global.trees) do e.order_deconstruction(game.forces["player"]) commands[#commands + 1] = {type = defines.command.attack, target = e} end global.unit_group.set_command({type = defines.command.compound, structure_type = defines.compound_command.logical_and, commands = commands}) game.print("Created biter and trees") -- At 11 seconds, destroy a tree before the biter gets to it elseif event.tick == 11 * 60 then if global.trees[2].valid then global.trees[2].destroy({}) game.print("Second tree destroyed") end end end )