From 3457f2416128c2f4d96f221af0e37ed57c313822 Mon Sep 17 00:00:00 2001 From: Jacob Schmidt Date: Sat, 22 Feb 2025 09:07:27 -0600 Subject: [PATCH] Update save and load functions to support scheduled/unscheduled execution --- addons/load/functions/fnc_custom.sqf | 11 ++++++++--- addons/save/functions/fnc_custom.sqf | 20 +++++++++++++++----- missionTemplate/configs/xpdb.h | 4 ++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/addons/load/functions/fnc_custom.sqf b/addons/load/functions/fnc_custom.sqf index 44a694f..2d41a3d 100644 --- a/addons/load/functions/fnc_custom.sqf +++ b/addons/load/functions/fnc_custom.sqf @@ -17,7 +17,6 @@ * * Arguments: * 0: ID of Slot (default: 0) - * 1: Unscheduled environment (default: false) * * Return Value: * N/A @@ -46,6 +45,7 @@ private _loadEntries = "true" configClasses (_config); private _entryName = configName _x; private _functionName = getText (_x >> "function"); private _args = getArray (_x >> "args"); + private _scheduled = getNumber (_x >> "scheduled") == 1; if (_functionName != "") then { private _function = call compile _functionName; @@ -53,9 +53,14 @@ private _loadEntries = "true" configClasses (_config); if (!isNil "_savedData") then { _args pushBack _savedData; - _args call _function; - [EGVAR(db,debug), "xpdb_load_fnc_custom", format ["Loading '%1.%2.%3'", EGVAR(db,prefix), _slot, _entryName], false] call EFUNC(utils,debug); + if (_scheduled) then { + _args spawn _function; + [EGVAR(db,debug), "xpdb_load_fnc_custom", format ["Loading '%1.%2.%3'", EGVAR(db,prefix), _slot, _entryName], false] call EFUNC(utils,debug); + } else { + _args call _function; + [EGVAR(db,debug), "xpdb_load_fnc_custom", format ["Loading '%1.%2.%3'", EGVAR(db,prefix), _slot, _entryName], false] call EFUNC(utils,debug); + }; }; }; } forEach _loadEntries; diff --git a/addons/save/functions/fnc_custom.sqf b/addons/save/functions/fnc_custom.sqf index 5a1ba8c..5817325 100644 --- a/addons/save/functions/fnc_custom.sqf +++ b/addons/save/functions/fnc_custom.sqf @@ -17,7 +17,6 @@ * * Arguments: * 0: ID of Slot (default: 0) - * 1: Unscheduled environment (default: false) * * Return Value: * N/A @@ -45,14 +44,25 @@ private _saveEntries = "true" configClasses (_config); private _entryName = configName _x; private _functionName = getText (_x >> "function"); private _args = getArray (_x >> "args"); + private _scheduled = getNumber (_x >> "scheduled") == 1; if (_functionName != "") then { private _function = call compile _functionName; - private _result = _args call _function; - if (!isNil "_result") then { - [EGVAR(db,debug), "xpdb_save_fnc_custom", format ["Saving '%1.%2.%3'", EGVAR(db,prefix), _slot, _entryName], false] call EFUNC(utils,debug); - [_entryName, _result, _slot] call EFUNC(core,saveData); + if (_scheduled) then { + private _result = _args spawn _function; + + if (!isNil "_result") then { + [EGVAR(db,debug), "xpdb_save_fnc_custom", format ["Saving '%1.%2.%3'", EGVAR(db,prefix), _slot, _entryName], false] call EFUNC(utils,debug); + [_entryName, _result, _slot] call EFUNC(core,saveData); + }; + } else { + private _result = _args call _function; + + if (!isNil "_result") then { + [EGVAR(db,debug), "xpdb_save_fnc_custom", format ["Saving '%1.%2.%3'", EGVAR(db,prefix), _slot, _entryName], false] call EFUNC(utils,debug); + [_entryName, _result, _slot] call EFUNC(core,saveData); + }; }; }; } forEach _saveEntries; diff --git a/missionTemplate/configs/xpdb.h b/missionTemplate/configs/xpdb.h index 7170cb1..57ec660 100644 --- a/missionTemplate/configs/xpdb.h +++ b/missionTemplate/configs/xpdb.h @@ -3,20 +3,24 @@ class CfgXPDB { class playerStats { // XPDB_ARMADBCORE.0.playerStats function = "TAG_player_fnc_saveStats"; args[] = {}; + scheduled = 0; }; class world { // XPDB_ARMADBCORE.0.world function = "TAG_world_fnc_saveNearbyVehicles"; args[] = {}; + scheduled = 0; }; }; class load { class playerStats { // XPDB_ARMADBCORE.0.playerStats function = "TAG_player_fnc_loadStats"; args[] = {}; + scheduled = 1; }; class world { // XPDB_ARMADBCORE.0.world function = "TAG_world_fnc_loadNearbyVehicles"; args[] = {}; + scheduled = 1; }; }; }; \ No newline at end of file