Help making a custom scenario for unlimited resources

Post all other topics which do not belong to any other category.
Post Reply
Silba
Burner Inserter
Burner Inserter
Posts: 19
Joined: Mon Mar 20, 2017 4:24 pm
Contact:

Help making a custom scenario for unlimited resources

Post by Silba »

Hi everyone, hope this is the right place.

I'm trying to create a scenario very similar to the recent crash site scenarios except i would like unlimited coal, stone, iron and copper ore with oil and (now)uranium being scarce to force expansion and exploration. I tried using Creative Mode mod(before .15 was out so im not trying to use outdated mods) but either the mod or map editor are broken when placing duplicator chests as they don't function unless i manually place them which means the scenario doesnt work without setup which gets quite tedius. I know i can save right after setup and use that as my starting point but i would like to just load the scenario directly and be able to play and share it with no setup.

Is there any way to provide unlimited resources in a small space? The idea is to have unlimited but with limited throughput in a compact space without pre setting up 100s of miners in an almost unlmited pile of ores and belting it down. i'm open to mods or even making my own if someone could point me in the right direction if it's simple enough.

Daid
Fast Inserter
Fast Inserter
Posts: 163
Joined: Sun Jul 03, 2016 7:42 am
Contact:

Re: Help making a custom scenario for unlimited resources

Post by Daid »

I've used this as control.lua script for a scenario with unlimited resources, including trees.

Code: Select all

script.on_event(defines.events.on_tick, function(event)
    --Refill all resources when they are drained.
    if global.resource_list == nil then
        global.resource_list = game.surfaces["nauvis"].find_entities_filtered{type="resource"}
        global.resource_index = 1
    end
    if global.resource_index >= #global.resource_list then
        global.resource_index = 1
        checkForNewTrees()
    else
        global.resource_index = global.resource_index + 1
    end
    local resource = global.resource_list[global.resource_index]
    if resource ~= nil then
        if resource.amount < resource.prototype.autoplace_specification.richness_multiplier * 10 then
            resource.amount = resource.amount + resource.prototype.autoplace_specification.richness_multiplier * 10
        end
    end
end)

function checkForNewTrees()
    --Check how many trees we have, when there are no more trees, we want to grow some new ones.
    if global.tree_list == nil then
        global.tree_list = game.surfaces["nauvis"].find_entities_filtered{type="tree"}
    end
    local tree_count = 0
    for index, tree in pairs(global.tree_list) do
        if not tree.valid then
            global.tree_list[index] = nil
        else
            tree_count = tree_count + 1
        end
    end
    if tree_count < 15 then
        local map_size = 64
        local tree_type = "tree-0" .. math.random(1, 5)
        local position = game.surfaces["nauvis"].find_non_colliding_position(tree_type, {math.random(-map_size, map_size), math.random(-map_size, map_size)}, map_size, 2)
        if position ~= nil then
            table.insert(global.tree_list, game.surfaces["nauvis"].create_entity{name=tree_type, position=position})
        end
    end 
end

Silba
Burner Inserter
Burner Inserter
Posts: 19
Joined: Mon Mar 20, 2017 4:24 pm
Contact:

Re: Help making a custom scenario for unlimited resources

Post by Silba »

Daid wrote:I've used this as control.lua script for a scenario with unlimited resources, including trees.

Code: Select all

script.on_event(defines.events.on_tick, function(event)
    --Refill all resources when they are drained.
    if global.resource_list == nil then
        global.resource_list = game.surfaces["nauvis"].find_entities_filtered{type="resource"}
        global.resource_index = 1
    end
    if global.resource_index >= #global.resource_list then
        global.resource_index = 1
        checkForNewTrees()
    else
        global.resource_index = global.resource_index + 1
    end
    local resource = global.resource_list[global.resource_index]
    if resource ~= nil then
        if resource.amount < resource.prototype.autoplace_specification.richness_multiplier * 10 then
            resource.amount = resource.amount + resource.prototype.autoplace_specification.richness_multiplier * 10
        end
    end
end)

function checkForNewTrees()
    --Check how many trees we have, when there are no more trees, we want to grow some new ones.
    if global.tree_list == nil then
        global.tree_list = game.surfaces["nauvis"].find_entities_filtered{type="tree"}
    end
    local tree_count = 0
    for index, tree in pairs(global.tree_list) do
        if not tree.valid then
            global.tree_list[index] = nil
        else
            tree_count = tree_count + 1
        end
    end
    if tree_count < 15 then
        local map_size = 64
        local tree_type = "tree-0" .. math.random(1, 5)
        local position = game.surfaces["nauvis"].find_non_colliding_position(tree_type, {math.random(-map_size, map_size), math.random(-map_size, map_size)}, map_size, 2)
        if position ~= nil then
            table.insert(global.tree_list, game.surfaces["nauvis"].create_entity{name=tree_type, position=position})
        end
    end 
end
So does this replenish ore deposits etc as they run out? I would like to avoid having a large mining operation if possible.

I've never played about with anything outside of the gui so im assuming scenarios get given an .lua file(s) so i would just have this code in place of the original control.lua? If no one else chimes in this might be the only way... assuming my understanding is correct.

Post Reply

Return to “General discussion”