Page 1 of 1

Lua command for increasing depth of existing ore

Posted: Sat Jan 28, 2017 6:54 pm
by Lastmerlin
Exactly as the title says :)

There are lots of examples for generating new ore (with excessive depth if you like it). But I like the *natural* shaped ore patches. Hence I would like a command that multiplies the depth of all already existing ore in a certain area around the player by a given factor. This also keeps the natural variation of ore depth among the tiles. Ideally (but optionally), with a condition to multiply only, when the depth is below a threshhold.

I can program myself (although very little experience in Lua), I mainly miss a command to inquire the ore contests of a tile (btw - is there a more in-depth programming reference?). But to be honest - I would be most grateful if someone, who can do this in three minutes, chipped these few lines together, instead of an hour of trial-and-error for myself.

Thanks in advance..

Re: Lua command for increasing depth of existing ore

Posted: Sat Jan 28, 2017 8:15 pm
by Klonan
Something like this:

Code: Select all

local radius = 32
local player = game.player
local surface = player.surface
local position = player.position
local area = 
{
  {position.x - radius, position.y - radius},
  {position.x + radius, position.y + radius}
}
local resources = surface.find_entities_filtered{type = resource, area = area}
for k, resource in pairs(resource) do
  resource.amount = resource.amount + 1000
  resource.amount = resource.amount * 2
  resource.amount = resource.amount + math.random(10)
  if resource.amount < 1000 then
    resource.amount = resource.amount * 10
  end
end

Re: Lua command for increasing depth of existing ore

Posted: Sun Jan 29, 2017 12:10 am
by Articulating
Klonan wrote:

Code: Select all

local resources = surface.find_entities_filtered{type = resource, area = area}
You'll need quotes around resource (type = "resource") :)

Re: Lua command for increasing depth of existing ore

Posted: Sun Jan 29, 2017 12:23 am
by Nexela

Code: Select all

for k, resource in pairs(resources) do
also missing an s on resources

Re: Lua command for increasing depth of existing ore

Posted: Sun Jan 29, 2017 2:19 pm
by Lastmerlin
Fantastic, that looks exactly like the snippet I wanted to have. Thank you :)

Re: Lua command for increasing depth of existing ore

Posted: Mon Jan 30, 2017 8:00 am
by darkfrei
And how to do some map-specified random for resources creation? For example, some scanner searched new patches in this area, but sometimes it's no more ore here. But in another place it could be much better.

Re: Lua command for increasing depth of existing ore

Posted: Mon Jan 30, 2017 9:34 am
by Lastmerlin
Final remark: Adapted the numbers to my needs and it worked perfectly. Thanks!

Last Question (a bit offtopic and for curiosity): What would be the proposed way to figure this out yourself? I found http://lua-api.factorio.com/ . This is the complete and official API reference right? Quite a tough step up from copying premade snippets, but surely possible. Are there any other ressources/ collection of code snippets/ stackoverflow for factorio lua ;) etc.? I suppose the mod forum contains a lot of these too, but its difficult to search. I'm am almost 100% sure something similar was asked multiple times already, but my search attempts did not yield anything...