From dac3047fcaf426a2e9a135dab304621fd195d833 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 10 Apr 2015 22:16:33 -0500 Subject: [PATCH 1/5] Use AllVehicles Instead of CAManBase --- addons/hearing/CfgEventHandlers.hpp | 4 ++-- addons/hearing/functions/fnc_firedNear.sqf | 24 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/addons/hearing/CfgEventHandlers.hpp b/addons/hearing/CfgEventHandlers.hpp index 94b1ab0703..cfe71fe01d 100644 --- a/addons/hearing/CfgEventHandlers.hpp +++ b/addons/hearing/CfgEventHandlers.hpp @@ -20,9 +20,9 @@ class Extended_Init_EventHandlers { }; class Extended_FiredNear_EventHandlers { - class CAManBase { + class AllVehicles { class GVAR(FiredNear) { - clientFiredNear = QUOTE( if (GVAR(enableCombatDeafness) && {_this select 0 == ACE_player}) then {_this call FUNC(firedNear)}; ); + clientFiredNear = QUOTE(_this call FUNC(firedNear);); }; }; }; diff --git a/addons/hearing/functions/fnc_firedNear.sqf b/addons/hearing/functions/fnc_firedNear.sqf index c66361801e..2351afe3c5 100644 --- a/addons/hearing/functions/fnc_firedNear.sqf +++ b/addons/hearing/functions/fnc_firedNear.sqf @@ -21,23 +21,23 @@ */ #include "script_component.hpp" -private ["_unit", "_firer", "_distance", "_weapon", "_muzzle", "_mode", "_ammo", "_silencer", "_audibleFireCoef", "_loudness", "_strength"]; +private ["_silencer", "_audibleFireCoef", "_loudness", "_strength"]; -_unit = _this select 0; -_firer = _this select 1; -_distance = (_this select 2) max 1; -_weapon = _this select 3; -_muzzle = _this select 4; -_mode = _this select 5; -_ammo = _this select 6; +PARAMS_7(_object,_firer,_distance,_weapon,_muzzle,_mode,_ammo); +//Only run if combatDeafness enabled: +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 {}; +if (_distance < 1) then {_distance = 1;}; + _silencer = switch (_weapon) do { - case (primaryWeapon _firer) : {(primaryWeaponItems _firer) select 0}; - case (secondaryWeapon _firer) : {(secondaryWeaponItems _firer) select 0}; - case (handgunWeapon _firer) : {(handgunItems _firer) select 0}; +case (primaryWeapon _firer) : {(primaryWeaponItems _firer) select 0}; +case (secondaryWeapon _firer) : {(secondaryWeaponItems _firer) select 0}; +case (handgunWeapon _firer) : {(handgunItems _firer) select 0}; default {""}; }; @@ -56,4 +56,4 @@ _strength = _loudness - (_loudness/50 * _distance); // linear drop off if (_strength < 0.01) exitWith {}; -[{_this call FUNC(earRinging)}, [_unit, _strength], 0.2, 0] call EFUNC(common,waitAndExecute); +[{_this call FUNC(earRinging)}, [ACE_player, _strength], 0.2, 0] call EFUNC(common,waitAndExecute); From 0edcf03e1253d1ed1b7c5b4014a90e953aa1184e Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 10 Apr 2015 23:21:54 -0500 Subject: [PATCH 2/5] Handle Vehicle Attunation --- addons/hearing/XEH_postInit.sqf | 5 ++ addons/hearing/XEH_preInit.sqf | 1 + addons/hearing/functions/fnc_firedNear.sqf | 5 +- .../fnc_updatePlayerVehicleAttunation.sqf | 57 +++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 addons/hearing/functions/fnc_updatePlayerVehicleAttunation.sqf 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; From ae064359f6e096c32b785a03b0740044dc12fc19 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 10 Apr 2015 23:51:07 -0500 Subject: [PATCH 3/5] Remove Debug --- addons/hearing/XEH_postInit.sqf | 6 ++++-- addons/hearing/functions/fnc_firedNear.sqf | 8 ++++---- .../functions/fnc_updatePlayerVehicleAttunation.sqf | 5 ++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/addons/hearing/XEH_postInit.sqf b/addons/hearing/XEH_postInit.sqf index 76656bf70b..4dc22efd4f 100644 --- a/addons/hearing/XEH_postInit.sqf +++ b/addons/hearing/XEH_postInit.sqf @@ -1,12 +1,14 @@ #include "script_component.hpp" +if (!hasInterface) exitWith {}; + GVAR(currentDeafness) = 0; GVAR(newStrength) = 0; +GVAR(playerVehAttunation) = 1; // Spawn volume updating process [FUNC(updateVolume), 0.1, [] ] call CBA_fnc_addPerFrameHandler; -GVAR(playerVehAttunation) = 1; - +//Update veh attunation when player veh changes ["playerVehicleChanged", {_this call FUNC(updatePlayerVehicleAttunation);}] call EFUNC(common,addEventHandler); ["playerTurretChanged", {_this call FUNC(updatePlayerVehicleAttunation);}] call EFUNC(common,addEventHandler); diff --git a/addons/hearing/functions/fnc_firedNear.sqf b/addons/hearing/functions/fnc_firedNear.sqf index bd6a503528..7b50a44a14 100644 --- a/addons/hearing/functions/fnc_firedNear.sqf +++ b/addons/hearing/functions/fnc_firedNear.sqf @@ -21,17 +21,17 @@ */ #include "script_component.hpp" -private ["_silencer", "_audibleFireCoef", "_loudness", "_strength"]; +private ["_silencer", "_audibleFireCoef", "_loudness", "_strength", "_vehAttenuation"]; PARAMS_7(_object,_firer,_distance,_weapon,_muzzle,_mode,_ammo); //Only run if combatDeafness enabled: 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 ((ACE_player != _object) && {(vehicle ACE_player) != _object}) exitWith {}; if (_weapon in ["Throw", "Put"]) exitWith {}; -_attenuation = if ((ACE_player == (vehicle ACE_player)) || {isTurnedOut ACE_player}) then {1} else {GVAR(playerVehAttunation)}; +_vehAttenuation = if ((ACE_player == (vehicle ACE_player)) || {isTurnedOut ACE_player}) then {1} else {GVAR(playerVehAttunation)}; if (_distance < 1) then {_distance = 1;}; @@ -53,7 +53,7 @@ _audibleFire = getNumber (configFile >> "CfgAmmo" >> _ammo >> "audibleFire"); //_audibleFireTime = getNumber (configFile >> "CfgAmmo" >> _ammo >> "audibleFireTime"); _loudness = _audibleFireCoef * _audibleFire / 64; -_strength = _attenuation * (_loudness - (_loudness/50 * _distance)); // linear drop off +_strength = _vehAttenuation * (_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 index bb4899e998..e03fc23d50 100644 --- a/addons/hearing/functions/fnc_updatePlayerVehicleAttunation.sqf +++ b/addons/hearing/functions/fnc_updatePlayerVehicleAttunation.sqf @@ -25,12 +25,11 @@ if (ACE_player == _vehicle) then { } 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 { From e7472344435aad9c18026abd8406810d901faeec Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Mon, 20 Apr 2015 02:17:47 -0500 Subject: [PATCH 4/5] Cleanup Spelling --- addons/hearing/CfgEventHandlers.hpp | 1 - addons/hearing/XEH_postInit.sqf | 6 ++--- addons/hearing/XEH_preInit.sqf | 2 +- ...sqf => fnc_updatePlayerVehAttenuation.sqf} | 27 +++++++------------ 4 files changed, 13 insertions(+), 23 deletions(-) rename addons/hearing/functions/{fnc_updatePlayerVehicleAttunation.sqf => fnc_updatePlayerVehAttenuation.sqf} (57%) diff --git a/addons/hearing/CfgEventHandlers.hpp b/addons/hearing/CfgEventHandlers.hpp index cfe71fe01d..ce968ed2ca 100644 --- a/addons/hearing/CfgEventHandlers.hpp +++ b/addons/hearing/CfgEventHandlers.hpp @@ -1,4 +1,3 @@ - class Extended_PreInit_EventHandlers { class ADDON { init = QUOTE(call COMPILE_FILE(XEH_preInit) ); diff --git a/addons/hearing/XEH_postInit.sqf b/addons/hearing/XEH_postInit.sqf index 4dc22efd4f..7b584f8397 100644 --- a/addons/hearing/XEH_postInit.sqf +++ b/addons/hearing/XEH_postInit.sqf @@ -4,11 +4,11 @@ if (!hasInterface) exitWith {}; GVAR(currentDeafness) = 0; GVAR(newStrength) = 0; -GVAR(playerVehAttunation) = 1; +GVAR(playerVehAttenuation) = 1; // Spawn volume updating process [FUNC(updateVolume), 0.1, [] ] call CBA_fnc_addPerFrameHandler; //Update veh attunation when player veh changes -["playerVehicleChanged", {_this call FUNC(updatePlayerVehicleAttunation);}] call EFUNC(common,addEventHandler); -["playerTurretChanged", {_this call FUNC(updatePlayerVehicleAttunation);}] call EFUNC(common,addEventHandler); +["playerVehicleChanged", {_this call FUNC(updatePlayerVehAttenuation);}] call EFUNC(common,addEventHandler); +["playerTurretChanged", {_this call FUNC(updatePlayerVehAttenuation);}] call EFUNC(common,addEventHandler); diff --git a/addons/hearing/XEH_preInit.sqf b/addons/hearing/XEH_preInit.sqf index 4ac4c779cd..16b9f35f80 100644 --- a/addons/hearing/XEH_preInit.sqf +++ b/addons/hearing/XEH_preInit.sqf @@ -10,7 +10,7 @@ PREP(hasEarPlugsIn); PREP(moduleHearing); PREP(putInEarPlugs); PREP(removeEarPlugs); -PREP(updatePlayerVehicleAttunation); +PREP(updatePlayerVehAttenuation); PREP(updateVolume); ADDON = true; diff --git a/addons/hearing/functions/fnc_updatePlayerVehicleAttunation.sqf b/addons/hearing/functions/fnc_updatePlayerVehAttenuation.sqf similarity index 57% rename from addons/hearing/functions/fnc_updatePlayerVehicleAttunation.sqf rename to addons/hearing/functions/fnc_updatePlayerVehAttenuation.sqf index e03fc23d50..15f3121c38 100644 --- a/addons/hearing/functions/fnc_updatePlayerVehicleAttunation.sqf +++ b/addons/hearing/functions/fnc_updatePlayerVehAttenuation.sqf @@ -1,15 +1,15 @@ /* * Author: PabstMirror - * Gets the sound attunation of a player to the outside. + * Gets the sound attenuation of a player to the outside. * * Arguments: - * 0: Unit (player) + * None * * Return Value: * Ammount that unit can hear outside * * Example: - * [] call ace_hearing_fnc_updatePlayerVehicleAttunation + * [] call ace_hearing_fnc_updatePlayerVehAttenuation * * Public: No */ @@ -19,10 +19,8 @@ _vehicle = vehicle ACE_player; if (isNull _vehicle) exitWith {}; -_newAttenuation = -1; -if (ACE_player == _vehicle) then { - _newAttenuation = 1; -} else { +_newAttenuation = 1; +if (ACE_player != _vehicle) then { _effectType = ""; _turretPath = [ACE_player] call EFUNC(common,getTurretIndex); _effectType = getText (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "attenuationEffectType"); @@ -38,19 +36,12 @@ if (ACE_player == _vehicle) then { }; }; }; - _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; +TRACE_2("New vehicle attenuation",_vehicle,_newAttenuation); + +GVAR(playerVehAttenuation) = _newAttenuation; + From 822bd22c977e80566697ce9eead4424dbba291fb Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Mon, 20 Apr 2015 02:18:46 -0500 Subject: [PATCH 5/5] gj git --- addons/hearing/functions/fnc_firedNear.sqf | 11 ++++------- .../functions/fnc_updatePlayerVehAttenuation.sqf | 12 +++++++++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/addons/hearing/functions/fnc_firedNear.sqf b/addons/hearing/functions/fnc_firedNear.sqf index 7b50a44a14..6a603c3c3a 100644 --- a/addons/hearing/functions/fnc_firedNear.sqf +++ b/addons/hearing/functions/fnc_firedNear.sqf @@ -31,26 +31,23 @@ if (!GVAR(enableCombatDeafness)) exitWith {}; if ((ACE_player != _object) && {(vehicle ACE_player) != _object}) exitWith {}; if (_weapon in ["Throw", "Put"]) exitWith {}; -_vehAttenuation = if ((ACE_player == (vehicle ACE_player)) || {isTurnedOut ACE_player}) then {1} else {GVAR(playerVehAttunation)}; +_vehAttenuation = if ((ACE_player == (vehicle ACE_player)) || {isTurnedOut ACE_player}) then {1} else {GVAR(playerVehAttenuation)}; if (_distance < 1) then {_distance = 1;}; _silencer = switch (_weapon) do { -case (primaryWeapon _firer) : {(primaryWeaponItems _firer) select 0}; -case (secondaryWeapon _firer) : {(secondaryWeaponItems _firer) select 0}; -case (handgunWeapon _firer) : {(handgunItems _firer) select 0}; + case (primaryWeapon _firer) : {(primaryWeaponItems _firer) select 0}; + case (secondaryWeapon _firer) : {(secondaryWeaponItems _firer) select 0}; + case (handgunWeapon _firer) : {(handgunItems _firer) select 0}; default {""}; }; _audibleFireCoef = 1; -//_audibleFireTimeCoef = 1; if (_silencer != "") then { _audibleFireCoef = getNumber (configFile >> "CfgWeapons" >> _silencer >> "ItemInfo" >> "AmmoCoef" >> "audibleFire"); - //_audibleFireTimeCoef = getNumber (configFile >> "CfgWeapons" >> _silencer >> "ItemInfo" >> "AmmoCoef" >> "audibleFireTime"); }; _audibleFire = getNumber (configFile >> "CfgAmmo" >> _ammo >> "audibleFire"); -//_audibleFireTime = getNumber (configFile >> "CfgAmmo" >> _ammo >> "audibleFireTime"); _loudness = _audibleFireCoef * _audibleFire / 64; _strength = _vehAttenuation * (_loudness - (_loudness/50 * _distance)); // linear drop off diff --git a/addons/hearing/functions/fnc_updatePlayerVehAttenuation.sqf b/addons/hearing/functions/fnc_updatePlayerVehAttenuation.sqf index 15f3121c38..a7285d5e2b 100644 --- a/addons/hearing/functions/fnc_updatePlayerVehAttenuation.sqf +++ b/addons/hearing/functions/fnc_updatePlayerVehAttenuation.sqf @@ -36,7 +36,18 @@ if (ACE_player != _vehicle) then { }; }; }; + _newAttenuation = switch (true) do { + case (_effectType == ""): {1}; + case (_effectType == "CarAttenuation"): {0.5}; + case (_effectType == "RHS_CarAttenuation"): {0.5}; + case (_effectType == "OpenCarAttenuation"): {1}; + case (_effectType == "TankAttenuation"): {0.1}; + case (_effectType == "HeliAttenuation"): {0.3}; + case (_effectType == "OpenHeliAttenuation"): {0.9}; + case (_effectType == "SemiOpenHeliAttenuation"): {0.6}; + case (_effectType == "HeliAttenuationGunner"): {0.85}; + case (_effectType == "HeliAttenuationRamp"): {0.85}; default {1}; }; }; @@ -44,4 +55,3 @@ if (ACE_player != _vehicle) then { TRACE_2("New vehicle attenuation",_vehicle,_newAttenuation); GVAR(playerVehAttenuation) = _newAttenuation; -