gruppe-adler / grad-persistence

Save/Load mission progress in server's profileNamespace
26 stars 13 forks source link

How to autoexecute grad_persistence_fnc_saveMission ? #51

Open Ravenger2709 opened 2 years ago

Ravenger2709 commented 2 years ago

Hi! I used your script in my mission. On #save command with admin privelegies it`s work fine, but i want to autpsave my mission.

Added this to init.sqf :

while {true} do
{
    sleep 10;
    [true, 10] remoteExec ["grad_persistence_fnc_saveMission",2,false];
};

but it`s only save player state, not vehicles, storages and ect.

Can anybody help my to write right script?

McDiod commented 2 years ago

This should do it:

// in initServer.sqf
[] spawn {
    while {true} do {
        sleep 10;
        [true, 10] call grad_persistence_fnc_saveMission;
    };
};

or if you want to get more fancy:

// in initServer.sqf
[{
    [true, 10] call grad_persistence_fnc_saveMission;
} , 10, []] call CBA_fnc_addPerFrameHandler;
SE-Lynx commented 1 year ago

I've been doing a few experiments and have found the following approach to work well. It saves whenever a player disconnects and when an admin uses #missions or #restart. It unfortunately does not save on server shutdown but the save-on-disconnect is a half-assed workaround. init.sqf

if (hasInterface) then {
    [] spawn {
        waitUntil {!isNull findDisplay 46};
        (findDisplay 46) displayAddEventHandler ["Unload", {
            if (!isServer) exitWith {};
            [false, 0] call grad_persistence_fnc_saveMission;
        }];
    };
} else {
    addMissionEventHandler ["HandleDisconnect", {
        if !(allPlayers isEqualTo []) exitWith {false};
        params ["_unit"];
        deleteVehicle _unit;
        [false, 0] call grad_persistence_fnc_saveMission;
    }];
};

initServer.sqf

if (isServer || isDedicated) exitWith {
    addMissionEventHandler ["MPEnded", {
        [false, 0] call grad_persistence_fnc_saveMission;
    }];
};