map restart without disconnect

Anything that prevents you play the game properly. Do you have issues with paying for the game, downloading it or properly running it on your computer? Let us know here.
Post Reply
XaLpHa89
Burner Inserter
Burner Inserter
Posts: 14
Joined: Wed Jan 24, 2018 6:59 am

map restart without disconnect

Post by XaLpHa89 » Thu Nov 08, 2018 9:39 pm

I am looking for a simple command or function that wants to set the map to complete and restart without disconnecting the player. The map is running on a headless server. With the commandPipe it is currently possible to restart the map via a parallel program.

Code: Select all

game.write_file("commandPipe", ":loadscenario --force", false, 0)

game.set_game_state{game_finished=true, player_won=false, next_level=next_level, can_continue=false}
5be487b6b737f.jpg
5be487b6b737f.jpg (28.62 KiB) Viewed 132 times

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 1468
Joined: Thu Nov 20, 2014 11:11 pm

Re: map restart without disconnect

Post by darkfrei » Fri Nov 09, 2018 6:16 am

Like New game+?

XaLpHa89
Burner Inserter
Burner Inserter
Posts: 14
Joined: Wed Jan 24, 2018 6:59 am

Re: map restart without disconnect

Post by XaLpHa89 » Fri Nov 09, 2018 9:41 pm

darkfrei wrote:
Fri Nov 09, 2018 6:16 am
Like New game+?
The mod meets exactly my idea. I will now watch what I can use of it. Thank you.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 1468
Joined: Thu Nov 20, 2014 11:11 pm

Re: map restart without disconnect

Post by darkfrei » Fri Nov 09, 2018 9:50 pm

XaLpHa89 wrote:
Fri Nov 09, 2018 9:41 pm
The mod meets exactly my idea. I will now watch what I can use of it. Thank you.
Some mods without data.lua can be applied as scenarios or modded-save-game-file, where you can set up control.lua. It means that nobody needs to install this mod, just connect and play.

XaLpHa89
Burner Inserter
Burner Inserter
Posts: 14
Joined: Wed Jan 24, 2018 6:59 am

Re: map restart without disconnect

Post by XaLpHa89 » Fri Nov 09, 2018 11:30 pm

Through you, I have actually found the function I was looking for.

Code: Select all

    local function generate_new_world( player )

        debug_log( 'Generating new game plus...' )

        ---------------------------------------
        -- RSO INTEGRATION
        ---------------------------------------

        debug_log( 'Looking for RSO...' )

        if remote.interfaces[ 'RSO' ]
        then
            debug_log( 'Detected RSO' )

            if remote.interfaces[ 'RSO' ][ 'resetGeneration' ]
            then
                global.use_rso = true
            else
                player.print( { 'msg.new-game-plus-outdated-rso' } )

                return
            end
        else
            debug_log( 'No RSO found' )

            global.use_rso = false
        end

        ---------------------------------------
        -- MAP GEN SETTINGS
        ---------------------------------------

        debug_log( 'Making map gen settings...' )

        local map_gen_settings = make_map_gen_settings( player )

        if not map_gen_settings
        then
            debug_log( 'Aborted generating new game plus' )

            return
        end

        ---------------------------------------
        -- MAP SETTINGS
        ---------------------------------------

        debug_log( 'Changing map settings...' )

        if not change_map_settings( player )
        then
            debug_log( 'Aborted generating new game plus' )

            return
        end

        ---------------------------------------
        -- CREATE NEW SURFACE
        ---------------------------------------

        debug_log( 'Creating surface...' )

        local surface_number = util.get_valid_surface_number( global.next_nauvis_number )

        local nauvis_plus = game.create_surface( 'Nauvis plus ' .. surface_number, map_gen_settings )

        ---------------------------------------
        -- TELEPORT PLAYERS TO NEW SURFACE
        ---------------------------------------

        for _, player in pairs( game.players )
        do
            player.teleport( { 1, 1 }, nauvis_plus )

            player.force.chart( nauvis_plus, { { player.position.x - 200, player.position.y - 200 }, { player.position.x + 200, player.position.y + 200 } } )
        end

        ---------------------------------------
        -- SET SPAWN
        ---------------------------------------

        for _, force in pairs( game.forces )
        do
            force.set_spawn_position( { 1,1 }, nauvis_plus )
        end

        ---------------------------------------
        -- SET WHETHER THE TECH NEEDS TO BE RESET
        ---------------------------------------

        local frame_flow = mod_gui.get_frame_flow( player )

        if frame_flow[ 'new-game-plus-config-frame' ][ 'new-game-plus-config-option-table' ][ 'new-game-plus-reset-research-checkbox' ].state
        then
            global.tech_reset = true
        else
            global.tech_reset = false
        end

        ---------------------------------------
        -- KILL THE GUI, IT'S NOT NEEDED AND
        -- SHOULD NOT EXIST IN THE BACKGROUND
        ---------------------------------------

        debug_log( 'Destroying the gui...' )

        for _, player in pairs( game.players )
        do
            gui.kill( player )
        end

        ---------------------------------------
        -- DESTROY THE OTHER SURFACES
        ---------------------------------------

        debug_log( 'Removing surfaces...' )

        for _,surface in pairs( game.surfaces )
        do
            ---------------------------------------
            -- CAN NOT DELETE NAUVIS
            ---------------------------------------

            if surface.name == 'nauvis'
            then
                ---------------------------------------
                -- BE NICE TO OTHER MODS
                ---------------------------------------

                script.raise_event( on_pre_surface_cleared_event, { surface_index = surface.index } )

                ---------------------------------------
                -- SO I DELETE ITS CHUNKS
                ---------------------------------------

                for chunk in surface.get_chunks()
                do
                    surface.delete_chunk( { chunk.x, chunk.y } )
                end

                debug_log( 'Deleted nauvis chunks.' )

            elseif not surface.name:find( 'Factory floor' ) and ( surface.name ~= 'Nauvis plus ' .. global.next_nauvis_number )
            then
                ---------------------------------------
                -- DON'T DELETE FACTORISSIMO STUFF OR
                -- THE NEW SURFACE
                ---------------------------------------

                game.delete_surface( surface )
            end
        end

        global.next_nauvis_number = global.next_nauvis_number + 1

        ---------------------------------------
        -- WE ACT LIKE NO ROCKET HAS BEEN
        -- LAUNCHED, SO THAT WE CAN DO THE
        -- WHOLE 'LAUNCH A SATELLITE AND
        -- MAKE GUI' THING AGAIN
        ---------------------------------------

        global.rocket_launched = false

        debug_log( 'New game plus has been generated' )
    end
Last edited by XaLpHa89 on Sun Nov 11, 2018 11:02 pm, edited 1 time in total.

User avatar
Bilka
Factorio Staff
Factorio Staff
Posts: 1024
Joined: Sat Aug 13, 2016 9:20 am

Re: map restart without disconnect

Post by Bilka » Fri Nov 09, 2018 11:41 pm

XaLpHa89 wrote:
Fri Nov 09, 2018 11:30 pm
Through you, I have actually found the function I was looking for.
And you butchered my formatting in the process, that really looks horrible.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

XaLpHa89
Burner Inserter
Burner Inserter
Posts: 14
Joined: Wed Jan 24, 2018 6:59 am

Re: map restart without disconnect

Post by XaLpHa89 » Sat Nov 10, 2018 12:04 am

Bilka wrote:
Fri Nov 09, 2018 11:41 pm
And you butchered my formatting in the process, that really looks horrible.
Regarding reformatting, I have to smile a little bit. But I want to tell you, programmers have so many peculiarities. Most of the code that I read is too narrow and I can only read it correctly if I have implemented my usual formatting. The oldest conflict in programming is the use of four spaces or a tab.

Post Reply

Return to “Technical Help”