diff --git a/addons/captives/CfgEventHandlers.hpp b/addons/captives/CfgEventHandlers.hpp index b8c182d1f6..07dbe45fb7 100644 --- a/addons/captives/CfgEventHandlers.hpp +++ b/addons/captives/CfgEventHandlers.hpp @@ -14,7 +14,7 @@ class Extended_PostInit_EventHandlers { class Extended_GetIn_EventHandlers { class All { class GVAR(AutoDetachCaptive) { - getIn = "if (local (_this select 2) && {(_this select 2) getVariable ['ACE_isEscorting', false]}) then {(_this select 2) setVariable ['ACE_isEscorting', false, true]}"; + getIn = QUOTE(_this call FUNC(handleGetIn)); }; }; }; @@ -32,16 +32,7 @@ class Extended_GetOut_EventHandlers { class Extended_Killed_EventHandlers { class CAManBase { class GVAR(AutoDetachCaptive) { - killed = "if ((_this select 0) getVariable ['ACE_isCaptive', false]) then {(_this select 0) setVariable ['ACE_isCaptive', false, true]}; if ((_this select 0) getVariable ['ACE_isEscorting', false]) then {(_this select 0) setVariable ['ACE_isEscorting', false, true]};"; - }; - }; -}; - -//handle captive and unconsciousness state -class Extended_Init_EventHandlers { - class CAManBase { - class GVAR(AutoDetachCaptive) { - init = "_this call ACE_Captives_fnc_initUnit"; + killed = QUOTE(_this call FUNC(handleKilled)); }; }; }; @@ -50,7 +41,7 @@ class Extended_Init_EventHandlers { class Extended_InitPost_EventHandlers { class CAManBase { class GVAR(InitPost) { - init = "if (local (_this select 0)) then {_this call ACE_Captives_fnc_initPost};"; + init = QUOTE(_this call FUNC(handleUnitInitPost)); }; }; }; diff --git a/addons/captives/XEH_preInit.sqf b/addons/captives/XEH_preInit.sqf index 505d57051e..5ff2379c0b 100644 --- a/addons/captives/XEH_preInit.sqf +++ b/addons/captives/XEH_preInit.sqf @@ -6,12 +6,13 @@ PREP(canFriskPerson); PREP(canLoadCaptive); PREP(canUnloadCaptive); PREP(escortCaptive); +PREP(handleGetIn); PREP(handleGetOut); +PREP(handleKilled); PREP(handleKnockedOut); PREP(handlePlayerChanged); PREP(handleWokeUp); -PREP(initPost); -PREP(initUnit); +PREP(handleUnitInitPost); PREP(loadCaptive); PREP(openFriskMenu); PREP(setCaptive); diff --git a/addons/captives/config.cpp b/addons/captives/config.cpp index 7e5c3382bb..7bef039e37 100644 --- a/addons/captives/config.cpp +++ b/addons/captives/config.cpp @@ -18,14 +18,14 @@ class CfgPatches { #include "CfgWeapons.hpp" -class ACE_Core_canInteractConditions { - class ACE_Interaction_isNotEscorting { - condition = "!(_player getVariable ['ACE_isEscorting', false])"; +class ACE_canInteractConditions { + class GVAR(isNotEscorting) { + condition = QUOTE(!(_player getVariable ['ACE_isEscorting', false])"; }; - class ACE_Interaction_isNotCaptive { + class GVAR(isNotCaptive) { condition = "!(_player getVariable ['ACE_isCaptive', false])"; }; - class ACE_Interaction_isNotSurrendering { + class GVAR(isNotSurrendering) { condition = "!(_player getVariable ['ACE_isSurrender', false])"; }; }; diff --git a/addons/captives/functions/fnc_handleGetIn.sqf b/addons/captives/functions/fnc_handleGetIn.sqf new file mode 100644 index 0000000000..dc0b5aa5af --- /dev/null +++ b/addons/captives/functions/fnc_handleGetIn.sqf @@ -0,0 +1,24 @@ +/* + * 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: + * - + * + * Public: No + */ +#include "script_component.hpp" + +PARAMS_3(_vehicle,_dontcare,_unit); + +if ((local _unit) && (_unit getVariable ["ACE_isEscorting", false])) then { + _unit setVariable ["ACE_isEscorting", false, true]; +}; diff --git a/addons/captives/functions/fnc_handleGetOut.sqf b/addons/captives/functions/fnc_handleGetOut.sqf index f734fa0177..82e6417eab 100644 --- a/addons/captives/functions/fnc_handleGetOut.sqf +++ b/addons/captives/functions/fnc_handleGetOut.sqf @@ -19,16 +19,16 @@ PARAMS_3(_vehicle,_dontcare,_unit); -if (!local _unit) exitWith {}; -if (!(_unit getVariable ["ACE_isCaptive", false])) exitWith {}; +if ((local _unit)&&(_unit getVariable ["ACE_isCaptive", false])) then { -private ["_cargoIndex"]; + private ["_cargoIndex"]; -_cargoIndex = _unit getVariable ["ACE_Captives_CargoIndex", -1]; + _cargoIndex = _unit getVariable ["ACE_Captives_CargoIndex", -1]; -//If captive was not "unloaded", then move them back into the vehicle. -if (_cargoIndex != -1) exitWith { - _unit moveInCargo [_vehicle, _cargoIndex]; -}; + //If captive was not "unloaded", then move them back into the vehicle. + if (_cargoIndex != -1) exitWith { + _unit moveInCargo [_vehicle, _cargoIndex]; + }; -[_unit, "ACE_AmovPercMstpScapWnonDnon", 2] call EFUNC(common,doAnimation); + [_unit, "ACE_AmovPercMstpScapWnonDnon", 2] call EFUNC(common,doAnimation); +}; \ No newline at end of file diff --git a/addons/captives/functions/fnc_handleKilled.sqf b/addons/captives/functions/fnc_handleKilled.sqf new file mode 100644 index 0000000000..2d476f662c --- /dev/null +++ b/addons/captives/functions/fnc_handleKilled.sqf @@ -0,0 +1,26 @@ +/* + * Author: PabstMirror + * Handles when a unit is kill. Reset captivity and escorting status when getting killed + * + * Arguments: + * 0: _oldUnit + * + * Return Value: + * None + * + * Example: + * - + * + * Public: No + */ +#include "script_component.hpp" + +PARAMS_1(_oldUnit); + +if (_oldUnit getVariable ["ACE_isCaptive", false]) then { + _oldUnit setVariable ["ACE_isCaptive", false, true]; +}; + +if (_oldUnit getVariable ["ACE_isEscorting", false]) then { + _oldUnit setVariable ["ACE_isEscorting", false, true] +}; diff --git a/addons/captives/functions/fnc_handleUnitInitPost.sqf b/addons/captives/functions/fnc_handleUnitInitPost.sqf new file mode 100644 index 0000000000..97362b1b96 --- /dev/null +++ b/addons/captives/functions/fnc_handleUnitInitPost.sqf @@ -0,0 +1,29 @@ +/* +* Author: commy2 +* handle captive and unconsciousness state and prevent grenades +* +* Arguments: +* 0: _unit +* +* Return Value: +* The return value +* +* Example: +* TODO +* +* Public: No +*/ +#include "script_component.hpp" + +PARAMS_1(_unit); + +// prevent players from throwing grenades +[_unit, "Throw", {(_this select 1) getVariable ["ACE_isCaptive", false]}, {}] call EFUNC(common,addActionEventhandler); + +if (local _unit) then { + // reset status on mission start + if (_unit getVariable ["ACE_isCaptive", false]) then { + _unit setVariable ["ACE_isCaptive", false]; + [_unit, true] call FUNC(setCaptive); + }; +}; diff --git a/addons/captives/functions/fnc_initPost.sqf b/addons/captives/functions/fnc_initPost.sqf deleted file mode 100644 index 8e777a9717..0000000000 --- a/addons/captives/functions/fnc_initPost.sqf +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Author: commy2 - * TODO - * - * Arguments: - * 0: _unit - * - * Return Value: - * The return value - * - * Example: - * TODO - * - * Public: No - */ -#include "script_component.hpp" - -PARAMS_1(_unit); - -// reset status on mission start -if (_unit getVariable ["ACE_isCaptive", false]) then { - _unit setVariable ["ACE_isCaptive", false]; - [_unit, true] call ACE_Captives_fnc_setCaptive; -}; diff --git a/addons/captives/functions/fnc_initUnit.sqf b/addons/captives/functions/fnc_initUnit.sqf deleted file mode 100644 index df9356ff2a..0000000000 --- a/addons/captives/functions/fnc_initUnit.sqf +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Author: commy2 - * TODO - * - * Arguments: - * 0: _unit - * - * Return Value: - * The return value - * - * Example: - * TODO - * - * Public: No - */ -#include "script_component.hpp" - -PARAMS_1(_unit); - - -// prevent players from throwing grenades -[_unit, "Throw", {(_this select 1) getVariable ["ACE_isCaptive", false]}, {}] call EFUNC(common,addActionEventhandler); diff --git a/addons/captives/functions/fnc_loadCaptive.sqf b/addons/captives/functions/fnc_loadCaptive.sqf index 05f87a20c6..680fee343c 100644 --- a/addons/captives/functions/fnc_loadCaptive.sqf +++ b/addons/captives/functions/fnc_loadCaptive.sqf @@ -31,6 +31,6 @@ if (isNull _vehicle) then { }; if ((!isNil "_target") && {!isNil "_vehicle"}) then { - _unit setVariable ["ACE_isEscorting", false]; + _unit setVariable ["ACE_isEscorting", false, true]; ["MoveInCaptive", [_target], [_target, _vehicle]] call EFUNC(common,targetEvent); };