diff --git a/addons/hearing/XEH_postInit.sqf b/addons/hearing/XEH_postInit.sqf index adb7827ce7..76656bf70b 100644 --- a/addons/hearing/XEH_postInit.sqf +++ b/addons/hearing/XEH_postInit.sqf @@ -5,3 +5,8 @@ GVAR(newStrength) = 0; // Spawn volume updating process [FUNC(updateVolume), 0.1, [] ] call CBA_fnc_addPerFrameHandler; + +GVAR(playerVehAttunation) = 1; + +["playerVehicleChanged", {_this call FUNC(updatePlayerVehicleAttunation);}] call EFUNC(common,addEventHandler); +["playerTurretChanged", {_this call FUNC(updatePlayerVehicleAttunation);}] call EFUNC(common,addEventHandler); diff --git a/addons/hearing/XEH_preInit.sqf b/addons/hearing/XEH_preInit.sqf index 0785a32aff..4ac4c779cd 100644 --- a/addons/hearing/XEH_preInit.sqf +++ b/addons/hearing/XEH_preInit.sqf @@ -10,6 +10,7 @@ PREP(hasEarPlugsIn); PREP(moduleHearing); PREP(putInEarPlugs); PREP(removeEarPlugs); +PREP(updatePlayerVehicleAttunation); PREP(updateVolume); ADDON = true; diff --git a/addons/hearing/functions/fnc_firedNear.sqf b/addons/hearing/functions/fnc_firedNear.sqf index 2351afe3c5..bd6a503528 100644 --- a/addons/hearing/functions/fnc_firedNear.sqf +++ b/addons/hearing/functions/fnc_firedNear.sqf @@ -30,7 +30,8 @@ if (!GVAR(enableCombatDeafness)) exitWith {}; //Only run if firedNear object is player or player's vehicle: if ((ACE_player != (_this select 0)) && {(vehicle ACE_player) != (_this select 0)}) exitWith {}; if (_weapon in ["Throw", "Put"]) exitWith {}; -if (_unit != vehicle _unit && {!([_unit] call EFUNC(common,isTurnedOut))}) exitWith {}; + +_attenuation = if ((ACE_player == (vehicle ACE_player)) || {isTurnedOut ACE_player}) then {1} else {GVAR(playerVehAttunation)}; if (_distance < 1) then {_distance = 1;}; @@ -52,7 +53,7 @@ _audibleFire = getNumber (configFile >> "CfgAmmo" >> _ammo >> "audibleFire"); //_audibleFireTime = getNumber (configFile >> "CfgAmmo" >> _ammo >> "audibleFireTime"); _loudness = _audibleFireCoef * _audibleFire / 64; -_strength = _loudness - (_loudness/50 * _distance); // linear drop off +_strength = _attenuation * (_loudness - (_loudness/50 * _distance)); // linear drop off if (_strength < 0.01) exitWith {}; diff --git a/addons/hearing/functions/fnc_updatePlayerVehicleAttunation.sqf b/addons/hearing/functions/fnc_updatePlayerVehicleAttunation.sqf new file mode 100644 index 0000000000..bb4899e998 --- /dev/null +++ b/addons/hearing/functions/fnc_updatePlayerVehicleAttunation.sqf @@ -0,0 +1,57 @@ +/* + * Author: PabstMirror + * Gets the sound attunation of a player to the outside. + * + * Arguments: + * 0: Unit (player) + * + * Return Value: + * Ammount that unit can hear outside + * + * Example: + * [] call ace_hearing_fnc_updatePlayerVehicleAttunation + * + * Public: No + */ +#include "script_component.hpp" + +_vehicle = vehicle ACE_player; + +if (isNull _vehicle) exitWith {}; + +_newAttenuation = -1; +if (ACE_player == _vehicle) then { + _newAttenuation = 1; +} else { + _effectType = ""; + _turretPath = [ACE_player] call EFUNC(common,getTurretIndex); + systemChat format ["_turretPath %1", _turretPath]; + _effectType = getText (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "attenuationEffectType"); + systemChat format ["Veh EffectType %1", _effectType]; + if (!(_turretPath isEqualTo [])) then { + _turretConfig = [(configFile >> "CfgVehicles" >> (typeOf _vehicle)), _turretPath] call EFUNC(common,getTurretConfigPath); + + if ((getNumber (_turretConfig >> "disableSoundAttenuation")) == 1) then { + _effectType = ""; + } else { + if (isText (_turretConfig >> "soundAttenuationTurret")) then { + _effectType = getText (_turretConfig >> "soundAttenuationTurret"); + }; + }; + }; + + _newAttenuation = switch (true) do { + case (_effectType == ""): {1}; + case (_effectType == "CarAttenuation"): {0.7}; + case (_effectType == "OpenCarAttenuation"): {1}; + case (_effectType == "TankAttenuation"): {0.1}; + case (_effectType == "HeliAttenuation"): {0.25}; + case (_effectType == "OpenHeliAttenuation"): {0.7}; + case (_effectType == "SemiOpenHeliAttenuation"): {0.5}; + case (_effectType == "HeliAttenuationGunner"): {0.75}; + case (_effectType == "HeliAttenuationRamp"): {0.75}; + default {1}; + }; +}; + +GVAR(playerVehAttunation) = _newAttenuation;