mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Calculate hearing protection coefficient on events
This commit is contained in:
parent
8fed9325c9
commit
649b0c28e2
@ -10,24 +10,30 @@ GVAR(deafnessPrior) = 0;
|
||||
GVAR(volume) = 1;
|
||||
GVAR(playerVehAttenuation) = 1;
|
||||
GVAR(time3) = 0;
|
||||
GVAR(damageCoefficent) = 1;
|
||||
|
||||
["SettingsInitialized", {
|
||||
TRACE_1("settingInit",GVAR(EnableCombatDeafness));
|
||||
// Only run if combat deafness is enabled
|
||||
// Only run PFEH and install event handlers if combat deafness is enabled
|
||||
if (!GVAR(EnableCombatDeafness)) exitWith {};
|
||||
|
||||
// Spawn volume updating process
|
||||
[FUNC(updateVolume), 1, [false]] call CBA_fnc_addPerFrameHandler;
|
||||
|
||||
//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)
|
||||
["playerChanged", {
|
||||
GVAR(deafnessDV) = 0;
|
||||
GVAR(deafnessPrior) = 0;
|
||||
ACE_player setVariable [QGVAR(deaf), false];
|
||||
GVAR(time3) = 0;
|
||||
[] call FUNC(updateHearingProtection);
|
||||
}] call EFUNC(common,addEventhandler);
|
||||
|
||||
//Update protection on possible helmet change
|
||||
["playerInventoryChanged", {[] call FUNC(updateHearingProtection);}] call EFUNC(common,addEventhandler);
|
||||
|
||||
}] call EFUNC(common,addEventHandler);
|
||||
|
||||
//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)
|
||||
["playerChanged", {
|
||||
GVAR(deafnessDV) = 0;
|
||||
GVAR(deafnessPrior) = 0;
|
||||
ACE_player setVariable [QGVAR(deaf), false];
|
||||
GVAR(time3) = 0;
|
||||
}] call EFUNC(common,addEventhandler);
|
||||
|
@ -11,6 +11,7 @@ PREP(hasEarPlugsIn);
|
||||
PREP(moduleHearing);
|
||||
PREP(putInEarPlugs);
|
||||
PREP(removeEarPlugs);
|
||||
PREP(updateHearingProtection);
|
||||
PREP(updatePlayerVehAttenuation);
|
||||
PREP(updateVolume);
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
/*
|
||||
* Author: KoffeinFlummi, commy2, Rocko, Rommel, Ruthberg
|
||||
* Handle new sound souce near player and apply hearing damage
|
||||
* Handle new sound souce near ace_player and apply hearing damage
|
||||
*
|
||||
* Arguments:
|
||||
* 0: strength of ear ringing (Number between 0 and 1) <NUMBER>
|
||||
* 0: strength of ear ringing <NUMBER>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [_unit, _strength] call ace_hearing_fnc_earRinging
|
||||
* [_strength] call ace_hearing_fnc_earRinging
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
@ -20,18 +20,6 @@ if (_strength < 0.05) exitWith {};
|
||||
if (!isNull curatorCamera) exitWith {};
|
||||
if ((!GVAR(enabledForZeusUnits)) && {player != ACE_player}) exitWith {};
|
||||
|
||||
if (_unit getVariable ["ACE_hasEarPlugsin", false]) then {
|
||||
_strength = _strength / 4;
|
||||
};
|
||||
TRACE_2("adding",_strength * GVAR(damageCoefficent),GVAR(deafnessDV));
|
||||
|
||||
//headgear hearing protection
|
||||
if (headgear _unit != "") then {
|
||||
private _protection = (getNumber (configFile >> "CfgWeapons" >> (headgear _unit) >> QGVAR(protection))) min 1;
|
||||
if (_protection > 0) then {
|
||||
_strength = _strength * (1 - _protection);
|
||||
};
|
||||
};
|
||||
|
||||
TRACE_2("adding",_strength,GVAR(deafnessDV));
|
||||
|
||||
GVAR(deafnessDV) = GVAR(deafnessDV) + _strength;
|
||||
GVAR(deafnessDV) = GVAR(deafnessDV) + (_strength * GVAR(damageCoefficent));
|
||||
|
@ -29,3 +29,5 @@ _player setVariable ["ACE_hasEarPlugsIn", true, true];
|
||||
|
||||
/*// No Earplugs in inventory, telling user
|
||||
[localize LSTRING(NoPlugs)] call EFUNC(common,displayTextStructured);*/
|
||||
|
||||
[] call FUNC(updateHearingProtection);
|
||||
|
@ -30,3 +30,5 @@ _player setVariable ["ACE_hasEarPlugsIn", false, true];
|
||||
|
||||
//Force an immediate fast volume update:
|
||||
[[true]] call FUNC(updateVolume);
|
||||
|
||||
[] call FUNC(updateHearingProtection);
|
||||
|
28
addons/hearing/functions/fnc_updateHearingProtection.sqf
Normal file
28
addons/hearing/functions/fnc_updateHearingProtection.sqf
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Updates the hearing protection for player on earbuds/helmet change
|
||||
*
|
||||
* Arguments:
|
||||
* None
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [] call ace_hearing_fnc_updateHearingProtection
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
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);
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue
Block a user