2015-02-08 12:18:08 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal
|
|
|
|
* Sets a unit in the unconscious state.
|
2015-02-08 09:25:03 +00:00
|
|
|
*
|
2015-02-08 12:18:08 +00:00
|
|
|
* Arguments:
|
|
|
|
* 0: The unit that will be put in an unconscious state <OBJECT>
|
2015-04-02 20:55:23 +00:00
|
|
|
* 1: Set unconsciouns <BOOL> <OPTIONAL>
|
|
|
|
* 2: Minimum unconscious time <NUMBER> <OPTIONAL>
|
2015-02-08 12:18:08 +00:00
|
|
|
*
|
|
|
|
* ReturnValue:
|
2015-02-24 21:09:31 +00:00
|
|
|
* nil
|
2015-02-08 12:18:08 +00:00
|
|
|
*
|
|
|
|
* Public: yes
|
2015-02-08 09:25:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-04-02 20:55:23 +00:00
|
|
|
#define DEFAULT_DELAY (round(random(10)+5))
|
|
|
|
|
2015-02-28 11:05:22 +00:00
|
|
|
private ["_unit", "_set", "_animState", "_originalPos", "_captiveSwitch", "_startingTime","_minWaitingTime"];
|
2015-02-08 09:25:03 +00:00
|
|
|
_unit = _this select 0;
|
2015-02-28 22:35:53 +00:00
|
|
|
_set = if (count _this > 1) then {_this select 1} else {true};
|
2015-04-02 20:55:23 +00:00
|
|
|
_minWaitingTime = if (count _this > 2) then {_this select 2} else {DEFAULT_DELAY};
|
2015-02-28 11:05:22 +00:00
|
|
|
|
|
|
|
if !(_set) exitwith {
|
|
|
|
_unit setvariable ["ACE_isUnconscious", false,true];
|
|
|
|
};
|
2015-02-08 09:25:03 +00:00
|
|
|
|
|
|
|
if !(!(isNull _unit) && {(_unit isKindOf "CaManBase") && ([_unit] call EFUNC(common,isAwake))}) exitwith{};
|
|
|
|
|
|
|
|
if (!local _unit) exitwith {
|
2015-03-13 05:45:12 +00:00
|
|
|
[[_unit], QUOTE(DFUNC(setUnconscious)), _unit, false] call EFUNC(common,execRemoteFnc); /* TODO Replace by event system */
|
2015-02-08 09:25:03 +00:00
|
|
|
};
|
|
|
|
|
2015-02-28 22:34:14 +00:00
|
|
|
_unit setvariable ["ACE_isUnconscious", true, true];
|
2015-02-08 09:25:03 +00:00
|
|
|
_unit setUnconscious true;
|
|
|
|
|
2015-03-17 07:03:11 +00:00
|
|
|
if (_unit == ACE_player) then {
|
|
|
|
if (visibleMap) then {openMap false};
|
|
|
|
closeDialog 0;
|
|
|
|
};
|
|
|
|
|
2015-02-08 09:25:03 +00:00
|
|
|
// If a unit has the launcher out, it will sometimes start selecting the primairy weapon while unconscious,
|
|
|
|
// therefor we force it to select the primairy weapon before going unconscious
|
|
|
|
if ((vehicle _unit) isKindOf "StaticWeapon") then {
|
|
|
|
moveOut _unit;
|
|
|
|
unassignVehicle _unit;
|
|
|
|
//_unit action ["eject", vehicle _unit];
|
|
|
|
};
|
|
|
|
if (animationState _unit in ["ladderriflestatic","laddercivilstatic"]) then {
|
|
|
|
_unit action ["ladderOff", (nearestBuilding _unit)];
|
|
|
|
};
|
|
|
|
if (vehicle _unit == _unit) then {
|
|
|
|
if (primaryWeapon _unit == "") then {
|
|
|
|
_unit addWeapon "ACE_fakeWeapon";
|
|
|
|
};
|
|
|
|
_unit selectWeapon (primaryWeapon _unit);
|
|
|
|
_unit switchMove "";
|
|
|
|
_unit playmoveNow "";
|
|
|
|
};
|
|
|
|
|
|
|
|
// We are storing the current animation, so we can use it later on when waking the unit up inside a vehicle
|
|
|
|
_animState = animationState _unit;
|
|
|
|
_originalPos = unitPos _unit;
|
|
|
|
|
2015-02-28 22:34:14 +00:00
|
|
|
_unit setUnitPos "DOWN";
|
|
|
|
[_unit, true] call EFUNC(common,disableAI);
|
2015-02-08 09:25:03 +00:00
|
|
|
|
|
|
|
// So the AI does not get stuck, we are moving the unit to a temp group on its own.
|
2015-02-14 19:29:07 +00:00
|
|
|
[_unit, true, "ACE_isUnconscious", side group _unit] call EFUNC(common,switchToGroupSide);
|
2015-02-08 09:25:03 +00:00
|
|
|
|
2015-03-10 15:35:00 +00:00
|
|
|
[_unit, QGVAR(unconscious), true] call EFUNC(common,setCaptivityStatus);
|
2015-02-08 09:25:03 +00:00
|
|
|
[_unit, [_unit] call EFUNC(common,getDeathAnim), 1, true] call EFUNC(common,doAnimation);
|
|
|
|
|
|
|
|
_startingTime = time;
|
|
|
|
|
|
|
|
[{
|
2015-03-10 15:35:00 +00:00
|
|
|
private ["_unit", "_vehicleOfUnit","_minWaitingTime", "_oldAnimation", "_captiveSwitch", "_hasMovedOut"];
|
2015-02-08 09:25:03 +00:00
|
|
|
_args = _this select 0;
|
|
|
|
_unit = _args select 0;
|
|
|
|
_oldAnimation = _args select 1;
|
2015-03-10 15:35:00 +00:00
|
|
|
_originalPos = _args select 2;
|
|
|
|
_startingTime = _args select 3;
|
|
|
|
_minWaitingTime = _args select 4;
|
|
|
|
_hasMovedOut = _args select 5;
|
2015-04-09 18:13:46 +00:00
|
|
|
|
2015-02-08 09:25:03 +00:00
|
|
|
if (!alive _unit) exitwith {
|
|
|
|
[(_this select 1)] call cba_fnc_removePerFrameHandler;
|
|
|
|
};
|
|
|
|
|
|
|
|
// In case the unit is no longer in an unconscious state, we are going to check if we can already reset the animation
|
|
|
|
if !(_unit getvariable ["ACE_isUnconscious",false]) exitwith {
|
2015-04-03 18:07:39 +00:00
|
|
|
|
2015-02-08 09:25:03 +00:00
|
|
|
// TODO, handle this with carry instead, so we can remove the PFH here.
|
|
|
|
// Wait until the unit isn't being carried anymore, so we won't end up with wierd animations
|
2015-04-03 20:45:16 +00:00
|
|
|
if !(([_unit] call FUNC(isBeingCarried)) || ([_unit] call FUNC(isBeingDragged))) then {
|
2015-02-08 09:25:03 +00:00
|
|
|
if (vehicle _unit == _unit) then {
|
2015-04-04 18:21:06 +00:00
|
|
|
if (animationState _unit == "AinjPpneMstpSnonWrflDnon") then {
|
|
|
|
[_unit,"AinjPpneMstpSnonWrflDnon_rolltofront", 2] call EFUNC(common,doAnimation);
|
|
|
|
[_unit,"amovppnemstpsnonwnondnon", 1] call EFUNC(common,doAnimation);
|
|
|
|
} else {
|
|
|
|
[_unit,"amovppnemstpsnonwnondnon", 2] call EFUNC(common,doAnimation);
|
|
|
|
};
|
2015-02-08 09:25:03 +00:00
|
|
|
} else {
|
|
|
|
// Switch to the units original animation, assuming
|
|
|
|
// TODO: what if the unit switched vehicle?
|
2015-04-03 18:07:39 +00:00
|
|
|
[_unit, _oldAnimation, 2] call EFUNC(common,doAnimation);
|
2015-02-08 09:25:03 +00:00
|
|
|
};
|
|
|
|
// EXIT PFH
|
|
|
|
[(_this select 1)] call cba_fnc_removePerFrameHandler;
|
2015-04-03 20:45:16 +00:00
|
|
|
};
|
2015-02-28 11:05:22 +00:00
|
|
|
if (!_hasMovedOut) then {
|
2015-02-08 09:25:03 +00:00
|
|
|
// Reset the unit back to the previous captive state.
|
2015-03-10 15:35:00 +00:00
|
|
|
[_unit, QGVAR(unconscious), false] call EFUNC(common,setCaptivityStatus);
|
2015-03-24 21:10:41 +00:00
|
|
|
|
2015-02-08 09:25:03 +00:00
|
|
|
// Swhich the unit back to its original group
|
2015-02-14 19:29:07 +00:00
|
|
|
[_unit, false, "ACE_isUnconscious", side group _unit] call EFUNC(common,switchToGroupSide);
|
2015-02-08 09:25:03 +00:00
|
|
|
|
2015-04-10 20:02:36 +00:00
|
|
|
[_unit, false] call EFUNC(common,disableAI);
|
2015-02-28 22:34:14 +00:00
|
|
|
_unit setUnitPos _originalPos; // This is not position but stance (DOWN, MIDDLE, UP)
|
|
|
|
|
2015-02-28 11:05:22 +00:00
|
|
|
_unit setUnconscious false;
|
2015-03-24 21:10:41 +00:00
|
|
|
["medical_onUnconscious", [_unit, false]] call EFUNC(common,globalEvent);
|
2015-02-28 11:05:22 +00:00
|
|
|
// ensure this statement runs only once
|
2015-04-03 18:11:20 +00:00
|
|
|
_args set [5, true];
|
2015-02-28 11:05:22 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Ensure we are waiting at least a minimum period before checking if we can wake up the unit again, allows for temp knock outs
|
|
|
|
if ((time - _startingTime) >= _minWaitingTime) exitwith {
|
2015-02-08 09:25:03 +00:00
|
|
|
|
2015-02-28 11:05:22 +00:00
|
|
|
if (!([_unit] call FUNC(getUnconsciousCondition))) then {
|
2015-02-08 09:25:03 +00:00
|
|
|
_unit setvariable ["ACE_isUnconscious", false, true];
|
|
|
|
};
|
|
|
|
};
|
2015-03-10 15:35:00 +00:00
|
|
|
}, 0.1, [_unit,_animState, _originalPos, _startingTime, _minWaitingTime, false] ] call CBA_fnc_addPerFrameHandler;
|
2015-02-08 09:25:03 +00:00
|
|
|
|
2015-03-24 21:10:41 +00:00
|
|
|
["medical_onUnconscious", [_unit, true]] call EFUNC(common,globalEvent);
|