Lua command for increasing depth of existing ore

Place to get help with not working mods / modding interface.
Lastmerlin
Long Handed Inserter
Long Handed Inserter
Posts: 56
Joined: Thu Jun 16, 2016 11:02 am
Contact:

Lua command for increasing depth of existing ore

Post 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..
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5266
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Lua command for increasing depth of existing ore

Post 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
Articulating
Long Handed Inserter
Long Handed Inserter
Posts: 71
Joined: Mon Oct 17, 2016 10:33 am
Contact:

Re: Lua command for increasing depth of existing ore

Post 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") :)
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Lua command for increasing depth of existing ore

Post by Nexela »

Code: Select all

for k, resource in pairs(resources) do
also missing an s on resources
Lastmerlin
Long Handed Inserter
Long Handed Inserter
Posts: 56
Joined: Thu Jun 16, 2016 11:02 am
Contact:

Re: Lua command for increasing depth of existing ore

Post by Lastmerlin »

Fantastic, that looks exactly like the snippet I wanted to have. Thank you :)
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Lua command for increasing depth of existing ore

Post 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.
Lastmerlin
Long Handed Inserter
Long Handed Inserter
Posts: 56
Joined: Thu Jun 16, 2016 11:02 am
Contact:

Re: Lua command for increasing depth of existing ore

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

Return to “Modding help”