diff --git a/addons/apollo/XEH_postInitClient.sqf b/addons/apollo/XEH_postInitClient.sqf index d645f8d7..3094e88b 100644 --- a/addons/apollo/XEH_postInitClient.sqf +++ b/addons/apollo/XEH_postInitClient.sqf @@ -40,12 +40,8 @@ if (!hasInterface) exitWith {}; }; }] call CBA_fnc_addEventHandler; - // Load player and exit if loading failed - if !([player] call FUNC(playerLoadClient)) exitWith {}; - - // Save on each inventory change and every 10s with a delay between each save - ["loadout", FUNC(playerSaveClient)] call CBA_fnc_addPlayerEventHandler; - [FUNC(playerSaveClient), [player, [], true], SAVE_DELAY_PERIODIC] call CBA_fnc_waitAndExecute; - - INFO("Client loaded successfully."); + // Load client, add inventory one frame after removing initial inventory to prevent possible inventory desync + player allowDamage false; + player setUnitLoadout [[],[],[],[],[],[],"","",[],["","","","","",""]]; + [FUNC(playerLoadClient), [player]] call CBA_fnc_execNextFrame; }] call CBA_fnc_addEventHandler; diff --git a/addons/apollo/functions/fnc_playerLoadClient.sqf b/addons/apollo/functions/fnc_playerLoadClient.sqf index a4a334d5..e5886c6d 100644 --- a/addons/apollo/functions/fnc_playerLoadClient.sqf +++ b/addons/apollo/functions/fnc_playerLoadClient.sqf @@ -6,10 +6,10 @@ * 0: Player * * Return Value: - * Successfully Loaded + * None * * Example: - * _success = [player] call tac_apollo_fnc_playerLoadClient + * [player] call tac_apollo_fnc_playerLoadClient * * Public: No */ @@ -17,18 +17,8 @@ params ["_player"]; -_player allowDamage false; - -removeHeadgear _player: -removeGoggles _player; -removeVest _player; -removeBackpack _player; -removeUniform _player; -removeAllWeapons _player: -removeAllAssignedItems _player; - TRACE_1("Loading Client",_player); -private _return = false; +private _success = false; // Don't load when UID is "_SP_PLAYER_" (singleplayer/editor) if (getPlayerUID _player == "_SP_PLAYER_") exitWith {false}; @@ -47,7 +37,7 @@ if (_loadData == "loaded") then { if (_loadData == "done") then { // Initialization complete _updateInfo = false; - _return = true; + _success = true; } else { _codePacket = _loadData select [17, count _loadData]; //TRACE_1("Code Packet",_codePacket); @@ -57,16 +47,22 @@ if (_loadData == "loaded") then { }; }; -if (!_return) then { - ERROR_2("Player not successfully loaded (Name: %1 - UID: %2)!",profileName,getPlayerUID _player); - ["Your connection has been terminated - Error during Chronos loading!"] call FUNC(endMissionError); -} else { +if (_success) then { // Validate [QGVAR(savePlayer), [_player, "validate"]] call CBA_fnc_serverEvent; + // Has to be executed where unit is local _player allowDamage true; - // Save load time to prevent instant saving after load + + // Allow saving and save load time to prevent instant saving after load _player setVariable [QGVAR(lastSavedTime), CBA_missionTime]; -}; -_return + // Save on each inventory change and periodically with a delay between each save + ["loadout", FUNC(playerSaveClient)] call CBA_fnc_addPlayerEventHandler; + [FUNC(playerSaveClient), [_player, [], true], SAVE_DELAY_PERIODIC] call CBA_fnc_waitAndExecute; + + INFO("Client loaded successfully."); +} else { + ERROR_2("Player not successfully loaded (Name: %1 - UID: %2)!",profileName,getPlayerUID _player); + ["Your connection has been terminated - Error during Chronos loading!"] call FUNC(endMissionError); +}; diff --git a/addons/apollo/functions/fnc_playerSaveClient.sqf b/addons/apollo/functions/fnc_playerSaveClient.sqf index b9490c0b..2963e946 100644 --- a/addons/apollo/functions/fnc_playerSaveClient.sqf +++ b/addons/apollo/functions/fnc_playerSaveClient.sqf @@ -25,12 +25,13 @@ if (_periodic) then { [FUNC(playerSaveClient), [_player, [], _periodic], SAVE_DELAY_PERIODIC] call CBA_fnc_waitAndExecute; }; -// Only save if not remote controlling a unit and more than 10 seconds have passed from previous save +// Exit if delay has not passed yet private _delay = [SAVE_DELAY_INV_CHANGE, SAVE_DELAY_PERIODIC] select _periodic; if ((_player getVariable [QGVAR(lastSavedTime), CBA_missionTime]) + _delay > CBA_missionTime) exitWith { TRACE_1("Save - Not Saving (Delay Running)",CBA_missionTime); }; +// Exit if remote controlling a unit or the player is still invisible if (_player != player || {isNull _player} || {!alive _player} || {isObjectHidden _player}) exitWith { TRACE_1("Save - Not Saving",CBA_missionTime); };