ACE3/addons/common/functions/fnc_setForceWalkStatus.sqf

54 lines
1.8 KiB
Plaintext
Raw Normal View History

/*
2015-01-11 18:20:14 +00:00
Name: FUNC(setForceWalkStatus)
Author: Pabst Mirror (from captivity by commy2)
Description:
Sets the forceWalk status of an unit. This allows the handling of more than one reason to set forceWalk.
Unit will force walk until all reasons are removed.
Parameters:
0: OBJECT - Unit
1: STRING - Reason for forcing walking
2: BOOL - Is the reason still valid. True to force walk, false to remove restriction.
Returns:
None
Example:
[ACE_Player, "BrokenLeg", true] call FUNC(setForceWalkStatus)
*/
2015-01-13 19:56:02 +00:00
#include "script_component.hpp"
private ["_unit", "_reason", "_status", "_forceWalkReasons", "_unitForceWalkReasons", "_forceWalkReasonsBooleans", "_bitmaskNumber"];
_unit = _this select 0;
_reason = _this select 1;
_status = _this select 2;
_forceWalkReasons = missionNamespace getVariable ["ACE_forceWalkReasons", []];
// register new reason (these reasons are shared publicly, since units can change ownership, but keep their forceWalk status)
if !(_reason in _forceWalkReasons) then {
_forceWalkReasons pushBack _reason;
ACE_forceWalkReasons = _forceWalkReasons;
publicVariable "ACE_forceWalkReasons";
};
// get reasons why the unit is forceWalking already and update to the new status
2015-01-11 18:20:14 +00:00
_unitForceWalkReasons = [_unit] call FUNC(getForceWalkStatus);
_forceWalkReasonsBooleans = [];
{
_forceWalkReasonsBooleans set [_forEachIndex, (_forceWalkReasons select _forEachIndex) in _unitForceWalkReasons];
} forEach _forceWalkReasons;
_forceWalkReasonsBooleans set [_forceWalkReasons find _reason, _status];
2015-01-11 18:20:14 +00:00
_bitmaskNumber = _forceWalkReasonsBooleans call FUNC(toBitmask);
_unit setVariable ["ACE_forceWalkStatusNumber", _bitmaskNumber, true];
// actually apply the forceWalk command globaly
2015-04-29 22:53:49 +00:00
[[_unit], QUOTE(FUNC(applyForceWalkStatus)), 2] call FUNC(execRemoteFnc);