2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-01-11 16:42:31 +00:00
|
|
|
/*
|
|
|
|
* Author: KoffeinFlummi, commy2
|
|
|
|
* Handles deafness due to large-caliber weapons going off near the player.
|
|
|
|
*
|
|
|
|
* Arguments:
|
2024-05-24 23:05:19 +00:00
|
|
|
* 0: Object the event handler is assigned to <OBJECT> (unused)
|
|
|
|
* 1: Object which fires a weapon near the unit <OBJECT>
|
|
|
|
* 2: Distance in meters between the unit and firer <NUMBER>
|
|
|
|
* 3: Weapon <STRING>
|
|
|
|
* 4: Muzzle <STRING>
|
|
|
|
* 5: Current mode of the fired weapon <STRING>
|
|
|
|
* 6: Ammo <STRING>
|
|
|
|
* 7: Unit that fired the weapon <STRING>
|
2015-01-11 16:42:31 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-03-15 21:40:47 +00:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2024-05-24 23:05:19 +00:00
|
|
|
* [player, player, 10, "arifle_MX_ACO_pointer_F", "arifle_MX_ACO_pointer_F", "single", "B_65x39_Caseless", player] call ace_hearing_fnc_firedNear
|
2015-03-15 21:40:47 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
2015-01-11 16:42:31 +00:00
|
|
|
*/
|
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
params ["", "_firer", "_distance", "_weapon", "_muzzle", "_mode", "_ammo", "_gunner"];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
if (_weapon in ["Throw", "Put"]) exitWith {};
|
2015-06-13 16:42:09 +00:00
|
|
|
if (_distance > 50) exitWith {};
|
2015-04-11 04:21:54 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
_distance = 1 max _distance;
|
2016-01-10 00:51:41 +00:00
|
|
|
private _audibleFireCoef = 1;
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
// Unit that fired is on foot
|
|
|
|
private _magazine = if (_gunner == _firer) then {
|
|
|
|
// Check if the unit has a suppressor
|
|
|
|
private _suppressor = (_firer weaponAccessories _weapon) select 0;
|
2015-06-13 16:57:02 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
if (_suppressor != "") then {
|
|
|
|
_audibleFireCoef = getNumber (configFile >> "CfgWeapons" >> _suppressor >> "ItemInfo" >> "AmmoCoef" >> "audibleFire");
|
|
|
|
};
|
2015-06-13 16:32:48 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
(_firer weaponState _muzzle) select 3
|
|
|
|
} else {
|
|
|
|
// Unit that fired is in a vehicle
|
|
|
|
(weaponState [_firer, _firer unitTurret _gunner, _weapon, _muzzle, _mode]) select 3
|
|
|
|
};
|
2015-06-13 16:32:48 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
if (_magazine == "") exitWith {
|
|
|
|
TRACE_5("No mag for weapon/ammo??",_weapon,_muzzle,_ammo,_firer,_gunner);
|
2015-06-13 15:43:27 +00:00
|
|
|
};
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
TRACE_6("mag",_magazine,_weapon,_muzzle,_ammo,_firer,_gunner);
|
|
|
|
|
|
|
|
private _vehAttenuation = [GVAR(playerVehAttenuation), 1] select (isNull objectParent ACE_player || {isTurnedOut ACE_player});
|
|
|
|
private _loudness = _magazine call FUNC(getAmmoLoudness);
|
|
|
|
|
2016-01-10 00:51:41 +00:00
|
|
|
_loudness = _loudness * _audibleFireCoef;
|
|
|
|
private _strength = _vehAttenuation * (_loudness - (_loudness / 50 * _distance)); // linear drop off
|
|
|
|
|
|
|
|
TRACE_1("result",_strength);
|
2015-06-13 16:19:35 +00:00
|
|
|
|
2024-05-29 17:01:39 +00:00
|
|
|
// Call immediately, as it will get picked up later by the update thread anyway
|
|
|
|
_strength call FUNC(earRinging);
|