Page 1 of 2

How to remove enemies via console?

Posted: Sun Jan 11, 2015 8:59 pm
by Setari
So I accidentally put enemies on rich... like my entire starting area is just outlined in enemies. Is there any way to remove enemies via console command? Or to copy the map or edit properties or something so they are removed? I just wanted to play a map with rich minerals and wasn't paying attention to the properties before loading the map and now it's causing a problem for me. Luckily they're peaceful but still :\

Edit: And I mean remove the actual hives so they don't come back. I already know about the "kill all moving enemies" thing.

Re: How to remove enemies via console?

Posted: Sun Jan 11, 2015 9:35 pm
by FishSandwich
If you're not too far into the map, you could generate a map with the exchange string, and just turn biters off or whatever it is you want to do with them.

Re: How to remove enemies via console?

Posted: Sun Jan 11, 2015 10:24 pm
by Setari
I'm really far :| I have fuel production going right now so yeah. I'd rather not start a new map if I didn't have to if possible.

Re: How to remove enemies via console?

Posted: Sun Jan 11, 2015 11:06 pm
by Choumiko
Try this:

Code: Select all

/c local struct = {}
        local c, t = 0, 0
        for coord in game.getchunks() do
          local X,Y = coord.x, coord.y
          find = {"biter-spawner", "spitter-spawner", "small-worm-turret", "medium-worm-turret", "big-worm-turret"}
          if game.ischunkgenerated{X,Y} then
            struct[X.." "..Y] = {}
            local area = {{X*32, Y*32}, {X*32 + 32, Y*32 + 32}}
            for _,enemy in pairs(find) do
              for _, entity in ipairs(game.findentitiesfiltered{area = area, name = enemy}) do
                t = t+1
                if math.random(1,10) > 5 then
                  c = c+1
                  entity.destroy()
                end
              end
            end
            if not struct[X.." "..Y][1] then struct[X.." "..Y] = nil end
          end
        end
        game.player.print("Terminated "..c.." of "..t.."enemy structures")
Should remove about 50% of spawners and worms. Remove the if .. end around entity.destroy to be really cruel ;)

Re: How to remove enemies via console?

Posted: Mon Jan 12, 2015 12:22 am
by Adil
There seems to be no way to change generation settings, so you'll probably have to run that script every once in a while.

Re: How to remove enemies via console?

Posted: Tue Jan 13, 2015 11:54 pm
by Setari
Choumiko wrote:Try this:

Code: Select all

/c local struct = {}
        local c, t = 0, 0
        for coord in game.getchunks() do
          local X,Y = coord.x, coord.y
          find = {"biter-spawner", "spitter-spawner", "small-worm-turret", "medium-worm-turret", "big-worm-turret"}
          if game.ischunkgenerated{X,Y} then
            struct[X.." "..Y] = {}
            local area = {{X*32, Y*32}, {X*32 + 32, Y*32 + 32}}
            for _,enemy in pairs(find) do
              for _, entity in ipairs(game.findentitiesfiltered{area = area, name = enemy}) do
                t = t+1
                if math.random(1,10) > 5 then
                  c = c+1
                  entity.destroy()
                end
              end
            end
            if not struct[X.." "..Y][1] then struct[X.." "..Y] = nil end
          end
        end
        game.player.print("Terminated "..c.." of "..t.."enemy structures")
Should remove about 50% of spawners and worms. Remove the if .. end around entity.destroy to be really cruel ;)

I put this code in the console and it will eliminate the enemies?

Nice, I'll try it when I get a chance. If that's not how I do it, let me know please.

I appreciate the help guys, so much.

Re: How to remove enemies via console?

Posted: Mon Nov 02, 2015 1:59 am
by grifter1
Choumiko wrote:Try this:

Code: Select all

/c local struct = {}
        local c, t = 0, 0
        for coord in game.getchunks() do
          local X,Y = coord.x, coord.y
          find = {"biter-spawner", "spitter-spawner", "small-worm-turret", "medium-worm-turret", "big-worm-turret"}
          if game.ischunkgenerated{X,Y} then
            struct[X.." "..Y] = {}
            local area = {{X*32, Y*32}, {X*32 + 32, Y*32 + 32}}
            for _,enemy in pairs(find) do
              for _, entity in ipairs(game.findentitiesfiltered{area = area, name = enemy}) do
                t = t+1
                if math.random(1,10) > 5 then
                  c = c+1
                  entity.destroy()
                end
              end
            end
            if not struct[X.." "..Y][1] then struct[X.." "..Y] = nil end
          end
        end
        game.player.print("Terminated "..c.." of "..t.."enemy structures")
Should remove about 50% of spawners and worms. Remove the if .. end around entity.destroy to be really cruel ;)
Hi All can some one please help with a new command of the above that will work on 12.8 and if it is posable i want to get rid of all spawners of the map this is a very large map

my co-op mate has finished playing factorio for the moment and i want to just use this map for refining my train skills and the wiping out the spawners is very time consuming as all enemy is at max evolution and just solid red around the base

Re: How to remove enemies via console?

Posted: Mon Nov 02, 2015 3:53 am
by grifter1
Choumiko wrote:Try this:

Code: Select all

/c local struct = {}
        local c, t = 0, 0
        for coord in game.getchunks() do
          local X,Y = coord.x, coord.y
          find = {"biter-spawner", "spitter-spawner", "small-worm-turret", "medium-worm-turret", "big-worm-turret"}
          if game.ischunkgenerated{X,Y} then
            struct[X.." "..Y] = {}
            local area = {{X*32, Y*32}, {X*32 + 32, Y*32 + 32}}
            for _,enemy in pairs(find) do
              for _, entity in ipairs(game.findentitiesfiltered{area = area, name = enemy}) do
                t = t+1
                if math.random(1,10) > 5 then
                  c = c+1
                  entity.destroy()
                end
              end
            end
            if not struct[X.." "..Y][1] then struct[X.." "..Y] = nil end
          end
        end
        game.player.print("Terminated "..c.." of "..t.."enemy structures")
Should remove about 50% of spawners and worms. Remove the if .. end around entity.destroy to be really cruel ;)
Hi All

Can one of you bright coding guys help me out with a 12.8 compliant version of the above code
I am in a game that started of co-op and my mate has had all he can take of Factorio so i am going to use this map and a big sand box for refining my train skills
We started with the biters on max and evaluation is now max so the hole map is just about solid red outside my walls this isn’t a big problem as with the mods I have on I am now just about invincible it is just very time consuming to clear them out

If it is posable to have it remove all spawner like the kill all moving enemies code

I intent to do a big run around and stop them expanding back to the walls

Re: How to remove enemies via console?

Posted: Mon Nov 02, 2015 10:01 am
by prg
grifter1 wrote:Can one of you bright coding guys help me out with a 12.8 compliant version of the above code
I am in a game that started of co-op and my mate has had all he can take of Factorio so i am going to use this map and a big sand box for refining my train skills
We started with the biters on max and evaluation is now max so the hole map is just about solid red outside my walls this isn’t a big problem as with the mods I have on I am now just about invincible it is just very time consuming to clear them out

If it is posable to have it remove all spawner like the kill all moving enemies code

I intent to do a big run around and stop them expanding back to the walls

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")

Re: How to remove enemies via console?

Posted: Mon Nov 02, 2015 3:51 pm
by grifter1
prg wrote:
grifter1 wrote:Can one of you bright coding guys help me out with a 12.8 compliant version of the above code
I am in a game that started of co-op and my mate has had all he can take of Factorio so i am going to use this map and a big sand box for refining my train skills
We started with the biters on max and evaluation is now max so the hole map is just about solid red outside my walls this isn’t a big problem as with the mods I have on I am now just about invincible it is just very time consuming to clear them out

If it is posable to have it remove all spawner like the kill all moving enemies code

I intent to do a big run around and stop them expanding back to the walls

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")
thanks for the quick reply
but it didnt work do i need to change the local area = {{X*32, Y*32}, {X*32 + 32, Y*32 + 32}} as im a long way away from the starting point

Re: How to remove enemies via console?

Posted: Mon Nov 02, 2015 3:59 pm
by prg
grifter1 wrote:thanks for the quick reply
but it didnt work do i need to change the local area = {{X*32, Y*32}, {X*32 + 32, Y*32 + 32}} as im a long way away from the starting point
You don't need to change anything, that area doesn't have anything to do with your current position. Did you actually execute that code as a command, not say it as a chat message? DId you get some kind of error message?

Re: How to remove enemies via console?

Posted: Mon Nov 02, 2015 11:21 pm
by ssilk
Moved from General to Gamplay Help.

Re: How to remove enemies via console?

Posted: Tue Nov 03, 2015 12:24 am
by grifter1
prg wrote:
grifter1 wrote:thanks for the quick reply
but it didnt work do i need to change the local area = {{X*32, Y*32}, {X*32 + 32, Y*32 + 32}} as im a long way away from the starting point
You don't need to change anything, that area doesn't have anything to do with your current position. Did you actually execute that code as a command, not say it as a chat message? DId you get some kind of error message?
Thanks for trying to help me out

Yes I am entering it as a command and I get the noise that happens when you use a command but all the bases are still there I did go to check and entered the code while standing in a very large base
No error code but nothing happened
I did the kill all command and that removed all the creeps

I did change the game to peaceful mode and have a lot of mods running

Am I able to get a log file to help you know what is happening?

And what I was trying to say is that I have a very large area cleared of enemies
Is this only trying to clear a 32x32 from the starting spot ?

Re: How to remove enemies via console?

Posted: Tue Nov 03, 2015 9:38 am
by prg
grifter1 wrote:No error code but nothing happened
Did you get the message "Terminated 0 enemy structures" at the end?
grifter1 wrote:I did change the game to peaceful mode and have a lot of mods running
Does a mod change the name of the spawners? Point the mouse at one and run game.local_player.print(game.local_player.selected.name)
grifter1 wrote:Am I able to get a log file to help you know what is happening?
Next step would be to add more prints...
grifter1 wrote:And what I was trying to say is that I have a very large area cleared of enemies
Is this only trying to clear a 32x32 from the starting spot ?
The 32s in there get multiplied by X and Y, which are the coordinates of the chunk we're currently iterating over. And we're iterating over all the chunks, so it should be fine.

Re: How to remove enemies via console?

Posted: Tue Nov 03, 2015 12:32 pm
by grifter1
prg wrote:Did you get the message "Terminated 0 enemy structures" at the end?
not getting a message at all i have attached a img after the command
prg wrote:Does a mod change the name of the spawners? Point the mouse at one and run game.local_player.print(game.local_player.selected.name)

Code: Select all

game.local_player.print(game.local_player.selected.name
i tried this and i get nothing back
i don't think the mods i have change spawners list of mods below
  • 5dim_automatization_2.0.0.zip
    5dim_core_2.0.0.zip
    5dim_decoration_2.0.0.zip
    5dim_energy_2.0.0.zip
    5dim_logistic_2.0.0.zip
    5dim_mining_2.0.0.zip
    5dim_module_2.0.0.zip
    5dim_resources_2.0.0.zip
    5dim_trains_2.0.0.zip
    5dim_transport_2.0.0.zip
    5dim_vehicle_2.0.0.zip
    AdvancedEquipment_0.4.0.zip
    Advanced_Personal_Roboports_0.1.0.zip
    Crafting_Speed_Research_0.1.0.zip
    FARL_0.4.2.zip
    Stainless Steel Wagon_1.0.0.zip
    SupremeWarfare_1.0.5.zip
    Terraforming_0.12.0.zip
    UraniumPower_0.6.2.zip
    Warehousing_0.0.3.zip
    Yuoki_0.2.36.zip
    air-filtering_0.3.2.zip
    fluid-barrel_1.0.1.zip
    gravestone-mod_1.0.2.zip
    mod-list.json
    reverse-factory_1.1.3.zip
    yi_railway_0.0.3.zip


i have been playing with other commands and it looks like the game will only take commands with the multiplayer prefix and i checked i loaded it one player

Re: How to remove enemies via console?

Posted: Tue Nov 03, 2015 12:39 pm
by prg
Right, you're just missing the /c there. That's needed to execute commands, without it you're posting a chat message.

Re: How to remove enemies via console?

Posted: Tue Nov 03, 2015 2:09 pm
by grifter1
prg wrote:Right, you're just missing the /c there. That's needed to execute commands, without it you're posting a chat message.
that was it i just copied it from the box sorry

and i cant thank you enough :D

Re: How to remove enemies via console?

Posted: Mon Feb 01, 2016 10:41 pm
by sarcolopter
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?

Re: How to remove enemies via console?

Posted: Mon Feb 01, 2016 11:02 pm
by mophydeen
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 ?

Re: How to remove enemies via console?

Posted: Mon Feb 01, 2016 11:05 pm
by sarcolopter
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.