diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index ddb6c742c8..807f09c006 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -1,11 +1,6 @@ // by commy2 #include "script_component.hpp" -PREP(setStatusEffect); -PREP(applyStatusEffects); -PREP(getStatusEffects); - - // ACE Common Function PREP(addActionEventHandler); PREP(addActionMenuEventHandler); @@ -264,4 +259,16 @@ PREP(makeCopyOfBody_F); PREP(unloadPerson_F); PREP(cleanUpCopyOfBody_F); +PREP(setStatusEffect); +PREP(applyStatusEffects); +PREP(getStatusEffects); +PREP(statusEffectSetCaptive); +PREP(statusEffectForceWalk); + + +["setCaptive", {_this call FUNC(statusEffectSetCaptive)}] call FUNC(addEventHandler); +["forceWalk", {_this call FUNC(statusEffectForceWalk)}] call FUNC(addEventHandler); + + + ADDON = true; diff --git a/addons/common/functions/fnc_applyStatusEffects.sqf b/addons/common/functions/fnc_applyStatusEffects.sqf index 04f9368e85..7c8805dffc 100644 --- a/addons/common/functions/fnc_applyStatusEffects.sqf +++ b/addons/common/functions/fnc_applyStatusEffects.sqf @@ -4,8 +4,6 @@ #define HASH_INDEX(hash,key) ((hash select 0) find key) -xx3 = _this; - PARAMS_1(_unit); DEFAULT_PARAM(1,_isJip, false); DEFAULT_PARAM(2,_isRespawn, false); @@ -13,7 +11,9 @@ DEFAULT_PARAM(2,_isRespawn, false); _unitEffects = _unit getVariable ["ACE_statusEffects", 0]; _statusHashList = missionNamespace getVariable ["ACE_statusHashList", []]; -if (!local _unit) exitWith {}; +if (!local _unit) exitWith { + ["applyStatusEffects", _unit, _this] call FUNC(targetEvent); +}; if (_unitEffects == 0) exitWith {}; if (!(VALIDHASH(_statusHashList))) exitWith {}; @@ -21,33 +21,32 @@ _effectTypeHash = HASHLIST_SELECT(_statusHashList, 0); _removeOnJipHash = HASHLIST_SELECT(_statusHashList, 1); _removeOnRespawn = HASHLIST_SELECT(_statusHashList, 2); -_unitStatusBoolArray = [_unitEffects, (count (_effectTypeHash select 0))] call EFUNC(common,binarizeNumber); +_unitStatusBoolArray = [_unitEffects, (count (_effectTypeHash select 0))] call FUNC(binarizeNumber); -_allEffects = [(_effectTypeHash select 1)] call EFUNC(common,uniqueElementsOnly); +_allEffects = [(_effectTypeHash select 1)] call FUNC(uniqueElementsOnly); _activeEffects = []; _updated = false; { - if (_x) then { - TRACE_4("wtf", _isJip, _removeOnJipHash select 1 select _forEachIndex, _isRespawn, _removeOnRespawn select 1 select _forEachIndex); - if ((_isJip && {(_removeOnJipHash select 1) select _forEachIndex}) || {_isRespawn && {(_removeOnRespawn select 1) select _forEachIndex}}) then { - _updated = true; - _unitStatusBoolArray set [_forEachIndex, false]; - } else { - _effectType = (_effectTypeHash select 1) select _forEachIndex; - if (!(_effectType in _activeEffects)) then { - _activeEffects pushBack _effectType; - }; - }; - }; + if (_x) then { + TRACE_4("wtf", _isJip, _removeOnJipHash select 1 select _forEachIndex, _isRespawn, _removeOnRespawn select 1 select _forEachIndex); + if ((_isJip && {(_removeOnJipHash select 1) select _forEachIndex}) || {_isRespawn && {(_removeOnRespawn select 1) select _forEachIndex}}) then { + _updated = true; + _unitStatusBoolArray set [_forEachIndex, false]; + } else { + _effectType = (_effectTypeHash select 1) select _forEachIndex; + if (!(_effectType in _activeEffects)) then { + _activeEffects pushBack _effectType; + }; + }; + }; } forEach _unitStatusBoolArray; -TRACE_2("Updaing unit?",_unit,_updated); +TRACE_2("Updaing unit",_unit,_updated); if (_updated) then { - _unitStatusNumber = _unitStatusBoolArray call EFUNC(common,toBitmask); - _unit setVariable ["ACE_statusEffects", _unitStatusNumber, true]; + _unitStatusNumber = _unitStatusBoolArray call FUNC(toBitmask); + _unit setVariable ["ACE_statusEffects", _unitStatusNumber, true]; }; TRACE_3("Updaing All Effects",_unit,_allEffects,_activeEffects); { - [_x, [_unit, (_x in _activeEffects)]] call EFUNC(common,localEvent); + [_x, [_unit, (_x in _activeEffects)]] call FUNC(localEvent); } forEach _allEffects; - diff --git a/addons/common/functions/fnc_getStatusEffects.sqf b/addons/common/functions/fnc_getStatusEffects.sqf index 074b8ccb4d..cd9b118394 100644 --- a/addons/common/functions/fnc_getStatusEffects.sqf +++ b/addons/common/functions/fnc_getStatusEffects.sqf @@ -13,14 +13,14 @@ _statusHashList = missionNamespace getVariable ["ACE_statusHashList", []]; if (!(VALIDHASH(_statusHashList))) exitWith {[]}; _effectTypeHash = HASHLIST_SELECT(_statusHashList, 0); -_unitStatusBoolArray = [_unitEffects] call EFUNC(common,binarizeNumber); //create bool array +_unitStatusBoolArray = [_unitEffects] call FUNC(binarizeNumber); //create bool array _returnValue = []; { - if ((_unitStatusBoolArray select _forEachIndex) && {((_effectTypeHash select 1) select _forEachIndex) == _effectType}) then { - _returnValue pushBack _x; - }; + if ((_unitStatusBoolArray select _forEachIndex) && {((_effectTypeHash select 1) select _forEachIndex) == _effectType}) then { + _returnValue pushBack _x; + }; } forEach (_effectTypeHash select 0); TRACE_3("Effects:", _unit, _effectType, _returnValue); diff --git a/addons/common/functions/fnc_setStatusEffect.sqf b/addons/common/functions/fnc_setStatusEffect.sqf index 7bb8e263d0..64fe5f5d56 100644 --- a/addons/common/functions/fnc_setStatusEffect.sqf +++ b/addons/common/functions/fnc_setStatusEffect.sqf @@ -2,6 +2,9 @@ #include "script_component.hpp" +//[this, "fattie", "forceWalk", true, false, false] call ace_common_fnc_setStatusEffect; +//[this, "carrying jerrycan", "forceWalk", true, false, false] call ace_common_fnc_setStatusEffect; + #define HASH_INDEX(hash,key) ((hash select 0) find key) PARAMS_4(_unit,_effectName,_effectType,_isEnabled); @@ -12,37 +15,39 @@ _unitEffects = _unit getVariable ["ACE_statusEffects", 0]; _statusHashList = missionNamespace getVariable ["ACE_statusHashList", []]; if (!(VALIDHASH(_statusHashList))) then { - _statusHashList = HASHLIST_CREATELIST([]); - HASHLIST_PUSH(_statusHashList, HASHLIST_CREATEHASH(_statusHashList)); - HASHLIST_PUSH(_statusHashList, HASHLIST_CREATEHASH(_statusHashList)); - HASHLIST_PUSH(_statusHashList, HASHLIST_CREATEHASH(_statusHashList)); + _statusHashList = HASHLIST_CREATELIST([]); + HASHLIST_PUSH(_statusHashList, HASHLIST_CREATEHASH(_statusHashList)); + HASHLIST_PUSH(_statusHashList, HASHLIST_CREATEHASH(_statusHashList)); + HASHLIST_PUSH(_statusHashList, HASHLIST_CREATEHASH(_statusHashList)); }; _effectTypeHash = HASHLIST_SELECT(_statusHashList, 0); _removeOnJipHash = HASHLIST_SELECT(_statusHashList, 1); _removeOnRespawnHash = HASHLIST_SELECT(_statusHashList, 2); +if ((HASH_INDEX(_statusHashList,_effectName)) == -1) then {// If effect name isn't in hashList + HASH_SET(_effectTypeHash,_effectName,_effectType); + HASHLIST_SET(_statusHashList, 0, _effectTypeHash); + HASH_SET(_removeOnJipHash,_effectName,_removeOnJIP); + HASHLIST_SET(_statusHashList, 1, _removeOnJipHash); + HASH_SET(_removeOnRespawnHash,_effectName,_removeOnRespawn); + HASHLIST_SET(_statusHashList, 2, _removeOnRespawnHash); -if ((!HASH_HASKEY(_effectTypeHash,_effectType)) || {!HASH_HASKEY(_effectTypeHash,_effectType)}) then { - // If effect name isn't in hashList - HASH_SET(_effectTypeHash,_effectName,_effectType); - HASHLIST_SET(_statusHashList, 0, _effectTypeHash); - HASH_SET(_removeOnJipHash,_effectName,_removeOnJIP); - HASHLIST_SET(_statusHashList, 1, _removeOnJipHash); - HASH_SET(_removeOnRespawnHash,_effectName,_removeOnRespawn); - HASHLIST_SET(_statusHashList, 2, _removeOnRespawnHash); - - missionNamespace setVariable ["ACE_statusHashList", _statusHashList]; - publicVariable "ACE_statusHashList"; + missionNamespace setVariable ["ACE_statusHashList", _statusHashList]; + publicVariable "ACE_statusHashList"; }; _effectIndex = HASH_INDEX(_statusHashList, _effectName); -_unitStatusBoolArray = [_unitEffects, (count (_effectTypeHash select 0))] call EFUNC(common,binarizeNumber); //create bool array +_unitStatusBoolArray = [_unitEffects, (count (_effectTypeHash select 0))] call FUNC(binarizeNumber); //create bool array _unitStatusBoolArray set [_effectIndex, _isEnabled]; //set new status -_unitStatusNumber = _unitStatusBoolArray call EFUNC(common,toBitmask); +_unitStatusNumber = _unitStatusBoolArray call FUNC(toBitmask); _unit setVariable ["ACE_statusEffects", _unitStatusNumber, true]; -[_unit, false, false] call EFUNC(common,applyStatusEffects); +if (local _unit) then { + [_unit] call FUNC(applyStatusEffects); +} else { + ["applyStatusEffects", _unit, [_unit]] call FUNC(targetEvent); +}; diff --git a/addons/common/functions/fnc_statusEffectForceWalk.sqf b/addons/common/functions/fnc_statusEffectForceWalk.sqf new file mode 100644 index 0000000000..6095472b50 --- /dev/null +++ b/addons/common/functions/fnc_statusEffectForceWalk.sqf @@ -0,0 +1,7 @@ +#define DEBUG_MODE_FULL + +#include "script_component.hpp" + +PARAMS_2(_unit,_isEnabled); + +_unit forceWalk _isEnabled; diff --git a/addons/common/functions/fnc_statusEffectSetCaptive.sqf b/addons/common/functions/fnc_statusEffectSetCaptive.sqf new file mode 100644 index 0000000000..8051c00434 --- /dev/null +++ b/addons/common/functions/fnc_statusEffectSetCaptive.sqf @@ -0,0 +1,12 @@ +#define DEBUG_MODE_FULL + +#include "script_component.hpp" + +PARAMS_2(_unit,_isEnabled); +DEFAULT_PARAM(2,_isGlobal, false); + +if (!_isGlobal) exitWith { + ["setCaptive", [_unit, _isEnabled, true]] call FUNC(globalEvent); +} else { + _unit setCaptive _isEnabled; +}; \ No newline at end of file