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-08-22 17:47:23 +00:00
|
|
|
* 1: Set unconsciouns <BOOL> (default: true)
|
|
|
|
* 2: Minimum unconscious ACE_time <NUMBER> (default: (round(random(10)+5)))
|
|
|
|
* 3: Force AI Unconscious (skip random death chance) <BOOL> (default: false)
|
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
|
|
|
*
|
2015-07-12 15:25:00 +00:00
|
|
|
* Example:
|
|
|
|
* [bob, true] call ace_medical_fnc_setUnconscious;
|
|
|
|
*
|
2015-02-08 12:18:08 +00:00
|
|
|
* Public: yes
|
2015-02-08 09:25:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-08-22 17:47:23 +00:00
|
|
|
#define DEFAULT_DELAY (round(random(10)+5))
|
2015-04-02 20:55:23 +00:00
|
|
|
|
2015-09-26 17:30:13 +00:00
|
|
|
// only run this after the settings are initialized
|
|
|
|
if !(EGVAR(common,settingsInitFinished)) exitWith {
|
|
|
|
EGVAR(common,runAtSettingsInitialized) pushBack [FUNC(setUnconscious), _this];
|
|
|
|
};
|
|
|
|
|
2015-08-22 17:47:23 +00:00
|
|
|
private ["_animState", "_originalPos", "_startingTime", "_isDead"];
|
|
|
|
params ["_unit", ["_set", true], ["_minWaitingTime", DEFAULT_DELAY], ["_force", false]];
|
2015-02-28 11:05:22 +00:00
|
|
|
|
2015-04-23 09:31:27 +00:00
|
|
|
// No change, fuck off. (why is there no xor?)
|
|
|
|
if (_set isEqualTo (_unit getVariable ["ACE_isUnconscious", false])) exitWith {};
|
|
|
|
|
2015-02-28 11:05:22 +00:00
|
|
|
if !(_set) exitwith {
|
2015-04-17 18:24:05 +00:00
|
|
|
_unit setvariable ["ACE_isUnconscious", false, true];
|
2015-02-28 11:05:22 +00:00
|
|
|
};
|
2015-02-08 09:25:03 +00:00
|
|
|
|
2015-04-26 14:47:36 +00:00
|
|
|
if !(!(isNull _unit) && {(_unit isKindOf "CAManBase") && ([_unit] call EFUNC(common,isAwake))}) exitwith{};
|
2015-02-08 09:25:03 +00:00
|
|
|
|
|
|
|
if (!local _unit) exitwith {
|
2015-05-16 13:19:42 +00:00
|
|
|
[[_unit, _set, _minWaitingTime, _force], 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};
|
2015-04-20 20:22:09 +00:00
|
|
|
while {dialog} do {
|
|
|
|
closeDialog 0;
|
|
|
|
};
|
2015-03-17 07:03:11 +00:00
|
|
|
};
|
|
|
|
|
2015-04-17 18:24:05 +00:00
|
|
|
// if we have unconsciousness for AI disabled, we will kill the unit instead
|
2015-06-05 20:43:09 +00:00
|
|
|
_isDead = false;
|
2015-06-08 18:12:16 +00:00
|
|
|
if (!([_unit, GVAR(remoteControlledAI)] call EFUNC(common,isPlayer)) && !_force) then {
|
2015-04-30 20:16:45 +00:00
|
|
|
_enableUncon = _unit getVariable [QGVAR(enableUnconsciousnessAI), GVAR(enableUnconsciousnessAI)];
|
2015-06-05 20:43:09 +00:00
|
|
|
if (_enableUncon == 0 or {_enableUncon == 1 and (random 1) < 0.5}) then {
|
2015-04-30 20:16:45 +00:00
|
|
|
[_unit, true] call FUNC(setDead);
|
2015-06-05 20:43:09 +00:00
|
|
|
_isDead = true;
|
2015-04-30 20:16:45 +00:00
|
|
|
};
|
2015-04-17 18:24:05 +00:00
|
|
|
};
|
2015-06-05 20:43:09 +00:00
|
|
|
if (_isDead) exitWith {};
|
2015-04-17 18:24:05 +00:00
|
|
|
|
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 {
|
2015-04-30 23:35:50 +00:00
|
|
|
[_unit] call EFUNC(common,unloadPerson);
|
2015-02-08 09:25:03 +00:00
|
|
|
};
|
|
|
|
if (animationState _unit in ["ladderriflestatic","laddercivilstatic"]) then {
|
|
|
|
_unit action ["ladderOff", (nearestBuilding _unit)];
|
|
|
|
};
|
|
|
|
if (vehicle _unit == _unit) then {
|
|
|
|
if (primaryWeapon _unit == "") then {
|
2015-04-13 08:46:42 +00:00
|
|
|
_unit addWeapon "ACE_FakePrimaryWeapon";
|
2015-02-08 09:25:03 +00:00
|
|
|
};
|
|
|
|
_unit selectWeapon (primaryWeapon _unit);
|
|
|
|
};
|
|
|
|
|
|
|
|
// We are storing the current animation, so we can use it later on when waking the unit up inside a vehicle
|
2015-05-01 20:03:05 +00:00
|
|
|
if (vehicle _unit != _unit) then {
|
|
|
|
_unit setVariable [QGVAR(vehicleAwakeAnim), [(vehicle _unit), (animationState _unit)]];
|
|
|
|
};
|
|
|
|
|
|
|
|
//Save current stance:
|
2015-02-08 09:25:03 +00:00
|
|
|
_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-04-13 05:32:07 +00:00
|
|
|
//Unconscious units shouldn't be put in another group #527:
|
2015-04-20 19:37:30 +00:00
|
|
|
if (GVAR(moveUnitsFromGroupOnUnconscious)) then {
|
|
|
|
[_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-04-30 20:17:25 +00:00
|
|
|
_anim = [_unit] call EFUNC(common,getDeathAnim);
|
2015-04-24 20:20:16 +00:00
|
|
|
[_unit, _anim, 1, true] call EFUNC(common,doAnimation);
|
|
|
|
[{
|
2015-08-22 17:47:23 +00:00
|
|
|
params ["_unit", "_anim"];
|
2015-04-30 20:19:31 +00:00
|
|
|
if ((_unit getVariable "ACE_isUnconscious") and (animationState _unit != _anim)) then {
|
2015-04-24 20:20:16 +00:00
|
|
|
[_unit, _anim, 2, true] call EFUNC(common,doAnimation);
|
|
|
|
};
|
2015-04-30 23:36:09 +00:00
|
|
|
}, [_unit, _anim], 0.5, 0] call EFUNC(common,waitAndExecute);
|
2015-02-08 09:25:03 +00:00
|
|
|
|
2015-05-21 16:42:44 +00:00
|
|
|
_startingTime = ACE_time;
|
2015-02-08 09:25:03 +00:00
|
|
|
|
2015-05-01 20:03:05 +00:00
|
|
|
[DFUNC(unconsciousPFH), 0.1, [_unit, _originalPos, _startingTime, _minWaitingTime, false, vehicle _unit isKindOf "ParachuteBase"] ] call CBA_fnc_addPerFrameHandler;
|
2015-02-08 09:25:03 +00:00
|
|
|
|
2015-04-26 14:47:36 +00:00
|
|
|
// unconscious can't talk
|
|
|
|
[_unit, "isUnconscious"] call EFUNC(common,muteUnit);
|
|
|
|
|
2015-03-24 21:10:41 +00:00
|
|
|
["medical_onUnconscious", [_unit, true]] call EFUNC(common,globalEvent);
|