Handle Vehicle Attunation

This commit is contained in:
PabstMirror 2015-04-10 23:21:54 -05:00
parent dac3047fca
commit 0edcf03e12
4 changed files with 66 additions and 2 deletions

View File

@ -5,3 +5,8 @@ GVAR(newStrength) = 0;
// Spawn volume updating process // Spawn volume updating process
[FUNC(updateVolume), 0.1, [] ] call CBA_fnc_addPerFrameHandler; [FUNC(updateVolume), 0.1, [] ] call CBA_fnc_addPerFrameHandler;
GVAR(playerVehAttunation) = 1;
["playerVehicleChanged", {_this call FUNC(updatePlayerVehicleAttunation);}] call EFUNC(common,addEventHandler);
["playerTurretChanged", {_this call FUNC(updatePlayerVehicleAttunation);}] call EFUNC(common,addEventHandler);

View File

@ -10,6 +10,7 @@ PREP(hasEarPlugsIn);
PREP(moduleHearing); PREP(moduleHearing);
PREP(putInEarPlugs); PREP(putInEarPlugs);
PREP(removeEarPlugs); PREP(removeEarPlugs);
PREP(updatePlayerVehicleAttunation);
PREP(updateVolume); PREP(updateVolume);
ADDON = true; ADDON = true;

View File

@ -30,7 +30,8 @@ if (!GVAR(enableCombatDeafness)) exitWith {};
//Only run if firedNear object is player or player's vehicle: //Only run if firedNear object is player or player's vehicle:
if ((ACE_player != (_this select 0)) && {(vehicle ACE_player) != (_this select 0)}) exitWith {}; if ((ACE_player != (_this select 0)) && {(vehicle ACE_player) != (_this select 0)}) exitWith {};
if (_weapon in ["Throw", "Put"]) exitWith {}; if (_weapon in ["Throw", "Put"]) exitWith {};
if (_unit != vehicle _unit && {!([_unit] call EFUNC(common,isTurnedOut))}) exitWith {};
_attenuation = if ((ACE_player == (vehicle ACE_player)) || {isTurnedOut ACE_player}) then {1} else {GVAR(playerVehAttunation)};
if (_distance < 1) then {_distance = 1;}; if (_distance < 1) then {_distance = 1;};
@ -52,7 +53,7 @@ _audibleFire = getNumber (configFile >> "CfgAmmo" >> _ammo >> "audibleFire");
//_audibleFireTime = getNumber (configFile >> "CfgAmmo" >> _ammo >> "audibleFireTime"); //_audibleFireTime = getNumber (configFile >> "CfgAmmo" >> _ammo >> "audibleFireTime");
_loudness = _audibleFireCoef * _audibleFire / 64; _loudness = _audibleFireCoef * _audibleFire / 64;
_strength = _loudness - (_loudness/50 * _distance); // linear drop off _strength = _attenuation * (_loudness - (_loudness/50 * _distance)); // linear drop off
if (_strength < 0.01) exitWith {}; if (_strength < 0.01) exitWith {};

View File

@ -0,0 +1,57 @@
/*
* Author: PabstMirror
* Gets the sound attunation of a player to the outside.
*
* Arguments:
* 0: Unit (player) <OBJECT>
*
* Return Value:
* Ammount that unit can hear outside <NUMBER>
*
* Example:
* [] call ace_hearing_fnc_updatePlayerVehicleAttunation
*
* Public: No
*/
#include "script_component.hpp"
_vehicle = vehicle ACE_player;
if (isNull _vehicle) exitWith {};
_newAttenuation = -1;
if (ACE_player == _vehicle) then {
_newAttenuation = 1;
} else {
_effectType = "";
_turretPath = [ACE_player] call EFUNC(common,getTurretIndex);
systemChat format ["_turretPath %1", _turretPath];
_effectType = getText (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "attenuationEffectType");
systemChat format ["Veh EffectType %1", _effectType];
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.7};
case (_effectType == "OpenCarAttenuation"): {1};
case (_effectType == "TankAttenuation"): {0.1};
case (_effectType == "HeliAttenuation"): {0.25};
case (_effectType == "OpenHeliAttenuation"): {0.7};
case (_effectType == "SemiOpenHeliAttenuation"): {0.5};
case (_effectType == "HeliAttenuationGunner"): {0.75};
case (_effectType == "HeliAttenuationRamp"): {0.75};
default {1};
};
};
GVAR(playerVehAttunation) = _newAttenuation;