diff --git a/addons/medical/XEH_postInit.sqf b/addons/medical/XEH_postInit.sqf index a0550fa308..116809b26f 100644 --- a/addons/medical/XEH_postInit.sqf +++ b/addons/medical/XEH_postInit.sqf @@ -43,14 +43,14 @@ GVAR(effectUnconsciousUnit) = objNull; GVAR(playingHeartBeatSound) = true; _sleep = 60 / _heartRate; if (_heartRate < 60) then { - _sound = _hbSoundsSlow select (random((count _hbSoundsSlow) -1)); + _sound = GVAR(heartBeatSounds_Slow) select (random((count GVAR(heartBeatSounds_Slow)) -1)); playSound _sound; [{ GVAR(playingHeartBeatSound) = false; }, [], _sleep, _sleep] call EFUNC(common,waitAndExecute); } else { if (_heartRate > 120) then { - _sound = _hbSoundsFast select (random((count _hbSoundsFast) -1)); + _sound = GVAR(heartBeatSounds_Fast) select (random((count GVAR(heartBeatSounds_Fast)) -1)); playSound _sound; [{ GVAR(playingHeartBeatSound) = false; diff --git a/addons/medical/XEH_preInit.sqf b/addons/medical/XEH_preInit.sqf index 5c1945817c..f95e77f003 100644 --- a/addons/medical/XEH_preInit.sqf +++ b/addons/medical/XEH_preInit.sqf @@ -23,6 +23,8 @@ PREP(addToInjuredCollection); PREP(setUnconscious); PREP(getUnconsciousCondition); PREP(addUnconsciousCondition); +PREP(setDead); +PREP(playInjuredSound); GVAR(injuredUnitCollection) = []; diff --git a/addons/medical/functions/fnc_addToInjuredCollection.sqf b/addons/medical/functions/fnc_addToInjuredCollection.sqf index c832dc1a3c..c62e5862bf 100644 --- a/addons/medical/functions/fnc_addToInjuredCollection.sqf +++ b/addons/medical/functions/fnc_addToInjuredCollection.sqf @@ -38,7 +38,7 @@ if ([_unit] call FUNC(hasMedicalEnabled)) then { if (random(1) > 0.6) then { [_unit] call FUNC(setUnconscious); }; - //[_unit] call FUNC(playInjuredSound); + [_unit] call FUNC(playInjuredSound); }; }; }, 1, [_unit]] call CBA_fnc_addPerFrameHandler; diff --git a/addons/medical/functions/fnc_handleUnitVitals.sqf b/addons/medical/functions/fnc_handleUnitVitals.sqf index 566aedbbf8..9e5a5400c4 100644 --- a/addons/medical/functions/fnc_handleUnitVitals.sqf +++ b/addons/medical/functions/fnc_handleUnitVitals.sqf @@ -43,7 +43,7 @@ if ((_unit call FUNC(getBloodLoss)) > 0) then { }; }; -_painStatus = _unit getvariable [QGVAR(amountOfPain), 0]; +_painStatus = _unit getvariable [QGVAR(pain), 0]; if (_painStatus > 0) then { if !(_unit getvariable [QGVAR(hasPain), false]) then { _unit setvariable [QGVAR(hasPain), true, true]; @@ -56,7 +56,7 @@ if (_painStatus > 0) then { if (_bloodVolume < 30) exitwith { - // [_unit] call FUNC(setDead); + [_unit] call FUNC(setDead); }; if ([_unit] call EFUNC(common,isAwake)) then { diff --git a/addons/medical/functions/fnc_playInjuredSound.sqf b/addons/medical/functions/fnc_playInjuredSound.sqf new file mode 100644 index 0000000000..1044be7ecf --- /dev/null +++ b/addons/medical/functions/fnc_playInjuredSound.sqf @@ -0,0 +1,97 @@ +/* + * Author: Glowbal + * Play the injured sound for a unit if the unit is damaged. The sound broadcasted across MP. + * Will not play if the unit has already played a sound within to close a time frame. + * Delay: With minimal damage (below 1), the delay is (10 + random(50)) seconds. Otherwise it is 60 seconds / damage. + * + * Arguments: + * 0: The Unit + * + * ReturnValue: + * + * + * Public: No + */ + +#include "script_component.hpp" + +private ["_unit","_amountOfDamage","_bodyPartStatus","_availableSounds_A","_availableSounds_B","_availableSounds_C","_sound"]; +_unit = _this select 0; +if (!local _unit) exitwith{}; + +// Lock if the unit is already playing a sound. +if ((_unit getvariable [QGVAR(playingInjuredSound),false])) exitwith {}; +_unit setvariable [QGVAR(playingInjuredSound),true]; + +// Classnames of the available sounds. +_availableSounds_A = [ + "WoundedGuyA_01", + "WoundedGuyA_02", + "WoundedGuyA_03", + "WoundedGuyA_04", + "WoundedGuyA_05", + "WoundedGuyA_06", + "WoundedGuyA_07", + "WoundedGuyA_08" +]; +_availableSounds_B = [ + "WoundedGuyB_01", + "WoundedGuyB_02", + "WoundedGuyB_03", + "WoundedGuyB_04", + "WoundedGuyB_05", + "WoundedGuyB_06", + "WoundedGuyB_07", + "WoundedGuyB_08" +]; +_availableSounds_C = [ + "WoundedGuyC_01", + "WoundedGuyC_02", + "WoundedGuyC_03", + "WoundedGuyC_04", + "WoundedGuyC_05" +]; + +// TODO Base this off hitpoint damage +// Find the amount of damage for this unit, based upon body part status. +//_bodyPartStatus = [_unit,QGVAR(bodyPartStatus)] call EFUNC(common,getDefinedVariable); +_amountOfDamage = 0; +/*{ + _amountOfDamage = _amountOfDamage + _x; +}foreach _bodyPartStatus;*/ + +// Play the sound if there is any damage present. +if (_amountOfDamage > 0) exitwith { + _sound = ""; + + // Select the to be played sound based upon damage amount. + if (_amountOfDamage > 1) then { + if (random(1) > 0.5) then { + _sound = _availableSounds_A select (round(random((count _availableSounds_A) - 1))); + } else { + _sound = _availableSounds_B select (round(random((count _availableSounds_B) - 1))); + }; + } else { + _sound = _availableSounds_B select (round(random((count _availableSounds_B) - 1))); + }; + + // Play the sound + playSound3D [((getArray(configFile >> "CfgSounds" >> _sound >> "sound") select 0)), _unit, false, getPos _unit, 2, 1, 15]; // +2db, 15 meters. + + // Figure out what the delay will be before it is possible to play a sound again. + private "_delay"; + _delay = 1; + if (_amountOfDamage < 1) then { + _delay = 10 + random(50); + } else { + _delay = (60 / _amountOfDamage); + }; + + // Clean up the lock + [{ + (_this select 0) setvariable [QGVAR(playingInjuredSound),nil]; + }, [_unit], _delay, _delay] call EFUNC(common,waitAndExecute); +}; + +// Clean up in case there has not been played any sounds. +_unit setvariable [QGVAR(playingInjuredSound),nil]; diff --git a/addons/medical/functions/fnc_setCardiacArrest.sqf b/addons/medical/functions/fnc_setCardiacArrest.sqf index 6b63d71f79..03b9835fd7 100644 --- a/addons/medical/functions/fnc_setCardiacArrest.sqf +++ b/addons/medical/functions/fnc_setCardiacArrest.sqf @@ -40,8 +40,7 @@ _timer = 0; [(_this select 1)] call cba_fnc_removePerFrameHandler; }; if (_counter - _timer < 1) exitwith { - - //[_unit] call FUNC(setDead); + [_unit] call FUNC(setDead); [(_this select 1)] call cba_fnc_removePerFrameHandler; _unit setvariable [QGVAR(inCardiacArrest), nil,true]; }; diff --git a/addons/medical/functions/fnc_setDead.sqf b/addons/medical/functions/fnc_setDead.sqf new file mode 100644 index 0000000000..bf63a32230 --- /dev/null +++ b/addons/medical/functions/fnc_setDead.sqf @@ -0,0 +1,36 @@ +/* + * Author: Glowbal + * Either kills a unit or puts the unit in a revivable state, depending on the settings. + * + * Arguments: + * 0: The unit that will be killed + * + * ReturnValue: + * + * + * Public: yes + */ + +#include "script_component.hpp" + +private ["_unit"]; +_unit = _this select 0; +_force = false; +if (count _this >= 2) then { + _force = _this select 1; +}; + +if (!alive _unit) exitwith{}; +if (!local _unit) exitwith { + [[_unit, _force], QUOTE(FUNC(setDead)), _unit, false] call EFUNC(common,execRemoteFnc); +}; + +if (missionName getVariable [QGVAR(enableRevive), false]) exitwith { + // TODO Implement the revive state +}; + +_unit setvariable ["ACE_isDead", true, true]; +if (isPLayer _unit) then { + _unit setvariable ["isDeadPlayer", true, true]; +}; +_unit setdamage 1; diff --git a/addons/medical/functions/fnc_setUnconscious.sqf b/addons/medical/functions/fnc_setUnconscious.sqf index f49e816e63..4e2675dddc 100644 --- a/addons/medical/functions/fnc_setUnconscious.sqf +++ b/addons/medical/functions/fnc_setUnconscious.sqf @@ -1,11 +1,14 @@ -/** - * fn_setUnconsciousState.sqf - * @Descr: Sets a unit in the unconscious state - * @Author: Glowbal +/* + * Author: Glowbal + * Sets a unit in the unconscious state. * - * @Arguments: [unit OBJECT] - * @Return: void - * @PublicAPI: true + * Arguments: + * 0: The unit that will be put in an unconscious state + * + * ReturnValue: + * + * + * Public: yes */ #include "script_component.hpp"