From c93e9e3f3b0b9cf1bbc39f46f893b6742a9bf357 Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 30 Sep 2016 13:03:43 +0200 Subject: [PATCH] fix playSoundInjured wrong args --- .../functions/fnc_handleStateDefault.sqf | 2 +- .../functions/fnc_handleStateInjured.sqf | 2 +- .../functions/fnc_handleStateRevive.sqf | 2 +- .../functions/fnc_handleStateUnconscious.sqf | 2 +- .../functions/fnc_playInjuredSound.sqf | 81 ------------------- addons/medical/script_component.hpp | 4 + .../functions/fnc_playInjuredSound.sqf | 7 +- 7 files changed, 13 insertions(+), 87 deletions(-) delete mode 100644 addons/medical/functions/fnc_playInjuredSound.sqf diff --git a/addons/medical/functions/fnc_handleStateDefault.sqf b/addons/medical/functions/fnc_handleStateDefault.sqf index 404f49779b..5339268054 100644 --- a/addons/medical/functions/fnc_handleStateDefault.sqf +++ b/addons/medical/functions/fnc_handleStateDefault.sqf @@ -22,5 +22,5 @@ systemChat format["handling state default for unit: %1", _this]; private _pain = _unit getVariable [QGVAR(pain), 0]; if (_pain > (_unit getVariable [QGVAR(painSuppress), 0])) then { - [_unit, _pain] call EFUNC(medical_engine,playInjuredSound); + [_unit, "moan", PAIN_TO_MOAN(_pain)] call EFUNC(medical_engine,playInjuredSound); }; diff --git a/addons/medical/functions/fnc_handleStateInjured.sqf b/addons/medical/functions/fnc_handleStateInjured.sqf index c208bea0e0..9f104498c6 100644 --- a/addons/medical/functions/fnc_handleStateInjured.sqf +++ b/addons/medical/functions/fnc_handleStateInjured.sqf @@ -20,5 +20,5 @@ if (!local _unit) exitWith { private _pain = _unit getVariable [QGVAR(pain), 0]; if (_pain > (_unit getVariable [QGVAR(painSuppress), 0])) then { - [_unit, _pain] call EFUNC(medical_engine,playInjuredSound); + [_unit, "moan", PAIN_TO_MOAN(_pain)] call EFUNC(medical_engine,playInjuredSound); }; diff --git a/addons/medical/functions/fnc_handleStateRevive.sqf b/addons/medical/functions/fnc_handleStateRevive.sqf index abff476246..45abbd2ed4 100644 --- a/addons/medical/functions/fnc_handleStateRevive.sqf +++ b/addons/medical/functions/fnc_handleStateRevive.sqf @@ -51,5 +51,5 @@ if (GVAR(level) >= 2) then { private _pain = _unit getVariable [QGVAR(pain), 0]; if (_pain > (_unit getVariable [QGVAR(painSuppress), 0])) then { - [_unit, _pain] call EFUNC(medical_engine,playInjuredSound); + [_unit, "moan", PAIN_TO_MOAN(_pain)] call EFUNC(medical_engine,playInjuredSound); }; diff --git a/addons/medical/functions/fnc_handleStateUnconscious.sqf b/addons/medical/functions/fnc_handleStateUnconscious.sqf index c208bea0e0..9f104498c6 100644 --- a/addons/medical/functions/fnc_handleStateUnconscious.sqf +++ b/addons/medical/functions/fnc_handleStateUnconscious.sqf @@ -20,5 +20,5 @@ if (!local _unit) exitWith { private _pain = _unit getVariable [QGVAR(pain), 0]; if (_pain > (_unit getVariable [QGVAR(painSuppress), 0])) then { - [_unit, _pain] call EFUNC(medical_engine,playInjuredSound); + [_unit, "moan", PAIN_TO_MOAN(_pain)] call EFUNC(medical_engine,playInjuredSound); }; diff --git a/addons/medical/functions/fnc_playInjuredSound.sqf b/addons/medical/functions/fnc_playInjuredSound.sqf deleted file mode 100644 index 2e5ec2ab5f..0000000000 --- a/addons/medical/functions/fnc_playInjuredSound.sqf +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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 - * 1: Amount of Pain - * - * ReturnValue: - * None - * - * Public: No - */ - -#include "script_component.hpp" - -params ["_unit", "_pain"]; -if (!local _unit || !GVAR(enableScreams)) exitWith{}; - -// Lock if the unit is already playing a sound. -if ((_unit getVariable [QGVAR(playingInjuredSound),false])) exitWith {}; -_unit setVariable [QGVAR(playingInjuredSound),true]; - -// Play the sound if there is any damage present. -if (_pain > 0 && {[_unit] call EFUNC(common,isAwake)}) exitWith { - // Classnames of the available sounds. - private _availableSounds_A = [ - "WoundedGuyA_01", - "WoundedGuyA_02", - "WoundedGuyA_03", - "WoundedGuyA_04", - "WoundedGuyA_05", - "WoundedGuyA_06", - "WoundedGuyA_07", - "WoundedGuyA_08" - ]; - private _availableSounds_B = [ - "WoundedGuyB_01", - "WoundedGuyB_02", - "WoundedGuyB_03", - "WoundedGuyB_04", - "WoundedGuyB_05", - "WoundedGuyB_06", - "WoundedGuyB_07", - "WoundedGuyB_08" - ]; - private _availableSounds_C = [ - "WoundedGuyC_01", - "WoundedGuyC_02", - "WoundedGuyC_03", - "WoundedGuyC_04", - "WoundedGuyC_05" - ]; - private _sound = ""; - - // Select the to be played sound based upon damage amount. - if (_pain > 0.5) then { - if (random(1) > 0.5) then { - _sound = selectRandom _availableSounds_A; - } else { - _sound = selectRandom _availableSounds_B; - }; - } else { - _sound = selectRandom _availableSounds_B; - }; - // Play the sound - playSound3D [(getArray(configFile >> "CfgSounds" >> _sound >> "sound") select 0) + ".wss", objNull, false, getPos _unit, 15, 1, 25]; // +2db, 15 meters. - - // Figure out what the delay will be before it is possible to play a sound again. - private _delay = (30 - (random(25) * _pain)) max (3.5 + random(2)); - - // Clean up the lock - [{ - (_this select 0) setVariable [QGVAR(playingInjuredSound), nil]; - }, [_unit], _delay, _delay] call CBA_fnc_waitAndExecute; -}; - -// Clean up in case there has not been played any sounds. -_unit setVariable [QGVAR(playingInjuredSound), nil]; diff --git a/addons/medical/script_component.hpp b/addons/medical/script_component.hpp index c008c9e7bd..9f15450234 100644 --- a/addons/medical/script_component.hpp +++ b/addons/medical/script_component.hpp @@ -16,3 +16,7 @@ #endif #include "\z\ace\addons\main\script_macros.hpp" + +// scale received pain to 0-2 level to select type of scream +// below 0.33: 0, from 0.34 to 0.66: 1, more than 0.67: 2 +#define PAIN_TO_MOAN(pain) (floor (3 * pain) min 2) diff --git a/addons/medical_engine/functions/fnc_playInjuredSound.sqf b/addons/medical_engine/functions/fnc_playInjuredSound.sqf index aa7ae2dd4d..24b578f4de 100644 --- a/addons/medical_engine/functions/fnc_playInjuredSound.sqf +++ b/addons/medical_engine/functions/fnc_playInjuredSound.sqf @@ -18,7 +18,8 @@ */ #include "script_component.hpp" -#define TIME_OUT 1 +#define TIME_OUT_HIT 1 +#define TIME_OUT_MOAN 5 params [["_unit", objNull, [objNull]], ["_type", "hit", [""]], ["_severity", 0, [0]]]; TRACE_3("",_unit,_type,_severity); @@ -27,9 +28,11 @@ if (!local _unit) exitWith { ACE_LOGERROR("Unit not local or null"); }; +private _timeOut = [TIME_OUT_HIT, TIME_OUT_MOAN] select (_type == "moan"); + // Handle timeout if (_unit getVariable [QGVAR(soundTimeout), -1] > CBA_missionTime) exitWith {}; -_unit setVariable [QGVAR(soundTimeout), CBA_missionTime + TIME_OUT]; +_unit setVariable [QGVAR(soundTimeout), CBA_missionTime + _timeOut]; // Get sounds private _soundsNamespace = NAMESPACE_NULL;