diff --git a/addons/captives/CfgEventHandlers.hpp b/addons/captives/CfgEventHandlers.hpp index 722750f915..8829d0f275 100644 --- a/addons/captives/CfgEventHandlers.hpp +++ b/addons/captives/CfgEventHandlers.hpp @@ -10,15 +10,6 @@ class Extended_PostInit_EventHandlers { }; }; -//release escorted captive when entering a vehicle -class Extended_GetIn_EventHandlers { - class All { - class GVAR(AutoDetachCaptive) { - getIn = QUOTE(_this call FUNC(handleGetIn)); - }; - }; -}; - //reset captive animation after leaving vehicle class Extended_GetOut_EventHandlers { class All { @@ -45,4 +36,3 @@ class Extended_InitPost_EventHandlers { }; }; }; - diff --git a/addons/captives/XEH_postInit.sqf b/addons/captives/XEH_postInit.sqf index 9d1a242d4d..9c124630ee 100644 --- a/addons/captives/XEH_postInit.sqf +++ b/addons/captives/XEH_postInit.sqf @@ -21,6 +21,9 @@ if (isServer) then { }]; }; +["playerVehicleChanged", {_this call FUNC(handleVehicleChanged)}] call EFUNC(common,addEventHandler); +["zeusDisplayChanged", {_this call FUNC(handleZeusDisplayChanged)}] call EFUNC(common,addEventHandler); + //TODO: Medical Integration Events??? // [_unit, "knockedOut", { diff --git a/addons/captives/XEH_preInit.sqf b/addons/captives/XEH_preInit.sqf index 75ee77e9bc..f6ec44225f 100644 --- a/addons/captives/XEH_preInit.sqf +++ b/addons/captives/XEH_preInit.sqf @@ -16,12 +16,13 @@ PREP(doFriskPerson); PREP(doLoadCaptive); PREP(doRemoveHandcuffs); PREP(doUnloadCaptive); -PREP(handleGetIn); PREP(handleGetOut); PREP(handleKilled); PREP(handleKnockedOut); PREP(handlePlayerChanged); PREP(handleUnitInitPost); +PREP(handleVehicleChanged); +PREP(handleZeusDisplayChanged); PREP(handleWokeUp); PREP(moduleSurrender); PREP(setHandcuffed); diff --git a/addons/captives/functions/fnc_handleGetIn.sqf b/addons/captives/functions/fnc_handleGetIn.sqf deleted file mode 100644 index 54133e2362..0000000000 --- a/addons/captives/functions/fnc_handleGetIn.sqf +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Author: commy2 - * Handles when a unit gets in to a vehicle. Release escorted captive when entering a vehicle - * - * Arguments: - * 0: _vehicle - * 2: dunno - * 1: _unit - * - * Return Value: - * The return value - * - * Example: - * [car2, x, player] call ACE_captives_fnc_handleGetIn - * - * Public: No - */ -#include "script_component.hpp" - -PARAMS_3(_vehicle,_dontcare,_unit); - -if ((local _unit) && (_unit getVariable [QGVAR(isEscorting), false])) then { - _unit setVariable [QGVAR(isEscorting), false, true]; -}; diff --git a/addons/captives/functions/fnc_handleKnockedOut.sqf b/addons/captives/functions/fnc_handleKnockedOut.sqf index 3257d544ca..aba01b194f 100644 --- a/addons/captives/functions/fnc_handleKnockedOut.sqf +++ b/addons/captives/functions/fnc_handleKnockedOut.sqf @@ -1,2 +1,25 @@ -// by commy2 +/* + * Author: PabstMirror + * Handles when a unit gets knocked out. Ends surrendering. + * + * Arguments: + * 0: Unit + * + * Return Value: + * Nothing + * + * Example: + * [bob, true] call ACE_captives_fnc_handleKnockedOut + * + * Public: No + */ +#include "script_component.hpp" + +//ToDo: Waiting on medical integration + +PARAMS_1(_unit); + +if (_unit getVariable [QGVAR(isSurrendering), false]) then { //If surrendering, stop + [_unit, _false] call FUNC(surrender); +}; diff --git a/addons/captives/functions/fnc_handlePlayerChanged.sqf b/addons/captives/functions/fnc_handlePlayerChanged.sqf index 13e284ef80..21fd1e1ec3 100644 --- a/addons/captives/functions/fnc_handlePlayerChanged.sqf +++ b/addons/captives/functions/fnc_handlePlayerChanged.sqf @@ -18,10 +18,16 @@ PARAMS_2(_newUnit,_oldUnit); +//set showHUD based on new unit status: if ((_newUnit getVariable [QGVAR(isHandcuffed), false]) || {_newUnit getVariable [QGVAR(isSurrendering), false]}) then { TRACE_1("Player Change (showHUD false)",_newUnit); - showHUD false; + showHUD false; } else { TRACE_1("Player Change (showHUD true)",_newUnit); showHUD true; }; + +//If old player was escorting, stop +if (_oldUnit getVariable [QGVAR(isEscorting), false]) then { + _oldUnit setVariable [QGVAR(isEscorting), false, true]; +}; diff --git a/addons/captives/functions/fnc_handleVehicleChanged.sqf b/addons/captives/functions/fnc_handleVehicleChanged.sqf new file mode 100644 index 0000000000..74f966ecc3 --- /dev/null +++ b/addons/captives/functions/fnc_handleVehicleChanged.sqf @@ -0,0 +1,30 @@ +/* + * Author: commy2 + * Handles when a player's vehicle changes (supports scripted vehicle changes) + * + * Arguments: + * 0: unit + * 1: newVehicle + * + * Return Value: + * Nothing + * + * Example: + * [player, car] call ACE_captives_fnc_handleVehicleChanged + * + * Public: No + */ +#include "script_component.hpp" + +PARAMS_2(_unit,_vehicle); + +//When moved into a vehicle (action or scripted) +if ((vehicle _unit) != _unit) then { + if (_unit getVariable [QGVAR(isEscorting), false]) then { + _unit setVariable [QGVAR(isEscorting), false, true]; + }; + + if (_unit getVariable [QGVAR(isSurrendering), false]) then { + [_unit, false] call FUNC(surrender); + }; +}; diff --git a/addons/captives/functions/fnc_handleZeusDisplayChanged.sqf b/addons/captives/functions/fnc_handleZeusDisplayChanged.sqf new file mode 100644 index 0000000000..e328d410fa --- /dev/null +++ b/addons/captives/functions/fnc_handleZeusDisplayChanged.sqf @@ -0,0 +1,31 @@ +/* + * Author: PabstMirror + * Handles handles ZeusDisplayChanged event + * Need to reset showHUD after closing zeus + * + * Arguments: + * 0: Unit + * 1: Display is now open + * + * Return Value: + * Nothing + * + * Example: + * [bob1, false] call ACE_captives_fnc_handleZeusDisplayChanged + * + * Public: No + */ +#include "script_component.hpp" + +PARAMS_2(_unit,_zeusIsOpen); + +//set showHUD based on unit status: +if (!_zeusIsOpen) then { + if ((_unit getVariable [QGVAR(isHandcuffed), false]) || {_unit getVariable [QGVAR(isSurrendering), false]}) then { + TRACE_1("Player Change (showHUD false)",_newUnit); + showHUD false; + } else { + TRACE_1("Player Change (showHUD true)",_newUnit); + showHUD true; + }; +}; diff --git a/addons/captives/functions/fnc_setHandcuffed.sqf b/addons/captives/functions/fnc_setHandcuffed.sqf index 912b00662f..06906167e9 100644 --- a/addons/captives/functions/fnc_setHandcuffed.sqf +++ b/addons/captives/functions/fnc_setHandcuffed.sqf @@ -30,6 +30,9 @@ if (_state isEqualTo (_unit getVariable [QGVAR(isHandcuffed), false])) then { if (_state) then { _unit setVariable [QGVAR(isHandcuffed), true, true]; + if (_unit getVariable [QGVAR(isSurrendering), false]) then { //If surrendering, stop + [_unit, _false] call FUNC(surrender); + }; [_unit, QGVAR(Handcuffed), true] call EFUNC(common,setCaptivityStatus); _unit setVariable [QGVAR(CargoIndex), ((vehicle _unit) getCargoIndex _unit), true]; diff --git a/addons/captives/functions/fnc_surrender.sqf b/addons/captives/functions/fnc_surrender.sqf index 1f0e232926..25d5e6a008 100644 --- a/addons/captives/functions/fnc_surrender.sqf +++ b/addons/captives/functions/fnc_surrender.sqf @@ -30,12 +30,7 @@ if ((_unit getVariable [QGVAR(isSurrendering), false]) isEqualTo _state) then { if (_state) then { _unit setVariable [QGVAR(isSurrendering), true, true]; - [_unit, QGVAR(Surrendered), true] call EFUNC(common,setCaptivityStatus); - - if (_unit == ACE_player) then { - showHUD false; - }; - + // fix anim on mission start (should work on dedicated servers) [{ PARAMS_1(_unit); @@ -45,19 +40,27 @@ if (_state) then { }; }, [_unit], 0.01, 0] call EFUNC(common,waitAndExecute); - //PFEH - (TODO: move to event system?) + //Start up a pfeh to make sure the unit actualy goes into the animation + //Only change variables and captivity when they reach that state + //fixes vaulting to break animation [{ - EXPLODE_1_PVT((_this select 0),_unit); - if (_unit getVariable [QGVAR(isSurrendering), false]) then { - //If unit dies, gets knocked out, or is handcuffed then end surrender - if ((!alive _unit) || {_unit getVariable ["ACE_isUnconscious", false]} || {_unit getVariable [QGVAR(isHandcuffed), false]}) then { - [_unit, false] call FUNC(surrender); - [(_this select 1)] call CBA_fnc_removePerFrameHandler; - }; - } else { - [(_this select 1)] call cba_fnc_removePerFrameHandler; + PARAMS_2(_args,_pfID); + EXPLODE_2_PVT(_args,_unit,_maxTime); + + if (time > _maxTime) exitWith { + [_pfID] call CBA_fnc_removePerFrameHandler; + _unit setVariable [QGVAR(isSurrendering), false, true]; + ERROR("Surrender animation failed"); }; - }, 0.0, [_unit]] call CBA_fnc_addPerFrameHandler; + if ((animationState _unit) == "ACE_AmovPercMstpSsurWnonDnon") exitWith { + [_pfID] call CBA_fnc_removePerFrameHandler; + + if (_unit == ACE_player) then { + showHUD false; + }; + [_unit, QGVAR(Surrendered), true] call EFUNC(common,setCaptivityStatus); + }; + }, 0, [_unit, (time + 20)]] call CBA_fnc_addPerFrameHandler; } else { _unit setVariable [QGVAR(isSurrendering), false, true]; [_unit, QGVAR(Surrendered), false] call EFUNC(common,setCaptivityStatus);