Page 2 of 2
					
				Re: How to remove enemies via console?
				Posted: Mon Feb 01, 2016 11:26 pm
				by mophydeen
				sarcolopter wrote:mophydeen wrote:sarcolopter wrote:Sorry for necroing. I used this, and it appears to have removed all enemies from the map, instead of ~50%. Is there any way to respawn them?
Go back one save ?
 
That would defeat the purpose, since I'd be back right where I started.
 
Go back and retry command
Which command did you enter?
 
			 
			
					
				Re: How to remove enemies via console?
				Posted: Tue Feb 02, 2016 4:45 am
				by sarcolopter
				mophydeen wrote:sarcolopter wrote:mophydeen wrote:sarcolopter wrote:Sorry for necroing. I used this, and it appears to have removed all enemies from the map, instead of ~50%. Is there any way to respawn them?
Go back one save ?
 
That would defeat the purpose, since I'd be back right where I started.
 
Go back and retry command
Which command did you enter?
 
 Code: Select all
   local c = 0, 0
    local s = game.local_player.surface
    for coord in s.get_chunks() do
        local X,Y = coord.x, coord.y
        find = {"biter-spawner", "spitter-spawner", "small-worm-turret", "medium-worm-turret", "big-worm-turret"}
        if s.is_chunk_generated{X,Y} then
            local area = {{X*32, Y*32}, {X*32 + 32, Y*32 + 32}}
            for _,enemy in pairs(find) do
                for _, entity in ipairs(s.find_entities_filtered{area = area, name = enemy}) do
                    c = c+1
                    entity.destroy()
                end
            end
        end
    end
    game.local_player.print("Terminated "..c.." enemy structures")
I don't see how repeating an entity.destroy() command would spawn additional entities. Is there an entity.create() command or similar?
 
			 
			
					
				Re: How to remove enemies via console?
				Posted: Tue Feb 02, 2016 6:26 am
				by Koub
				Well next time, if you want to remove, say, half of the spawners, in the innermost loop, add a test like : 
Code: Select all
                for _, entity in ipairs(s.find_entities_filtered{area = area, name = enemy}) do
                  if math.random(0,1) > 0.5 then
                     c = c+1
                     entity.destroy()
                     end
                end
What you did there is basically remove all spawners one by one.
Well I'm not 100% sure of the syntax, but the idea is there 

 
			 
			
					
				Re: How to remove enemies via console?
				Posted: Tue Feb 02, 2016 1:18 pm
				by Klonan
				Here is a script that will kill all worms, biters, spitters and spawners everywhere on the map:
Code: Select all
/c local surface = game.local_player.surface
for c in surface.get_chunks() do
for key, entity in pairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, force= "enemy"})) do
entity.destroy()
end
end
This is the same, but will only kill half of them:
Code: Select all
/c local surface = game.local_player.surface
for c in surface.get_chunks() do
for key, entity in pairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, force= "enemy"})) do
if key % 2 == 0 then
entity.destroy() 
end
end
end
 
			 
			
					
				Re: How to remove enemies via console?
				Posted: Tue Feb 02, 2016 5:22 pm
				by sarcolopter
				well sheeeeeeit. guess I'll figure out how to mod in a crafting recipe for artifacts
			 
			
					
				Re: How to remove enemies via console?
				Posted: Sun Sep 11, 2016 12:03 pm
				by Iggmynir
				Klonan wrote:Here is a script that will kill all worms, biters, spitters and spawners everywhere on the map:
Code: Select all
/c local surface = game.local_player.surface
for c in surface.get_chunks() do
for key, entity in pairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, force= "enemy"})) do
entity.destroy()
end
end
 
 
Hello Klonan, is this command still supposed to work? I used it in a map of mine a few months ago. After one of the recent experimental updates enemys started showing up at my borders again. When I tried to use the command to wreck all of thier stuff I got an error message: 
Code: Select all
Cannot execute command. Error: LuaGameScript doesn't contain key local_player.stack traceback: [string "local surface = game.local_player.surface fo.."]:1: in main chunk
 
			 
			
					
				Re: How to remove enemies via console?
				Posted: Mon Sep 12, 2016 3:59 pm
				by Adil
				These days it's `player` instead of `local_player`.
			 
			
					
				Re: How to remove enemies via console?
				Posted: Mon Sep 12, 2016 10:52 pm
				by Iggmynir
				Adil wrote:These days it's `player` instead of `local_player`.
Thank you 
