Console help

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
User avatar
Alice3173
Fast Inserter
Fast Inserter
Posts: 119
Joined: Sun Apr 24, 2016 11:35 pm
Contact:

Console help

Post by Alice3173 »

So I'm trying to automate the "/c game.player.selected.amount = ###" command. It's a huge pain to have to do that manually for every single tile in a field of ore even with the console command history. I looked at a few different ways of doing this but with my very limited understanding of Lua (I really just cannot parse its structure so anything more than basic commands I'm never sure if my errors are with me structuring things badly or the command itself not being utilized properly) and the complete lack of examples in the API documentation I just cannot figure this out. I tried setting the command to run once per tick with this code:

Code: Select all

/c game.onevent(defines.events.ontick, function(event) if game.tick % 60 == 0 then game.player.selected.amount=30000010 end end)
which I co-opted from some code I came across on Reddit. This gives this error however:
Image

After that I tried this code:

Code: Select all

/c defines.events.on_gui_click, function() game.player.selected.amount = 30000010 end
I noticed after the fact that it specifies gui clicks though so I'm not sure it would even function the way I wanted to begin with. It, however, gives this error:
Image

After this I tried several different things, most of which were completely misguided to begin with such as game.player.surface.get_tile() which of course wouldn't work since resources aren't tiles. I eventually stumbled across game.player.surface.find_entities() and game.player.surface.find_entities_filtered{area = {{-10, -10}, {10, 10}}, type= "resource"} which seemed promising. I can't actually tell whether these commands actually work though because they return absolutely no info in the console despite not erroring out and trying to print them doesn't return anything at all either. This, for example:

Code: Select all

/c game.player.print(game.player.surface.find_entities_filtered{area = {{-10, -10}, {10, 10}}, type= "resource"})
gives an error of this:
Image
while adding .name to the end (which appears to be valid according to the documentation) just returns a nil value.

It doesn't really matter to me what sort of method I'd need to really use but it would be extremely helpful if someone could help me figure out some way to make this a lot easier than having to do /c game.player.selected.amount =### for each and every tile.

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Console help

Post by Nexela »

Are you doing this for existing ore or are you trying to create ore?

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Console help

Post by Nexela »

Existing ores, 10 tiles in each direction of the player (.13 or .14 version of factorio)

Code: Select all

/c x=game.player.position.x; y=game.player.position.y ;for _,ore in pairs(game.player.surface.find_entities_filtered{area={{x-10, y-10},{x+10, y+10}}, type="resource"}) do ore.amount=30000 end
Create a new patch of coal in a 20x20 square centered on player deleting any existing resource underneath

Code: Select all

/c x=game.player.position.x; y=game.player.position.y; area={{x-20, y-20},{x+20, y+20}}; for _,ore in pairs(game.player.surface.find_entities_filtered{area=area, type="resource"}) do ore.destroy(); end; for i=x-20, x+20, 1 do for j=y-20, y+20, 1 do game.player.surface.create_entity{name="coal", amount=3000, position={i, j}} end end
P.S no checks so don't place this too close to water

User avatar
Alice3173
Fast Inserter
Fast Inserter
Posts: 119
Joined: Sun Apr 24, 2016 11:35 pm
Contact:

Re: Console help

Post by Alice3173 »

Nexela wrote:Are you doing this for existing ore or are you trying to create ore?
It's for existing ore. Mid to late game with some mods you tend to burn through entire ore fields so quickly that it's almost not even worth building factories up around them so I'd like to fill them up more than they are by default.
Nexela wrote:Existing ores, 10 tiles in each direction of the player (.13 or .14 version of factorio)

Code: Select all

/c x=game.player.position.x; y=game.player.position.y ;for _,ore in pairs(game.player.surface.find_entities_filtered{area={{x-10, y-10},{x+10, y+10}}, type="resource"}) do ore.amount=30000 end
Hm, I tried this but while it doesn't error out it doesn't actually seem to do anything either. Is there any chance a mod might somehow break it? Cause I'm currently using two mods that affect ores in some fashion. Bob's Mod's ores as well as Angel's Infinite Ores. Tried it on both an area of coal as well as an area of some of the mods from Bob's Mods and it doesn't seem to affect them. (Edit: Also version is 0.13.20 if there's any differences between 0.13 and 0.14 that'd be relevant here.)

User avatar
Deadly-Bagel
Smart Inserter
Smart Inserter
Posts: 1498
Joined: Wed Jul 13, 2016 10:12 am
Contact:

Re: Console help

Post by Deadly-Bagel »

Heh, I was messing about trying to find out what was in one of the chests in the last level of Transport Belt Madness last night (turns out it was coins). I was trying to query the chest directly but first I had to find it from the position.

Same command (can't remember exactly what it was, FindEntities I think) but with different parameters:

Code: Select all

Expected table, got number.
Expected number, got table
Made me laugh xD
Money might be the root of all evil, but ignorance is the heart.

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Console help

Post by Nexela »

Hm, I tried this but while it doesn't error out it doesn't actually seem to do anything either. Is there any chance a mod might somehow break it? Cause I'm currently using two mods that affect ores in some fashion. Bob's Mod's ores as well as Angel's Infinite Ores. Tried it on both an area of coal as well as an area of some of the mods from Bob's Mods and it doesn't seem to affect them. (Edit: Also version is 0.13.20 if there's any differences between 0.13 and 0.14 that'd be relevant here.)
Not sure how it interacts with angels infinite ores but I don't imagine there would be a problem.

all that code does is look through the resources the player is standing on and sets the amount to 30k. if you hover over a piece of ore it should say 30k left.

edit: if you are copy/pasting the code make sure it starts at the beginning of the line and goes all the way to the "end"

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5152
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Console help

Post by Klonan »

Alice3173 wrote:

Code: Select all

/c game.onevent(defines.events.ontick, function(event) if game.tick % 60 == 0 then game.player.selected.amount=30000010 end end)

Code: Select all

/c defines.events.on_gui_click, function() game.player.selected.amount = 30000010 end

Code: Select all

/c game.player.print(game.player.surface.find_entities_filtered{area = {{-10, -10}, {10, 10}}, type= "resource"})
All of these are incorrect in some way, something like this is your best chance:

Code: Select all

/c local d = 20 local p = game.player local s = p.surface local pp = p.position local area = {{pp.x-d,pp.y-d},{pp.x+d,pp.y+d}} for k, ore in pairs (s.find_entities_filtered{area = area, type = "resource"}) do ore.amount = 10000 end

User avatar
Alice3173
Fast Inserter
Fast Inserter
Posts: 119
Joined: Sun Apr 24, 2016 11:35 pm
Contact:

Re: Console help

Post by Alice3173 »

Nexela wrote:Not sure how it interacts with angels infinite ores but I don't imagine there would be a problem.

all that code does is look through the resources the player is standing on and sets the amount to 30k. if you hover over a piece of ore it should say 30k left.

edit: if you are copy/pasting the code make sure it starts at the beginning of the line and goes all the way to the "end"
Klonan's code doesn't seem to have any effect either so maybe one of the mods does change things in some odd way. And I definitely got the whole line. I used the "select all" button that code tags have when copy+pasting it.
Klonan wrote:All of these are incorrect in some way, something like this is your best chance:

Code: Select all

/c local d = 20 local p = game.player local s = p.surface local pp = p.position local area = {{pp.x-d,pp.y-d},{pp.x+d,pp.y+d}} for k, ore in pairs (s.find_entities_filtered{area = area, type = "resource"}) do ore.amount = 10000 end
I thought that might be the case. I have little to no experience with Lua and I just cannot wrap my head around the way it's structured or something. Between that and the lack of example code in the api documentation I tend to do a lot of flailing around with trial and error. And your code doesn't seem to do anything either. There's no errors from your code nor Nexela's but it doesn't seem to affect any of my ores. I tried replading 'type = "resources"' with 'name = "coal"' while standing in the middle of some coal and that didn't work either. Is there any way to print out what entities it returns through find_entities_filtered? That's actually been a huge problem for me trying to figure things out is I never seem to be able to actually see the results of a lot of the commands the game has.
Last edited by Alice3173 on Wed Sep 07, 2016 9:36 am, edited 1 time in total.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5152
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Console help

Post by Klonan »

Alice3173 wrote:
Nexela wrote:Not sure how it interacts with angels infinite ores but I don't imagine there would be a problem.

all that code does is look through the resources the player is standing on and sets the amount to 30k. if you hover over a piece of ore it should say 30k left.

edit: if you are copy/pasting the code make sure it starts at the beginning of the line and goes all the way to the "end"
Klonan's code doesn't seem to have any effect either so maybe one of the mods does change things in some odd way. And I definitely got the whole line. I used the "select all" button that code tags have when copy+pasting it.
Klonan wrote:All of these are incorrect in some way, something like this is your best chance:

Code: Select all

/c local d = 20 local p = game.player local s = p.surface local pp = p.position local area = {{pp.x-d,pp.y-d},{pp.x+d,pp.y+d}} for k, ore in pairs (s.find_entities_filtered{area = area, type = "resource"}) do ore.amount = 10000 end
I thought that might be the case. I have little to no experience with Lua and I just cannot wrap my head around the way it's structured for something. Between that and the lack of example code in the api documentation I tend to do a lot of flailing around with trial and error. And your code doesn't seem to do anything either. There's no errors from your code nor Nexela's but it doesn't seem to affect any of my ores. I tried replading 'type = "resources"' with 'name = "coal"' while standing in the middle of some coal and that didn't work either. Is there any way to print out what entities it returns through find_entities_filtered? That's actually been a huge problem for me trying to figure things out is I never seem to be able to actually see the results of a lot of the commands the game has.
To print the names you can do this:

Code: Select all

/c local d = 20 local p = game.player local s = p.surface local pp = p.position local area = {{pp.x-d,pp.y-d},{pp.x+d,pp.y+d}} for k, ore in pairs (s.find_entities_filtered{area = area, type = "resource"}) do p.print(ore.name.." "..ore.amount) end

User avatar
Alice3173
Fast Inserter
Fast Inserter
Posts: 119
Joined: Sun Apr 24, 2016 11:35 pm
Contact:

Re: Console help

Post by Alice3173 »

Klonan wrote:To print the names you can do this:

Code: Select all

/c local d = 20 local p = game.player local s = p.surface local pp = p.position local area = {{pp.x-d,pp.y-d},{pp.x+d,pp.y+d}} for k, ore in pairs (s.find_entities_filtered{area = area, type = "resource"}) do p.print(ore.name.." "..ore.amount) end
Interestingly that seemed to work fine on both coal as well as some of the stuff from mods. Though it looks like if there's an issue somewhere it'd be with Angel's Infinite Ores and not Bob's Mods since the ores look to be named "angels-ore#". I'm not really sure why the previous code isn't cooperating though if this code works just fine. Could there be some issue with the displayed numbers just not updating for some reason?

Post Reply

Return to “Gameplay Help”