Page 1 of 1

map restart without disconnect

Posted: Thu Nov 08, 2018 9:39 pm
by XaLpHa89
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 2405 times

Re: map restart without disconnect

Posted: Fri Nov 09, 2018 6:16 am
by darkfrei
Like New game+?

Re: map restart without disconnect

Posted: Fri Nov 09, 2018 9:41 pm
by XaLpHa89
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.

Re: map restart without disconnect

Posted: Fri Nov 09, 2018 9:50 pm
by darkfrei
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.

Re: map restart without disconnect

Posted: Fri Nov 09, 2018 11:30 pm
by XaLpHa89
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

Re: map restart without disconnect

Posted: Fri Nov 09, 2018 11:41 pm
by Bilka
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.

Re: map restart without disconnect

Posted: Sat Nov 10, 2018 12:04 am
by XaLpHa89
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.