Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hearing - Use SlotItemChanged event #10040

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 5 additions & 25 deletions addons/hearing/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ GVAR(lastPlayerVehicle) = objNull;
};

if ((!isNull _vehicle) && {_player != _vehicle}) then {
private _firedEH = _vehicle addEventHandler ["FiredNear", {call FUNC(firedNear)}];
private _firedEH = _vehicle addEventHandler ["FiredNear", LINKFUNC(firedNear)];
_vehicle setVariable [QGVAR(firedEH), _firedEH];
GVAR(lastPlayerVehicle) = _vehicle;
TRACE_2("added veh eh",_firedEH,GVAR(lastPlayerVehicle));
Expand All @@ -80,35 +80,15 @@ GVAR(lastPlayerVehicle) = objNull;

["turret", LINKFUNC(updatePlayerVehAttenuation), false] call CBA_fnc_addPlayerEventHandler;

[QGVAR(firedNear), "FiredNear", LINKFUNC(firedNear), true] call EFUNC(common,addPlayerEH);
[QGVAR(slotItemChanged), "SlotItemChanged", {(_this select 2) call FUNC(updateHearingProtection)}, true] call EFUNC(common,addPlayerEH);

// Reset deafness on respawn (or remote control player switch)
["unit", {
params ["_player", "_oldPlayer"];
TRACE_2("unit change",_player,_oldPlayer);

if (!isNull _oldPlayer) then {
private _firedEH = _oldPlayer getVariable [QGVAR(firedEH), -1];
_oldPlayer removeEventHandler ["FiredNear", _firedEH];
_oldPlayer setVariable [QGVAR(firedEH), nil];
TRACE_2("removed unit eh",_oldPlayer,_firedEH);
};
// Don't add a new EH if the unit respawned
if ((_player getVariable [QGVAR(firedEH), -1]) == -1) then {
if ((getNumber (configOf _player >> "isPlayableLogic")) == 1) exitWith {
TRACE_1("skipping playable logic",typeOf _player); // VirtualMan_F (placeable logic zeus / spectator)
};

private _firedEH = _player addEventHandler ["FiredNear", {call FUNC(firedNear)}];
_player setVariable [QGVAR(firedEH), _firedEH];
TRACE_2("added unit eh",_player,_firedEH);
};

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;
2 changes: 1 addition & 1 deletion addons/hearing/functions/fnc_putInEarplugs.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ if (_displayHint) then {
// Force an immediate volume update
true call FUNC(updateVolume);

call FUNC(updateHearingProtection);
UPDATE_HEARING_EARPLUGS call FUNC(updateHearingProtection);
2 changes: 1 addition & 1 deletion addons/hearing/functions/fnc_removeEarplugs.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ if (_displayHint) then {
// Force an immediate volume update
true call FUNC(updateVolume);

call FUNC(updateHearingProtection);
UPDATE_HEARING_EARPLUGS call FUNC(updateHearingProtection);
9 changes: 7 additions & 2 deletions addons/hearing/functions/fnc_updateHearingProtection.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* 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
*/
Expand All @@ -22,6 +22,11 @@ if (isNull ACE_player) exitWith {
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;
Expand Down
2 changes: 2 additions & 0 deletions addons/hearing/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@

#include "\z\ace\addons\main\script_macros.hpp"
#include "\z\ace\addons\hearing\script_macros_hearingProtection.hpp"

#define UPDATE_HEARING_EARPLUGS -1
Loading