Hearing - Fix explosions not affecting hearing (#10002)

* Have explosions affect hearing

* Update fnc_explosion.sqf

* Update XEH_postInit.sqf

* Update addons/hearing/functions/fnc_explosion.sqf

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

* Update fnc_explosion.sqf

* Make EH local

* Use sound entry instead

---------

Co-authored-by: PabstMirror <pabstmirror@gmail.com>
This commit is contained in:
johnb432 2024-08-12 15:45:03 +02:00 committed by GitHub
parent f3938ba0cc
commit 72f230a3a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 70 additions and 38 deletions

View File

@ -1,6 +1,6 @@
PREP(addEarPlugs); PREP(addEarPlugs);
PREP(earRinging); PREP(earRinging);
PREP(explosionNear); PREP(explosion);
PREP(firedNear); PREP(firedNear);
PREP(getAmmoLoudness); PREP(getAmmoLoudness);
PREP(handleRespawn); PREP(handleRespawn);

View File

@ -35,6 +35,7 @@ GVAR(lastPlayerVehicle) = objNull;
// Spawn volume updating process // Spawn volume updating process
[LINKFUNC(updateVolume), 1, false] call CBA_fnc_addPerFrameHandler; [LINKFUNC(updateVolume), 1, false] call CBA_fnc_addPerFrameHandler;
[QGVAR(explosion), LINKFUNC(explosion)] call CBA_fnc_addEventHandler;
[QGVAR(updateVolume), LINKFUNC(updateVolume)] call CBA_fnc_addEventHandler; [QGVAR(updateVolume), LINKFUNC(updateVolume)] call CBA_fnc_addEventHandler;
// Update veh attunation when player veh changes // Update veh attunation when player veh changes
@ -71,12 +72,7 @@ GVAR(lastPlayerVehicle) = objNull;
private _firedEH = _oldPlayer getVariable [QGVAR(firedEH), -1]; private _firedEH = _oldPlayer getVariable [QGVAR(firedEH), -1];
_oldPlayer removeEventHandler ["FiredNear", _firedEH]; _oldPlayer removeEventHandler ["FiredNear", _firedEH];
_oldPlayer setVariable [QGVAR(firedEH), nil]; _oldPlayer setVariable [QGVAR(firedEH), nil];
TRACE_2("removed unit eh",_oldPlayer,_firedEH);
private _explosionEH = _oldPlayer getVariable [QGVAR(explosionEH), -1];
_oldPlayer removeEventHandler ["Explosion", _explosionEH];
_oldPlayer setVariable [QGVAR(explosionEH), nil];
TRACE_3("removed unit eh",_oldPlayer,_firedEH,_explosionEH);
}; };
// Don't add a new EH if the unit respawned // Don't add a new EH if the unit respawned
if ((_player getVariable [QGVAR(firedEH), -1]) == -1) then { if ((_player getVariable [QGVAR(firedEH), -1]) == -1) then {
@ -86,11 +82,7 @@ GVAR(lastPlayerVehicle) = objNull;
private _firedEH = _player addEventHandler ["FiredNear", {call FUNC(firedNear)}]; private _firedEH = _player addEventHandler ["FiredNear", {call FUNC(firedNear)}];
_player setVariable [QGVAR(firedEH), _firedEH]; _player setVariable [QGVAR(firedEH), _firedEH];
TRACE_2("added unit eh",_player,_firedEH);
private _explosionEH = _player addEventHandler ["Explosion", {call FUNC(explosionNear)}];
_player setVariable [QGVAR(explosionEH), _explosionEH];
TRACE_3("added unit eh",_player,_firedEH,_explosionEH);
}; };
GVAR(deafnessDV) = 0; GVAR(deafnessDV) = 0;
@ -100,6 +92,17 @@ GVAR(lastPlayerVehicle) = objNull;
call FUNC(updateHearingProtection); call FUNC(updateHearingProtection);
}, true] call CBA_fnc_addPlayerEventHandler; }, true] call CBA_fnc_addPlayerEventHandler;
addMissionEventHandler ["ProjectileCreated", {
params ["_projectile"];
if (!local _projectile) exitWith {};
// Rockets only explode on local clients
_projectile addEventHandler ["Explode", {
[QGVAR(explosion), _this] call CBA_fnc_globalEvent;
}];
}];
// Update protection on possible helmet change // Update protection on possible helmet change
["loadout", LINKFUNC(updateHearingProtection), false] call CBA_fnc_addPlayerEventHandler; ["loadout", LINKFUNC(updateHearingProtection), false] call CBA_fnc_addPlayerEventHandler;
}] call CBA_fnc_addEventHandler; }] call CBA_fnc_addEventHandler;

View File

@ -0,0 +1,55 @@
#include "..\script_component.hpp"
/*
* Author: johnb43
* Handles deafness due to explosions going off near the player.
*
* Arguments:
* 0: Projectile <OBJECT>
* 1: Explosion position ASL <ARRAY>
* 2: Velocity <ARRAY> (unused)
*
* Return Value:
* None
*
* Example:
* [_projectile, [0, 0, 0], [0, 0, 0]] call ace_hearing_fnc_explosion
*
* Public: No
*/
// Ignore spectators, curators and alike
if ((getNumber (configOf ACE_player >> "isPlayableLogic")) == 1) exitWith {};
params ["_projectile", "_pos"];
// Don't allow for distances under 1
private _distance = ((eyePos ACE_player) vectorDistance _pos) max 1;
// Fast exit if explosion far away
if (_distance > 100) exitWith {
TRACE_1("too far away",_distance);
};
private _ammoConfig = configOf _projectile;
private _explosive = getNumber (_ammoConfig >> "explosive");
private _vehAttenuation = [GVAR(playerVehAttenuation), 1] select (isNull objectParent ACE_player || {isTurnedOut ACE_player});
TRACE_5("",typeOf _projectile,_distance,_explosive,_audibleFire,_vehAttenuation);
(if (isArray (_ammoConfig >> "soundHit1")) then {
getArray (_ammoConfig >> "soundHit1")
} else {
getArray (_ammoConfig >> "soundHit")
}) params ["", ["_volume", 1], "", ["_maxDistance", 1500]];
if (_distance > _maxDistance) exitWith {
TRACE_2("too far away",_distance,_maxDistance);
};
private _strength = _vehAttenuation * _explosive * _volume * _maxDistance / _distance^2;
TRACE_2("strength",_volume,_strength);
// Call immediately, as it will get picked up later by the update thread anyway
_strength call FUNC(earRinging);

View File

@ -1,26 +0,0 @@
#include "..\script_component.hpp"
/*
* Author: KoffeinFlummi, commy2, Ruthberg
* Handles deafness due to explosions going off near the player.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Damage inflicted to the unit <NUMBER>
*
* Return Value:
* None
*
* Example:
* [clientExplosionEvent] call ace_hearing_fnc_explosionNear
*
* Public: No
*/
params ["_unit", "_damage"];
TRACE_2("explosion near player",_unit,_damage);
private _strength = (0 max _damage) * 30;
// Call immediately, as it will get picked up later by the update thread anyway
_strength call FUNC(earRinging);