Skip to content

Commit

Permalink
Merge pull request #18 from McDiod/cancel-unflip
Browse files Browse the repository at this point in the history
close #9 - add ability to cancel unflip
  • Loading branch information
veteran29 committed Jul 11, 2019
2 parents 22178ee + d3a3bb9 commit 7ed05bb
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 17 deletions.
46 changes: 38 additions & 8 deletions addons/unflipping/XEH_preInitClient.sqf
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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
Expand Down
27 changes: 22 additions & 5 deletions addons/unflipping/XEH_preInitServer.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
15 changes: 11 additions & 4 deletions addons/unflipping/functions/fn_unflipAction.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,29 @@ 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
[
["\a3\3den\data\attributes\loiterdirection\cw_ca.paa"],
[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;
Expand Down

0 comments on commit 7ed05bb

Please sign in to comment.