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..
Lua command for increasing depth of existing ore
-
- Long Handed Inserter
- Posts: 56
- Joined: Thu Jun 16, 2016 11:02 am
- Contact:
Re: Lua command for increasing depth of existing ore
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
-
- Long Handed Inserter
- Posts: 71
- Joined: Mon Oct 17, 2016 10:33 am
- Contact:
Re: Lua command for increasing depth of existing ore
You'll need quotes around resource (type = "resource")Klonan wrote:Code: Select all
local resources = surface.find_entities_filtered{type = resource, area = area}
Re: Lua command for increasing depth of existing ore
Code: Select all
for k, resource in pairs(resources) do
-
- Long Handed Inserter
- Posts: 56
- Joined: Thu Jun 16, 2016 11:02 am
- Contact:
Re: Lua command for increasing depth of existing ore
Fantastic, that looks exactly like the snippet I wanted to have. Thank you
Re: Lua command for increasing depth of existing ore
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.
-
- Long Handed Inserter
- Posts: 56
- Joined: Thu Jun 16, 2016 11:02 am
- Contact:
Re: Lua command for increasing depth of existing ore
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...
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...