ACE3/addons/hearing/functions/fnc_earRinging.sqf

93 lines
2.5 KiB
Plaintext
Raw Normal View History

/*
2015-06-13 15:16:18 +00:00
* Author: KoffeinFlummi, commy2, Rocko, Rommel, Ruthberg
* Ear ringing PFH
*
* Arguments:
2015-06-13 15:16:18 +00:00
* 0: unit <OBJECT>
2015-03-15 21:40:47 +00:00
* 1: strength of ear ringing (Number between 0 and 1) <NUMBER>
*
* Return Value:
2015-03-15 21:40:47 +00:00
* None
*
* Example:
2015-06-13 15:16:18 +00:00
* [_unit, _strength] call ace_hearing_fnc_earRinging
2015-03-15 21:40:47 +00:00
*
* Public: No
*/
2015-01-14 01:41:53 +00:00
#include "script_component.hpp"
2015-06-13 15:16:18 +00:00
if (GVAR(DisableEarRinging)) exitWith {};
PARAMS_2(_unit,_strength);
2015-06-13 15:16:18 +00:00
if (isNull _unit) exitWith {};
if (_strength < 0.05) exitWith {};
2015-01-13 04:17:52 +00:00
if (_unit getVariable ["ACE_hasEarPlugsin", false]) then {
2015-03-15 21:40:47 +00:00
_strength = _strength / 4;
};
2015-06-13 15:16:18 +00:00
_unit setVariable [QGVAR(dv), (_unit getVariable [QGVAR(dv), 0]) + _strength];
2015-06-13 15:16:18 +00:00
if (GVAR(earRingingPFH) != -1) exitWith {};
2015-06-13 15:16:18 +00:00
GVAR(earRingingPFH) = [{
EXPLODE_1_PVT(_this select 0,_unit);
private ["_prior"];
_prior = (_unit getvariable [QGVAR(dv), 0]) min 20;
2015-06-13 15:23:45 +00:00
2015-06-13 15:16:18 +00:00
if (!alive _unit || _prior <= 0) exitWith {
_unit setVariable [QGVAR(dv), 0];
_unit setVariable [QGVAR(prior), 0];
GVAR(beep) = false;
GVAR(beep2) = false;
GVAR(time2) = 0;
GVAR(time3) = 0;
GVAR(time4) = 0;
GVAR(earRingingPFH) = -1;
[_this select 1] call cba_fnc_removePerFrameHandler;
};
if (((_unit getvariable [QGVAR(dv), 0]) - (_unit getvariable [QGVAR(prior), 0])) > 2) then {
if (ACE_time > GVAR(time3)) then {
GVAR(beep2) = false;
};
if (!GVAR(beep2)) then {
playSound "ACE_Combat_Deafness";
GVAR(beep2) = true;
GVAR(time3) = ACE_time + 5;
};
};
_unit setvariable [QGVAR(prior), _prior];
GVAR(volume) = (1 - (_prior / 20)) max 0;
if (_prior > 19.75) then {
_unit setvariable [QGVAR(deaf), true];
} else {
_unit setvariable [QGVAR(deaf), false];
};
if ((_unit getvariable [QGVAR(deaf), false]) && {ACE_time > GVAR(time4)}) then {
playSound "ACE_Combat_Deafness";
GVAR(beep2) = true;
GVAR(time3) = ACE_time + 10;
GVAR(time4) = ACE_time + 30;
};
2015-01-14 02:34:55 +00:00
2015-06-13 15:16:18 +00:00
// Hearing takes longer to return to normal after it hits rock bottom
_unit setvariable [QGVAR(dv), _prior - (0.5 * (GVAR(volume) max 0.1))];
if (_prior > 10) then {
//check if the ringing is already being played
if (ACE_time > GVAR(time2)) then {
GVAR(beep) = false;
};
if (!GVAR(beep)) then {
playSound "ACE_Ring_Backblast";
GVAR(time2) = ACE_time + 22;
GVAR(beep) = true;
};
};
}, 1, [_unit]] call CBA_fnc_addPerFrameHandler;