mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Cache volume attenuation due to earplugs and headgear
This commit is contained in:
parent
930c2f84c6
commit
0236c16e8f
@ -11,20 +11,24 @@ GVAR(volume) = 1;
|
||||
GVAR(playerVehAttenuation) = 1;
|
||||
GVAR(time3) = 0;
|
||||
GVAR(damageCoefficent) = 1;
|
||||
GVAR(volumeAttenuation) = 1;
|
||||
|
||||
["SettingsInitialized", {
|
||||
TRACE_1("settingInit",GVAR(EnableCombatDeafness));
|
||||
// Only run PFEH and install event handlers if combat deafness is enabled
|
||||
if (!GVAR(EnableCombatDeafness)) exitWith {};
|
||||
|
||||
// Update hearing protection now:
|
||||
[] call FUNC(updateHearingProtection);
|
||||
|
||||
// Spawn volume updating process
|
||||
[FUNC(updateVolume), 1, [false]] call CBA_fnc_addPerFrameHandler;
|
||||
|
||||
//Update veh attunation when player veh changes
|
||||
// Update veh attunation when player veh changes
|
||||
["playerVehicleChanged", {_this call FUNC(updatePlayerVehAttenuation);}] call EFUNC(common,addEventHandler);
|
||||
["playerTurretChanged", {_this call FUNC(updatePlayerVehAttenuation);}] call EFUNC(common,addEventHandler);
|
||||
|
||||
//Reset deafness on respawn (or remote control player switch)
|
||||
// Reset deafness on respawn (or remote control player switch)
|
||||
["playerChanged", {
|
||||
GVAR(deafnessDV) = 0;
|
||||
GVAR(deafnessPrior) = 0;
|
||||
@ -33,9 +37,6 @@ GVAR(damageCoefficent) = 1;
|
||||
[] call FUNC(updateHearingProtection);
|
||||
}] call EFUNC(common,addEventhandler);
|
||||
|
||||
//Update protection on possible helmet change
|
||||
// Update protection on possible helmet change
|
||||
["playerInventoryChanged", {[] call FUNC(updateHearingProtection);}] call EFUNC(common,addEventhandler);
|
||||
|
||||
//Update hearing protection now:
|
||||
[] call FUNC(updateHearingProtection);
|
||||
}] call EFUNC(common,addEventHandler);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Updates the hearing protection for player on earbuds/helmet change
|
||||
* Updates the hearing protection and volume attenuation for player on earbuds/helmet change
|
||||
*
|
||||
* Arguments:
|
||||
* None
|
||||
@ -17,12 +17,20 @@
|
||||
|
||||
TRACE_1("params",_this);
|
||||
|
||||
if (isNull ACE_player) exitWith {GVAR(damageCoefficent) = 0;};
|
||||
|
||||
GVAR(damageCoefficent) = if (ACE_player getVariable ["ACE_hasEarPlugsin", false]) then {0.25} else {1};
|
||||
if (headgear ACE_player != "") then { //headgear hearing protection
|
||||
private _protection = (getNumber (configFile >> "CfgWeapons" >> (headgear ACE_player) >> QGVAR(protection))) min 1;
|
||||
if (_protection > 0) then {
|
||||
GVAR(damageCoefficent) = GVAR(damageCoefficent) * (1 - _protection);
|
||||
};
|
||||
if (isNull ACE_player) exitWith {
|
||||
GVAR(damageCoefficent) = 0;
|
||||
GVAR(volumeAttenuation) = 1;
|
||||
};
|
||||
|
||||
// Handle Earplugs
|
||||
private _hasEarPlugsIn = [ACE_player] call FUNC(hasEarPlugsIn);
|
||||
GVAR(damageCoefficent) = [1, 0.25] select _hasEarPlugsIn;
|
||||
GVAR(volumeAttenuation) = [1, GVAR(EarplugsVolume)] select _hasEarPlugsIn;
|
||||
|
||||
// Handle Headgear
|
||||
if (headgear ACE_player != "") then {
|
||||
private _protection = (getNumber (configFile >> "CfgWeapons" >> (headgear ACE_player) >> QGVAR(protection))) min 1;
|
||||
GVAR(damageCoefficent) = GVAR(damageCoefficent) * (1 - _protection);
|
||||
private _attenuation = (getNumber (configFile >> "CfgWeapons" >> (headgear ACE_player) >> QGVAR(lowerVolume))) min 1;
|
||||
GVAR(volumeAttenuation) = GVAR(volumeAttenuation) * (1 - _attenuation);
|
||||
};
|
||||
|
@ -46,18 +46,8 @@ if (missionNameSpace getVariable [QGVAR(disableVolumeUpdate), false]) exitWith {
|
||||
|
||||
private _volume = GVAR(volume);
|
||||
|
||||
// Earplugs reduce hearing 50%
|
||||
if ([ACE_player] call FUNC(hasEarPlugsIn)) then {
|
||||
_volume = _volume min GVAR(EarplugsVolume);
|
||||
};
|
||||
|
||||
// Headgear can reduce hearing
|
||||
if (headgear ACE_player != "") then {
|
||||
private _lowerVolume = (getNumber (configFile >> "CfgWeapons" >> (headgear ACE_player) >> QGVAR(lowerVolume))) min 1;
|
||||
if (_lowerVolume > 0) then {
|
||||
_volume = _volume min (1 - _lowerVolume);
|
||||
};
|
||||
};
|
||||
// Earplugs and headgear can attenuate hearing
|
||||
_volume = _volume min GVAR(volumeAttenuation);
|
||||
|
||||
// Reduce volume if player is unconscious
|
||||
if (ACE_player getVariable ["ACE_isUnconscious", false]) then {
|
||||
|
Loading…
Reference in New Issue
Block a user