2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2016-07-30 12:00:42 +00:00
|
|
|
/*
|
|
|
|
* Author: commy2
|
|
|
|
* Play random injured sound for a unit. The sound is broadcasted across MP.
|
|
|
|
* Will not play if the unit has already played a sound within to close a time frame.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Unit <OBJECT>
|
2024-08-09 21:35:35 +00:00
|
|
|
* 1: Type ["hit", "moan"] <STRING> (default: "hit")
|
|
|
|
* 2: Severity [0, 1, 2] <NUMBER> (default: 0)
|
|
|
|
* 3: Hit sound distances <ARRAY> (default: [50, 60, 70])
|
|
|
|
* 4: Moan sound distances <ARRAY> (default: [10, 15, 20])
|
|
|
|
* 5: Allow unconscious units <BOOL> (default: false)
|
2016-07-30 12:00:42 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2018-07-18 18:21:27 +00:00
|
|
|
* [player, "hit", 1] call ace_medical_feedback_fnc_playInjuredSound
|
2016-07-30 12:00:42 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2016-09-30 11:03:43 +00:00
|
|
|
#define TIME_OUT_HIT 1
|
2019-12-17 17:17:49 +00:00
|
|
|
#define TIME_OUT_MOAN [12, 7.5, 5]
|
2016-07-30 12:00:42 +00:00
|
|
|
|
2024-08-09 21:35:35 +00:00
|
|
|
params [["_unit", objNull, [objNull]], ["_type", "hit", [""]], ["_severity", 0, [0]], ["_hitDistances", [50, 60, 70], [[]], [3]], ["_moanDistances", [10, 15, 20], [[]], [3]], ["_allowUnconscious", false, [true]]];
|
2017-02-19 04:11:40 +00:00
|
|
|
// TRACE_3("",_unit,_type,_severity);
|
2016-07-30 12:00:42 +00:00
|
|
|
|
2020-04-05 03:01:51 +00:00
|
|
|
if (!local _unit) exitWith { ERROR_2("playInjuredSound: Unit not local or null [%1:%2]",_unit,typeOf _unit); };
|
|
|
|
|
2024-08-09 21:35:35 +00:00
|
|
|
if (!_allowUnconscious && {!(_unit call EFUNC(common,isAwake))}) exitWith {};
|
2016-10-13 18:17:21 +00:00
|
|
|
|
2020-06-20 00:42:23 +00:00
|
|
|
// Limit network traffic by only sending the event to players who can potentially hear it
|
|
|
|
private _distance = if (_type == "hit") then {
|
2024-08-09 21:35:35 +00:00
|
|
|
_hitDistances select _severity
|
2020-06-20 00:42:23 +00:00
|
|
|
} else {
|
2024-08-09 21:35:35 +00:00
|
|
|
_moanDistances select _severity
|
2020-06-20 00:42:23 +00:00
|
|
|
};
|
2021-04-17 20:28:52 +00:00
|
|
|
private _targets = allPlayers inAreaArray [ASLToAGL getPosASL _unit, _distance, _distance, 0, false, _distance];
|
2020-06-20 00:42:23 +00:00
|
|
|
if (_targets isEqualTo []) exitWith {};
|
|
|
|
|
2016-07-30 12:00:42 +00:00
|
|
|
// Handle timeout
|
2016-10-13 18:17:21 +00:00
|
|
|
if (_unit getVariable [QGVAR(soundTimeout) + _type, -1] > CBA_missionTime) exitWith {};
|
2019-12-17 17:17:49 +00:00
|
|
|
private _timeOut = if (_type == "moan") then { TIME_OUT_MOAN # _severity } else { TIME_OUT_HIT };
|
2016-10-13 18:17:21 +00:00
|
|
|
_unit setVariable [QGVAR(soundTimeout) + _type, CBA_missionTime + _timeOut];
|
2016-07-30 12:00:42 +00:00
|
|
|
|
|
|
|
// Get units speaker
|
|
|
|
private _speaker = speaker _unit;
|
|
|
|
if (_speaker == "ACE_NoVoice") then {
|
|
|
|
_speaker = _unit getVariable "ace_originalSpeaker";
|
|
|
|
};
|
|
|
|
|
2019-10-11 20:00:53 +00:00
|
|
|
// Fallback if speaker has no associated scream/moan sound
|
|
|
|
if (isNull (configFile >> "CfgSounds" >> format ["ACE_moan_%1_low_1", _speaker])) then {
|
|
|
|
_speaker = "Male08ENG";
|
2016-07-30 12:00:42 +00:00
|
|
|
};
|
|
|
|
|
2019-10-11 20:00:53 +00:00
|
|
|
// Select actual sound
|
|
|
|
private _variation = ["low", "mid", "high"] select _severity;
|
2016-07-30 12:00:42 +00:00
|
|
|
|
2019-10-11 20:00:53 +00:00
|
|
|
private _cfgSounds = configFile >> "CfgSounds";
|
|
|
|
private _targetClass = format ["ACE_%1_%2_%3_", _type, _speaker, _variation];
|
|
|
|
private _index = 1;
|
|
|
|
private _sounds = [];
|
|
|
|
while {isClass (_cfgSounds >> (_targetClass + str _index))} do {
|
|
|
|
_sounds pushBack (_cfgSounds >> (_targetClass + str _index));
|
|
|
|
_index = _index + 1;
|
2016-07-30 12:00:42 +00:00
|
|
|
};
|
2019-10-11 20:00:53 +00:00
|
|
|
private _sound = configName selectRandom _sounds;
|
|
|
|
if (isNil "_sound") exitWith { WARNING_1("no sounds for target [%1]",_targetClass); };
|
2016-07-30 12:00:42 +00:00
|
|
|
|
2019-10-11 20:00:53 +00:00
|
|
|
[QGVAR(forceSay3D), [_unit, _sound, _distance], _targets] call CBA_fnc_targetEvent;
|