From 9f7d86c7f48c5ade1f8b4f6667069546efd9a8ff Mon Sep 17 00:00:00 2001 From: McDiod Date: Wed, 10 Jul 2019 21:59:23 +0200 Subject: [PATCH 1/7] add ability to cancel unflip --- addons/unflipping/XEH_preInitClient.sqf | 46 +++++++++++++++---- addons/unflipping/XEH_preInitServer.sqf | 27 +++++++++-- .../unflipping/functions/fn_unflipAction.sqf | 15 ++++-- 3 files changed, 71 insertions(+), 17 deletions(-) diff --git a/addons/unflipping/XEH_preInitClient.sqf b/addons/unflipping/XEH_preInitClient.sqf index 02825ac..f0c10f1 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..23035d6 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..56d4723 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; From d9ded0e0feea00fbd002fc54e2e90e14ff0f6225 Mon Sep 17 00:00:00 2001 From: McDiod Date: Thu, 11 Jul 2019 16:12:38 +0200 Subject: [PATCH 2/7] cancel-unflip code style Co-Authored-By: Filip Maciejewski --- addons/unflipping/XEH_preInitClient.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/unflipping/XEH_preInitClient.sqf b/addons/unflipping/XEH_preInitClient.sqf index f0c10f1..f075c9e 100644 --- a/addons/unflipping/XEH_preInitClient.sqf +++ b/addons/unflipping/XEH_preInitClient.sqf @@ -21,7 +21,7 @@ _this#2, // condition { - params ["_args","","_elapsedTime"]; + params ["_args", "", "_elapsedTime"]; _args params ["_vehicle", "_requiredUnits"]; // don't check before 1s elapsed to wait for publicVariable synchronization From 6239492e749bbfc5565820322664dec825965fe1 Mon Sep 17 00:00:00 2001 From: McDiod Date: Thu, 11 Jul 2019 16:12:46 +0200 Subject: [PATCH 3/7] cancel-unflip code style Co-Authored-By: Filip Maciejewski --- addons/unflipping/XEH_preInitClient.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/unflipping/XEH_preInitClient.sqf b/addons/unflipping/XEH_preInitClient.sqf index f075c9e..794f637 100644 --- a/addons/unflipping/XEH_preInitClient.sqf +++ b/addons/unflipping/XEH_preInitClient.sqf @@ -32,7 +32,7 @@ {}, // onFailure { - params ["_args","","","","_failureCode"]; + params ["_args", "", "", "", "_failureCode"]; _args params ["_vehicle", "", ""]; // user hit ESC From 82406d2b7aab8d52c6c71b351c62da744d32a8a7 Mon Sep 17 00:00:00 2001 From: McDiod Date: Thu, 11 Jul 2019 16:13:01 +0200 Subject: [PATCH 4/7] cancel-unflip code style Co-Authored-By: Filip Maciejewski --- addons/unflipping/XEH_preInitClient.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/unflipping/XEH_preInitClient.sqf b/addons/unflipping/XEH_preInitClient.sqf index 794f637..556f850 100644 --- a/addons/unflipping/XEH_preInitClient.sqf +++ b/addons/unflipping/XEH_preInitClient.sqf @@ -43,7 +43,7 @@ } 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 { + if (PLAYER in (_vehicle getVariable ["vet_unflippingUnits", []])) then { [_vehicle] call vet_unflipping_fnc_unflipAction; }; }; From c0939c930303bef2ee5544fad42b5d18f6fcfe8c Mon Sep 17 00:00:00 2001 From: McDiod Date: Thu, 11 Jul 2019 16:13:09 +0200 Subject: [PATCH 5/7] cancel-unflip code style Co-Authored-By: Filip Maciejewski --- addons/unflipping/XEH_preInitServer.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/unflipping/XEH_preInitServer.sqf b/addons/unflipping/XEH_preInitServer.sqf index 23035d6..6e60994 100644 --- a/addons/unflipping/XEH_preInitServer.sqf +++ b/addons/unflipping/XEH_preInitServer.sqf @@ -19,7 +19,7 @@ [ // condition { - params ["_vehicle","_requiredUnits"]; + params ["_vehicle", "_requiredUnits"]; count (_vehicle getVariable ["vet_unflippingUnits", []]) < _requiredUnits }, // statement (failure) From 5b38cad5a8ff97c9e21a0122b292f22fe362029f Mon Sep 17 00:00:00 2001 From: McDiod Date: Thu, 11 Jul 2019 16:13:17 +0200 Subject: [PATCH 6/7] cancel-unflip code style Co-Authored-By: Filip Maciejewski --- addons/unflipping/XEH_preInitServer.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/unflipping/XEH_preInitServer.sqf b/addons/unflipping/XEH_preInitServer.sqf index 6e60994..23588a2 100644 --- a/addons/unflipping/XEH_preInitServer.sqf +++ b/addons/unflipping/XEH_preInitServer.sqf @@ -25,7 +25,7 @@ // statement (failure) {}, // args - [_vehicle,_requiredUnits], + [_vehicle, _requiredUnits], // timeout vet_unflipping_time, // onTimeout (success) From d3a3bb9bb86b555d6e524004dbda5bea05b7fb52 Mon Sep 17 00:00:00 2001 From: McDiod Date: Thu, 11 Jul 2019 16:13:25 +0200 Subject: [PATCH 7/7] cancel-unflip code style Co-Authored-By: Filip Maciejewski --- addons/unflipping/functions/fn_unflipAction.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/unflipping/functions/fn_unflipAction.sqf b/addons/unflipping/functions/fn_unflipAction.sqf index 56d4723..5b2386c 100644 --- a/addons/unflipping/functions/fn_unflipAction.sqf +++ b/addons/unflipping/functions/fn_unflipAction.sqf @@ -66,7 +66,7 @@ if !(PLAYER in UNFLIPPING_UNITS) exitWith { }, // onFailure { - params ["_args","","","","_failureCode"]; + params ["_args", "", "", "", "_failureCode"]; _args params ["_vehicle"]; // don't stop unflipping if waiting progressBar was closed by new progressBar