mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #464 from acemod/fixFiredNear
Hearing: Fix firedNear not working in vehicles
This commit is contained in:
commit
2d3606302f
@ -1,4 +1,3 @@
|
||||
|
||||
class Extended_PreInit_EventHandlers {
|
||||
class ADDON {
|
||||
init = QUOTE(call COMPILE_FILE(XEH_preInit) );
|
||||
@ -20,9 +19,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););
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -1,7 +1,14 @@
|
||||
#include "script_component.hpp"
|
||||
|
||||
if (!hasInterface) exitWith {};
|
||||
|
||||
GVAR(currentDeafness) = 0;
|
||||
GVAR(newStrength) = 0;
|
||||
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(updatePlayerVehAttenuation);}] call EFUNC(common,addEventHandler);
|
||||
["playerTurretChanged", {_this call FUNC(updatePlayerVehAttenuation);}] call EFUNC(common,addEventHandler);
|
||||
|
@ -10,6 +10,7 @@ PREP(hasEarPlugsIn);
|
||||
PREP(moduleHearing);
|
||||
PREP(putInEarPlugs);
|
||||
PREP(removeEarPlugs);
|
||||
PREP(updatePlayerVehAttenuation);
|
||||
PREP(updateVolume);
|
||||
|
||||
ADDON = true;
|
||||
|
@ -21,18 +21,19 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_unit", "_firer", "_distance", "_weapon", "_muzzle", "_mode", "_ammo", "_silencer", "_audibleFireCoef", "_loudness", "_strength", "_audibleFire", "_audibleFireTime", "_audibleFireTimeCoef"];
|
||||
private ["_silencer", "_audibleFireCoef", "_loudness", "_strength", "_vehAttenuation"];
|
||||
|
||||
_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);
|
||||
|
||||
if (toLower _weapon in ["throw", "put"]) exitWith {};
|
||||
if (_unit != vehicle _unit && {!([_unit] call EFUNC(common,isTurnedOut))}) exitWith {};
|
||||
//Only run if combatDeafness enabled:
|
||||
if (!GVAR(enableCombatDeafness)) exitWith {};
|
||||
//Only run if firedNear object is player or player's vehicle:
|
||||
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(playerVehAttenuation)};
|
||||
|
||||
if (_distance < 1) then {_distance = 1;};
|
||||
|
||||
_silencer = switch (_weapon) do {
|
||||
case (primaryWeapon _firer) : {(primaryWeaponItems _firer) select 0};
|
||||
@ -42,18 +43,15 @@ _silencer = switch (_weapon) do {
|
||||
};
|
||||
|
||||
_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 = _loudness - (_loudness/50 * _distance); // linear drop off
|
||||
_strength = _vehAttenuation * (_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);
|
||||
|
57
addons/hearing/functions/fnc_updatePlayerVehAttenuation.sqf
Normal file
57
addons/hearing/functions/fnc_updatePlayerVehAttenuation.sqf
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Gets the sound attenuation of a player to the outside.
|
||||
*
|
||||
* Arguments:
|
||||
* None
|
||||
*
|
||||
* Return Value:
|
||||
* Ammount that unit can hear outside <NUMBER>
|
||||
*
|
||||
* Example:
|
||||
* [] call ace_hearing_fnc_updatePlayerVehAttenuation
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
_vehicle = vehicle ACE_player;
|
||||
|
||||
if (isNull _vehicle) exitWith {};
|
||||
|
||||
_newAttenuation = 1;
|
||||
if (ACE_player != _vehicle) then {
|
||||
_effectType = "";
|
||||
_turretPath = [ACE_player] call EFUNC(common,getTurretIndex);
|
||||
_effectType = getText (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "attenuationEffectType");
|
||||
|
||||
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.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};
|
||||
};
|
||||
};
|
||||
|
||||
TRACE_2("New vehicle attenuation",_vehicle,_newAttenuation);
|
||||
|
||||
GVAR(playerVehAttenuation) = _newAttenuation;
|
Loading…
Reference in New Issue
Block a user