added forceWalk and setCaptive events

This commit is contained in:
PabstMirror 2015-01-19 15:52:37 -06:00
parent 53cb63ec1d
commit cf59a3c2d4
6 changed files with 79 additions and 49 deletions

View File

@ -1,11 +1,6 @@
// by commy2 // by commy2
#include "script_component.hpp" #include "script_component.hpp"
PREP(setStatusEffect);
PREP(applyStatusEffects);
PREP(getStatusEffects);
// ACE Common Function // ACE Common Function
PREP(addActionEventHandler); PREP(addActionEventHandler);
PREP(addActionMenuEventHandler); PREP(addActionMenuEventHandler);
@ -264,4 +259,16 @@ PREP(makeCopyOfBody_F);
PREP(unloadPerson_F); PREP(unloadPerson_F);
PREP(cleanUpCopyOfBody_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; ADDON = true;

View File

@ -4,8 +4,6 @@
#define HASH_INDEX(hash,key) ((hash select 0) find key) #define HASH_INDEX(hash,key) ((hash select 0) find key)
xx3 = _this;
PARAMS_1(_unit); PARAMS_1(_unit);
DEFAULT_PARAM(1,_isJip, false); DEFAULT_PARAM(1,_isJip, false);
DEFAULT_PARAM(2,_isRespawn, false); DEFAULT_PARAM(2,_isRespawn, false);
@ -13,7 +11,9 @@ DEFAULT_PARAM(2,_isRespawn, false);
_unitEffects = _unit getVariable ["ACE_statusEffects", 0]; _unitEffects = _unit getVariable ["ACE_statusEffects", 0];
_statusHashList = missionNamespace getVariable ["ACE_statusHashList", []]; _statusHashList = missionNamespace getVariable ["ACE_statusHashList", []];
if (!local _unit) exitWith {}; if (!local _unit) exitWith {
["applyStatusEffects", _unit, _this] call FUNC(targetEvent);
};
if (_unitEffects == 0) exitWith {}; if (_unitEffects == 0) exitWith {};
if (!(VALIDHASH(_statusHashList))) exitWith {}; if (!(VALIDHASH(_statusHashList))) exitWith {};
@ -21,33 +21,32 @@ _effectTypeHash = HASHLIST_SELECT(_statusHashList, 0);
_removeOnJipHash = HASHLIST_SELECT(_statusHashList, 1); _removeOnJipHash = HASHLIST_SELECT(_statusHashList, 1);
_removeOnRespawn = HASHLIST_SELECT(_statusHashList, 2); _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 = []; _activeEffects = [];
_updated = false; _updated = false;
{ {
if (_x) then { if (_x) then {
TRACE_4("wtf", _isJip, _removeOnJipHash select 1 select _forEachIndex, _isRespawn, _removeOnRespawn select 1 select _forEachIndex); 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 { if ((_isJip && {(_removeOnJipHash select 1) select _forEachIndex}) || {_isRespawn && {(_removeOnRespawn select 1) select _forEachIndex}}) then {
_updated = true; _updated = true;
_unitStatusBoolArray set [_forEachIndex, false]; _unitStatusBoolArray set [_forEachIndex, false];
} else { } else {
_effectType = (_effectTypeHash select 1) select _forEachIndex; _effectType = (_effectTypeHash select 1) select _forEachIndex;
if (!(_effectType in _activeEffects)) then { if (!(_effectType in _activeEffects)) then {
_activeEffects pushBack _effectType; _activeEffects pushBack _effectType;
}; };
}; };
}; };
} forEach _unitStatusBoolArray; } forEach _unitStatusBoolArray;
TRACE_2("Updaing unit?",_unit,_updated); TRACE_2("Updaing unit",_unit,_updated);
if (_updated) then { if (_updated) then {
_unitStatusNumber = _unitStatusBoolArray call EFUNC(common,toBitmask); _unitStatusNumber = _unitStatusBoolArray call FUNC(toBitmask);
_unit setVariable ["ACE_statusEffects", _unitStatusNumber, true]; _unit setVariable ["ACE_statusEffects", _unitStatusNumber, true];
}; };
TRACE_3("Updaing All Effects",_unit,_allEffects,_activeEffects); 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; } forEach _allEffects;

View File

@ -13,14 +13,14 @@ _statusHashList = missionNamespace getVariable ["ACE_statusHashList", []];
if (!(VALIDHASH(_statusHashList))) exitWith {[]}; if (!(VALIDHASH(_statusHashList))) exitWith {[]};
_effectTypeHash = HASHLIST_SELECT(_statusHashList, 0); _effectTypeHash = HASHLIST_SELECT(_statusHashList, 0);
_unitStatusBoolArray = [_unitEffects] call EFUNC(common,binarizeNumber); //create bool array _unitStatusBoolArray = [_unitEffects] call FUNC(binarizeNumber); //create bool array
_returnValue = []; _returnValue = [];
{ {
if ((_unitStatusBoolArray select _forEachIndex) && {((_effectTypeHash select 1) select _forEachIndex) == _effectType}) then { if ((_unitStatusBoolArray select _forEachIndex) && {((_effectTypeHash select 1) select _forEachIndex) == _effectType}) then {
_returnValue pushBack _x; _returnValue pushBack _x;
}; };
} forEach (_effectTypeHash select 0); } forEach (_effectTypeHash select 0);
TRACE_3("Effects:", _unit, _effectType, _returnValue); TRACE_3("Effects:", _unit, _effectType, _returnValue);

View File

@ -2,6 +2,9 @@
#include "script_component.hpp" #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) #define HASH_INDEX(hash,key) ((hash select 0) find key)
PARAMS_4(_unit,_effectName,_effectType,_isEnabled); PARAMS_4(_unit,_effectName,_effectType,_isEnabled);
@ -12,37 +15,39 @@ _unitEffects = _unit getVariable ["ACE_statusEffects", 0];
_statusHashList = missionNamespace getVariable ["ACE_statusHashList", []]; _statusHashList = missionNamespace getVariable ["ACE_statusHashList", []];
if (!(VALIDHASH(_statusHashList))) then { if (!(VALIDHASH(_statusHashList))) then {
_statusHashList = HASHLIST_CREATELIST([]); _statusHashList = HASHLIST_CREATELIST([]);
HASHLIST_PUSH(_statusHashList, HASHLIST_CREATEHASH(_statusHashList)); HASHLIST_PUSH(_statusHashList, HASHLIST_CREATEHASH(_statusHashList));
HASHLIST_PUSH(_statusHashList, HASHLIST_CREATEHASH(_statusHashList)); HASHLIST_PUSH(_statusHashList, HASHLIST_CREATEHASH(_statusHashList));
HASHLIST_PUSH(_statusHashList, HASHLIST_CREATEHASH(_statusHashList)); HASHLIST_PUSH(_statusHashList, HASHLIST_CREATEHASH(_statusHashList));
}; };
_effectTypeHash = HASHLIST_SELECT(_statusHashList, 0); _effectTypeHash = HASHLIST_SELECT(_statusHashList, 0);
_removeOnJipHash = HASHLIST_SELECT(_statusHashList, 1); _removeOnJipHash = HASHLIST_SELECT(_statusHashList, 1);
_removeOnRespawnHash = HASHLIST_SELECT(_statusHashList, 2); _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 { missionNamespace setVariable ["ACE_statusHashList", _statusHashList];
// If effect name isn't in hashList publicVariable "ACE_statusHashList";
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";
}; };
_effectIndex = HASH_INDEX(_statusHashList, _effectName); _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 _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 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);
};

View File

@ -0,0 +1,7 @@
#define DEBUG_MODE_FULL
#include "script_component.hpp"
PARAMS_2(_unit,_isEnabled);
_unit forceWalk _isEnabled;

View File

@ -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;
};