Use SlotItemChanged

This commit is contained in:
johnb432 2024-05-28 21:52:47 +02:00
parent be9797d11d
commit e99e8ee8eb
5 changed files with 26 additions and 12 deletions

View File

@ -67,10 +67,16 @@ GVAR(lastPlayerVehicle) = objNull;
private _firedEH = _oldPlayer getVariable [QGVAR(firedEH), -1];
_oldPlayer removeEventHandler ["FiredNear", _firedEH];
_oldPlayer setVariable [QGVAR(firedEH), nil];
private _explosionEH = _oldPlayer getVariable [QGVAR(explosionEH), -1];
_oldPlayer removeEventHandler ["Explosion", _explosionEH];
_oldPlayer setVariable [QGVAR(explosionEH), nil];
TRACE_3("removed unit eh",_oldPlayer,_firedEH,_explosionEH);
private _slotItemChangedEH = _oldPlayer getVariable [QGVAR(slotItemChangedEH), -1];
_oldPlayer removeEventHandler ["SlotItemChanged", _slotItemChangedEH];
_oldPlayer setVariable [QGVAR(slotItemChangedEH), nil];
TRACE_4("removed unit eh",_oldPlayer,_firedEH,_explosionEH,_slotItemChangedEH);
};
// Don't add a new EH if the unit respawned
if ((_player getVariable [QGVAR(firedEH), -1]) == -1) then {
@ -79,17 +85,20 @@ GVAR(lastPlayerVehicle) = objNull;
};
private _firedEH = _player addEventHandler ["FiredNear", {call FUNC(firedNear)}];
_player setVariable [QGVAR(firedEH), _firedEH];
private _explosionEH = _player addEventHandler ["Explosion", {call FUNC(explosionNear)}];
_player setVariable [QGVAR(explosionEH), _explosionEH];
TRACE_3("added unit eh",_player,_firedEH,_explosionEH);
// Update protection on possible helmet change
private _slotItemChangedEH = _player addEventHandler ["SlotItemChanged", {(_this select 2) call FUNC(updateHearingProtection)}];
_player setVariable [QGVAR(slotItemChangedEH), _slotItemChangedEH];
TRACE_4("added unit eh",_player,_firedEH,_explosionEH,_slotItemChangedEH);
};
GVAR(deafnessDV) = 0;
GVAR(deafnessPrior) = 0;
GVAR(time3) = 0;
[] call FUNC(updateHearingProtection);
UPDATE_HEARING_EARPLUGS call FUNC(updateHearingProtection);
}, true] call CBA_fnc_addPlayerEventHandler;
// Update protection on possible helmet change
["loadout", LINKFUNC(updateHearingProtection), false] call CBA_fnc_addPlayerEventHandler;
}] call CBA_fnc_addEventHandler;

View File

@ -35,4 +35,4 @@ if (_displayHint) then {
// No Earplugs in inventory, telling user
//[localize LSTRING(NoPlugs)] call EFUNC(common,displayTextStructured);
[] call FUNC(updateHearingProtection);
UPDATE_HEARING_EARPLUGS call FUNC(updateHearingProtection);

View File

@ -36,4 +36,4 @@ if (_displayHint) then {
//Force an immediate fast volume update:
[[true]] call FUNC(updateVolume);
[] call FUNC(updateHearingProtection);
UPDATE_HEARING_EARPLUGS call FUNC(updateHearingProtection);

View File

@ -4,24 +4,27 @@
* Updates the hearing protection and volume attenuation for player on earbuds/helmet change
*
* Arguments:
* None
* 0: Slot <NUMBER>
*
* Return Value:
* None
*
* Example:
* [] call ace_hearing_fnc_updateHearingProtection
* UPDATE_HEARING_EARPLUGS call ace_hearing_fnc_updateHearingProtection
*
* Public: No
*/
TRACE_1("params",_this);
if (isNull ACE_player) exitWith {
GVAR(damageCoefficent) = 0;
GVAR(volumeAttenuation) = 1;
};
params ["_slot"];
TRACE_1("",_slot);
if !(_slot in [UPDATE_HEARING_EARPLUGS, TYPE_GOGGLE, TYPE_HEADGEAR]) exitWith {};
// Handle Earplugs
private _hasEarPlugsIn = [ACE_player] call FUNC(hasEarPlugsIn);
GVAR(damageCoefficent) = [1, 0.25] select _hasEarPlugsIn;

View File

@ -16,3 +16,5 @@
#include "\z\ace\addons\main\script_macros.hpp"
#include "\z\ace\addons\hearing\script_macros_hearingProtection.hpp"
#defined UPDATE_HEARING_EARPLUGS -1