diff --git a/addons/unflipping/XEH_preInitClient.sqf b/addons/unflipping/XEH_preInitClient.sqf index 02825ac..556f850 100644 --- a/addons/unflipping/XEH_preInitClient.sqf +++ b/addons/unflipping/XEH_preInitClient.sqf @@ -1,5 +1,6 @@ #include "initSettings.sqf" +#define PLAYER ([] call CBA_fnc_currentUnit) ["vet_unflipping_unflip_start_client", { diag_log text "[VET_Unflipping] Starting action"; @@ -8,23 +9,52 @@ // Force player to wait for unflipping time ["vet_unflipping_unflip_ready", { - params ["_time"]; + diag_log text "[VET_Unflipping] Unflip ready"; - // Spawn new unclosable progressbar for unflip action time + + // Spawn new progressbar for unflip action time [{ // TODO animation [ localize "STR_vet_unflipping_doing", - _this, - {true}, - {}, + // time + _this#2, + // condition + { + params ["_args", "", "_elapsedTime"]; + _args params ["_vehicle", "_requiredUnits"]; + + // don't check before 1s elapsed to wait for publicVariable synchronization + _elapsedTime < 1 || + {count (_vehicle getVariable ["vet_unflippingUnits", []]) >= _requiredUnits} + }, + // onSuccess {}, - [], + // onFailure + { + params ["_args", "", "", "", "_failureCode"]; + _args params ["_vehicle", "", ""]; + + // user hit ESC + if (_failureCode == 1) then { + ["vet_unflipping_unflip_stop", [_vehicle, PLAYER]] call CBA_fnc_serverEvent; + + // user did not hit ESC --> other reason for failure + } else { + // if user is in unflippingUnits --> enter wait mode again + // if not --> server has completed unflipping and reset the array + if (PLAYER in (_vehicle getVariable ["vet_unflippingUnits", []])) then { + [_vehicle] call vet_unflipping_fnc_unflipAction; + }; + }; + }, + // args + _this, true, // block mouse true, // block keys - false // allow close (esc) + true // allow close (esc) ] call CBA_fnc_progressBar; - }, _time] call CBA_fnc_execNextFrame; + }, _this] call CBA_fnc_execNextFrame; }] call CBA_fnc_addEventHandler; // Add ACE3 or Vanilla actions to vehicles diff --git a/addons/unflipping/XEH_preInitServer.sqf b/addons/unflipping/XEH_preInitServer.sqf index e3342d0..23588a2 100644 --- a/addons/unflipping/XEH_preInitServer.sqf +++ b/addons/unflipping/XEH_preInitServer.sqf @@ -14,13 +14,30 @@ // Enough people, exit and unflip vehicle if (_requiredUnits <= count _unflippingUnits) exitWith { diag_log text format ["[VET_Unflipping] Vehicle '%1', enough people to unflip (%2)", _vehicle, _requiredUnits]; + // Schedule unflip - [{ - _this call vet_unflipping_fnc_unflipVehicle; - _this setVariable ["vet_unflippingUnits", [], true]; - }, _vehicle, vet_unflipping_time] call CBA_fnc_waitAndExecute; + [ + // condition + { + params ["_vehicle", "_requiredUnits"]; + count (_vehicle getVariable ["vet_unflippingUnits", []]) < _requiredUnits + }, + // statement (failure) + {}, + // args + [_vehicle, _requiredUnits], + // timeout + vet_unflipping_time, + // onTimeout (success) + { + params ["_vehicle"]; + _vehicle call vet_unflipping_fnc_unflipVehicle; + _vehicle setVariable ["vet_unflippingUnits", [], true]; + } + ] call CBA_fnc_waitUntilAndExecute; + // Inform clients that unflip is ready and force them into unflip action wait time - ["vet_unflipping_unflip_ready", vet_unflipping_time, _unflippingUnits] call CBA_fnc_targetEvent; + ["vet_unflipping_unflip_ready", [_vehicle, _requiredUnits, vet_unflipping_time], _unflippingUnits] call CBA_fnc_targetEvent; }; diag_log text format ["[VET_Unflipping] Vehicle '%1', not enough people to unflip (%2)", _vehicle, _requiredUnits]; diff --git a/addons/unflipping/functions/fn_unflipAction.sqf b/addons/unflipping/functions/fn_unflipAction.sqf index 65b0341..5b2386c 100644 --- a/addons/unflipping/functions/fn_unflipAction.sqf +++ b/addons/unflipping/functions/fn_unflipAction.sqf @@ -50,12 +50,13 @@ if !(PLAYER in UNFLIPPING_UNITS) exitWith { localize "STR_vet_unflipping_waiting", 15, { - params ["_vehicle"]; + _this#0 params ["_vehicle"]; !(UNFLIPPING_UNITS isEqualTo []) && alive PLAYER }, + // onSuccess { - params ["_vehicle"]; + _this#0 params ["_vehicle"]; ["vet_unflipping_unflip_stop", [_vehicle, PLAYER]] call CBA_fnc_serverEvent; // Notify [ @@ -63,9 +64,15 @@ if !(PLAYER in UNFLIPPING_UNITS) exitWith { [localize "STR_vet_unflipping_need_more"] ] call CBA_fnc_notify; }, + // onFailure { - params ["_vehicle"]; - ["vet_unflipping_unflip_stop", [_vehicle, PLAYER]] call CBA_fnc_serverEvent; + params ["_args", "", "", "", "_failureCode"]; + _args params ["_vehicle"]; + + // don't stop unflipping if waiting progressBar was closed by new progressBar + if (_failureCode != 3) then { + ["vet_unflipping_unflip_stop", [_vehicle, PLAYER]] call CBA_fnc_serverEvent; + }; }, _this ] call CBA_fnc_progressBar;