ACE3/addons/hearing/functions/fnc_firedNear.sqf

99 lines
3.9 KiB
Plaintext
Raw Normal View History

/*
* Author: KoffeinFlummi, commy2
* Handles deafness due to large-caliber weapons going off near the player.
*
* Arguments:
2015-03-15 21:40:47 +00:00
* 0: Unit - Object the event handler is assigned to <OBJECT>
* 1: Firer: Object - Object which fires a weapon near the unit <OBJECT>
* 2: Distance - Distance in meters between the unit and firer <NUMBER>
* 3: weapon - Fired weapon <STRING>
* 4: muzzle - Muzzle that was used <STRING>
* 5: mod - Current mode of the fired weapon <STRING>
* 6: ammo - Ammo used <STRING>
*
* Return Value:
2015-03-15 21:40:47 +00:00
* None
*
* Example:
* [clientFiredNearEvent] call ace_hearing_fnc_firedNear
*
* Public: No
*/
2015-01-14 01:41:53 +00:00
#include "script_component.hpp"
//Only run if deafness or ear ringing is enabled:
if ((!GVAR(enableCombatDeafness)) && GVAR(DisableEarRinging)) exitWith {};
2015-08-13 21:42:20 +00:00
params ["_object", "_firer", "_distance", "_weapon", "_muzzle", "_mode", "_ammo"];
2015-04-11 03:16:33 +00:00
//Only run if firedNear object is player or player's vehicle:
2015-04-11 04:51:07 +00:00
if ((ACE_player != _object) && {(vehicle ACE_player) != _object}) exitWith {};
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
2015-07-11 02:01:32 +00:00
private ["_silencer", "_audibleFireCoef", "_loudness", "_strength", "_vehAttenuation", "_magazine", "_muzzles", "_weaponMagazines", "_muzzleMagazines", "_ammoType", "_initSpeed", "_ammoConfig", "_caliber", "_parentClasses"];
2015-04-20 07:18:46 +00:00
_vehAttenuation = if ((ACE_player == (vehicle ACE_player)) || {isTurnedOut ACE_player}) then {1} else {GVAR(playerVehAttenuation)};
2015-06-13 16:42:09 +00:00
_distance = 1 max _distance;
2015-04-11 03:16:33 +00:00
2015-08-13 21:42:20 +00:00
_silencer = call {
2015-08-13 22:31:42 +00:00
if (_weapon == primaryWeapon _firer) exitWith {(primaryWeaponItems _firer) select 0};
if (_weapon == secondaryWeapon _firer) exitWith {(secondaryWeaponItems _firer) select 0};
if (_weapon == handgunWeapon _firer) exitWith {(handgunItems _firer) select 0};
2015-08-13 21:42:20 +00:00
""
};
_audibleFireCoef = 1;
if (_silencer != "") then {
2015-03-15 21:40:47 +00:00
_audibleFireCoef = getNumber (configFile >> "CfgWeapons" >> _silencer >> "ItemInfo" >> "AmmoCoef" >> "audibleFire");
};
2015-06-13 17:12:24 +00:00
_weaponMagazines = missionNamespace getVariable [format[QEGVAR(common,weaponMagazines_%1),_weapon], []];
2015-06-13 16:57:02 +00:00
if (count _weaponMagazines == 0) then {
_muzzles = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles");
_weaponMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");
{
if (_x != "this") then {
_muzzleMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> _x >> "magazines");
_weaponMagazines append _muzzleMagazines;
};
2015-08-13 21:42:20 +00:00
} count _muzzles;
2015-06-18 09:56:58 +00:00
{
_ammoType = getText(configFile >> "CfgMagazines" >> _x >> "ammo");
_weaponMagazines set [_forEachIndex, [_x, _ammoType]];
} forEach _weaponMagazines;
2015-06-13 17:12:24 +00:00
missionNamespace setVariable [format[QEGVAR(common,weaponMagazines_%1),_weapon], _weaponMagazines];
2015-06-13 16:57:02 +00:00
};
_magazine = "";
{
2015-08-13 22:31:42 +00:00
_x params ["_magazineType", "_ammoType"];
if (_ammoType == _ammo) exitWith {
2015-06-18 09:56:58 +00:00
_magazine = _magazineType;
};
2015-08-13 21:42:20 +00:00
} count _weaponMagazines;
if (_magazine == "") exitWith {};
2015-06-13 15:16:18 +00:00
_initSpeed = getNumber(configFile >> "CfgMagazines" >> _magazine >> "initSpeed");
_ammoConfig = (configFile >> "CfgAmmo" >> _ammo);
_parentClasses = [_ammoConfig, true] call BIS_fnc_returnParents;
_caliber = getNumber(_ammoConfig >> "ACE_caliber");
2015-08-13 21:42:20 +00:00
_caliber = call {
if ("ShellBase" in _parentClasses) exitWith { 80 };
if ("RocketBase" in _parentClasses) exitWith { 200 };
if ("MissileBase" in _parentClasses) exitWith { 600 };
if ("SubmunitionBase" in _parentClasses) exitWith { 80 };
if (_caliber <= 0) then { 6.5 } else { _caliber };
};
2015-06-13 15:16:18 +00:00
_loudness = (_caliber ^ 1.25 / 10) * (_initspeed / 1000) * _audibleFireCoef / 5;
_strength = _vehAttenuation * (_loudness - (_loudness / 50 * _distance)); // linear drop off
2015-06-13 17:01:40 +00:00
//systemChat format["%1 : %2 : %3", _strength, _initSpeed, _parentClasses];
//systemChat format["%1 : %2 : %3", _weapon, _magazine, _initSpeed];
if (_strength < 0.01) exitWith {};
2015-04-11 03:16:33 +00:00
[{_this call FUNC(earRinging)}, [ACE_player, _strength], 0.2, 0] call EFUNC(common,waitAndExecute);