Handle enableCombatDeafness and/or ringing enabled

This commit is contained in:
PabstMirror 2015-07-11 21:00:40 -05:00
parent 040f4a92a0
commit 05d98370e4
7 changed files with 66 additions and 59 deletions

View File

@ -4,6 +4,7 @@ if (!hasInterface) exitWith {};
GVAR(deafnessDV) = 0;
GVAR(deafnessPrior) = 0;
GVAR(volume) = 1;
GVAR(playerVehAttenuation) = 1;
GVAR(beep) = false;
@ -13,12 +14,8 @@ GVAR(time3) = 0;
GVAR(time4) = 0;
["SettingsInitialized", {
//If not enabled, dont't add draw eventhandler or PFEH (for performance)
if (!GVAR(enableCombatDeafness)) exitWith {};
// Spawn volume updating process
[FUNC(updateVolume), 1, [] ] call CBA_fnc_addPerFrameHandler;
[FUNC(updateVolume), 1, [false] ] call CBA_fnc_addPerFrameHandler;
}] call EFUNC(common,addEventHandler);
//Update veh attunation when player veh changes

View File

@ -16,8 +16,6 @@
*/
#include "script_component.hpp"
if (!GVAR(enableCombatDeafness)) exitWith {};
PARAMS_2(_unit,_strength);
if (_unit != ACE_player) exitWith {};

View File

@ -16,8 +16,8 @@
*/
#include "script_component.hpp"
//Only run if combatDeafness enabled:
if (!GVAR(enableCombatDeafness)) exitWith {};
//Only run if deafness or ear ringing is enabled:
if ((!GVAR(enableCombatDeafness)) && GVAR(DisableEarRinging)) exitWith {};
PARAMS_2(_unit,_damage);

View File

@ -21,8 +21,8 @@
*/
#include "script_component.hpp"
//Only run if combatDeafness enabled:
if (!GVAR(enableCombatDeafness)) exitWith {};
//Only run if deafness or ear ringing is enabled:
if ((!GVAR(enableCombatDeafness)) && GVAR(DisableEarRinging)) exitWith {};
PARAMS_7(_object,_firer,_distance,_weapon,_muzzle,_mode,_ammo);

View File

@ -24,5 +24,8 @@ _player setVariable ["ACE_hasEarPlugsIn", true, true];
[localize LSTRING(EarPlugs_Are_On)] call EFUNC(common,displayTextStructured);
//Force an immediate fast volume update:
[[true]] call FUNC(updateVolume);
/*// No Earplugs in inventory, telling user
[localize LSTRING(NoPlugs)] call EFUNC(common,displayTextStructured);*/

View File

@ -27,3 +27,6 @@ _player addItem "ACE_EarPlugs";
_player setVariable ["ACE_hasEarPlugsIn", false, true];
[localize LSTRING(EarPlugs_Are_Off)] call EFUNC(common,displayTextStructured);
//Force an immediate fast volume update:
[[true]] call FUNC(updateVolume);

View File

@ -3,7 +3,8 @@
* Updates and applys the current deafness. Called every 0.1 sec from a PFEH.
*
* Arguments:
* None
* 0: Args <ARRAY>
* -----0: Just update volume (skip ringing/recovery) <BOOL><OPTIONAL>
*
* Return Value:
* None
@ -15,12 +16,19 @@
*/
#include "script_component.hpp"
private["_Volume"];
//Only run if deafness or ear ringing is enabled:
if ((!GVAR(enableCombatDeafness)) && GVAR(DisableEarRinging)) exitWith {};
EXPLODE_1_PVT((_this select 0),_justUpdateVolume);
private["_volume", "_soundTransitionTime"];
GVAR(deafnessDV) = (GVAR(deafnessDV) min 20) max 0;
GVAR(volume) = (1 - (GVAR(deafnessDV) / 20)) max 0;
//If we got a big increase in the last second:
if ((GVAR(deafnessDV) - GVAR(deafnessPrior)) > 2) then {
if (!_justUpdateVolume) then {
//If we got a big increase in the last second:
if ((GVAR(deafnessDV) - GVAR(deafnessPrior)) > 2) then {
if (ACE_time > GVAR(time3)) then {
GVAR(beep2) = false;
};
@ -29,12 +37,11 @@ if ((GVAR(deafnessDV) - GVAR(deafnessPrior)) > 2) then {
GVAR(beep2) = true;
GVAR(time3) = ACE_time + 5;
};
};
};
GVAR(deafnessPrior) = GVAR(deafnessDV);
GVAR(volume) = (1 - (GVAR(deafnessDV) / 20)) max 0;
GVAR(deafnessPrior) = GVAR(deafnessDV);
if (GVAR(deafnessDV) > 19.75) then {
if (GVAR(deafnessDV) > 19.75) then {
ACE_player setvariable [QGVAR(deaf), true];
if ((!GVAR(DisableEarRinging)) && {ACE_time > GVAR(time4)}) then {
playSound "ACE_Combat_Deafness";
@ -42,11 +49,11 @@ if (GVAR(deafnessDV) > 19.75) then {
GVAR(time3) = ACE_time + 10;
GVAR(time4) = ACE_time + 30;
};
} else {
} else {
ACE_player setvariable [QGVAR(deaf), false];
};
};
if (GVAR(deafnessDV) > 10) then {
if (GVAR(deafnessDV) > 10) then {
//check if the ringing is already being played
if (ACE_time > GVAR(time2)) then {
GVAR(beep) = false;
@ -56,12 +63,13 @@ if (GVAR(deafnessDV) > 10) then {
GVAR(time2) = ACE_time + 22;
GVAR(beep) = true;
};
};
// Hearing takes longer to return to normal after it hits rock bottom
GVAR(deafnessDV) = (GVAR(deafnessDV) - (0.5 * (GVAR(volume) max 0.1))) max 0;
};
// Hearing takes longer to return to normal after it hits rock bottom
GVAR(deafnessDV) = (GVAR(deafnessDV) - (0.5 * (GVAR(volume) max 0.1))) max 0;
TRACE_3("tick", GVAR(deafnessPrior), GVAR(deafnessDV), GVAR(volume));
if ((missionNameSpace getVariable [QGVAR(disableVolumeUpdate), false]) || {!GVAR(enableCombatDeafness)}) exitWith {};
_volume = GVAR(volume);
@ -84,11 +92,9 @@ if (ACE_player getVariable ["ACE_isUnconscious", false]) then {
_volume = _volume min GVAR(UnconsciousnessVolume);
};
if (!(missionNameSpace getVariable [QGVAR(disableVolumeUpdate), false])) then {
1 fadeSound _volume;
1 fadeSpeech _volume;
ACE_player setVariable ["tf_globalVolume", _volume];
if (!isNil "acre_api_fnc_setGlobalVolume") then {[_volume^(0.33)] call acre_api_fnc_setGlobalVolume;};
};
_soundTransitionTime = if (_justUpdateVolume) then {0.1} else {1};
//hintSilent format ["GVAR(currentDeafness), _Volume = %1, %2", GVAR(currentDeafness), _volume];
_soundTransitionTime fadeSound _volume;
_soundTransitionTime fadeSpeech _volume;
ACE_player setVariable ["tf_globalVolume", _volume];
if (!isNil "acre_api_fnc_setGlobalVolume") then {[_volume^(0.33)] call acre_api_fnc_setGlobalVolume;};