How to remove enemies via console?

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Setari
Burner Inserter
Burner Inserter
Posts: 5
Joined: Tue Jan 06, 2015 6:11 am
Contact:

How to remove enemies via console?

Post 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.

FishSandwich
Smart Inserter
Smart Inserter
Posts: 1847
Joined: Sun Feb 23, 2014 3:37 pm
Contact:

Re: How to remove enemies via console?

Post 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.

Setari
Burner Inserter
Burner Inserter
Posts: 5
Joined: Tue Jan 06, 2015 6:11 am
Contact:

Re: How to remove enemies via console?

Post 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.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: How to remove enemies via console?

Post 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 ;)

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: How to remove enemies via console?

Post 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.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

Setari
Burner Inserter
Burner Inserter
Posts: 5
Joined: Tue Jan 06, 2015 6:11 am
Contact:

Re: How to remove enemies via console?

Post 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.

grifter1
Inserter
Inserter
Posts: 37
Joined: Sat Aug 08, 2015 5:53 am
Contact:

Re: How to remove enemies via console?

Post 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

grifter1
Inserter
Inserter
Posts: 37
Joined: Sat Aug 08, 2015 5:53 am
Contact:

Re: How to remove enemies via console?

Post 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

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: How to remove enemies via console?

Post 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")
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

grifter1
Inserter
Inserter
Posts: 37
Joined: Sat Aug 08, 2015 5:53 am
Contact:

Re: How to remove enemies via console?

Post 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

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: How to remove enemies via console?

Post 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?
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: How to remove enemies via console?

Post by ssilk »

Moved from General to Gamplay Help.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

grifter1
Inserter
Inserter
Posts: 37
Joined: Sat Aug 08, 2015 5:53 am
Contact:

Re: How to remove enemies via console?

Post 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 ?

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: How to remove enemies via console?

Post 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.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

grifter1
Inserter
Inserter
Posts: 37
Joined: Sat Aug 08, 2015 5:53 am
Contact:

Re: How to remove enemies via console?

Post 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
Attachments
after console command.JPG
after console command.JPG (123.06 KiB) Viewed 23763 times

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: How to remove enemies via console?

Post by prg »

Right, you're just missing the /c there. That's needed to execute commands, without it you're posting a chat message.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

grifter1
Inserter
Inserter
Posts: 37
Joined: Sat Aug 08, 2015 5:53 am
Contact:

Re: How to remove enemies via console?

Post 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

sarcolopter
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Sun Jul 26, 2015 5:08 pm
Contact:

Re: How to remove enemies via console?

Post 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?

mophydeen
Filter Inserter
Filter Inserter
Posts: 529
Joined: Sun Nov 22, 2015 5:02 pm
Contact:

Re: How to remove enemies via console?

Post 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 ?

sarcolopter
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Sun Jul 26, 2015 5:08 pm
Contact:

Re: How to remove enemies via console?

Post 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.

Post Reply

Return to “Gameplay Help”