From f15eabdc7b0763f91ab8f07bf9af790790debc1d Mon Sep 17 00:00:00 2001 From: Hypoxic Date: Thu, 30 May 2024 00:06:26 -0400 Subject: [PATCH 1/2] Added "turretOpticsMode" player event handler Adds a player event handler to detect when the player changes turret zoom (FOV)- --- addons/events/fnc_addPlayerEventHandler.sqf | 36 +++++++++++++-------- addons/events/fnc_playerEvent.sqf | 9 ++++-- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/addons/events/fnc_addPlayerEventHandler.sqf b/addons/events/fnc_addPlayerEventHandler.sqf index 7e3aebc741..7fd5b1b293 100644 --- a/addons/events/fnc_addPlayerEventHandler.sqf +++ b/addons/events/fnc_addPlayerEventHandler.sqf @@ -6,20 +6,21 @@ Description: Adds a player event handler. Possible events: - "unit" - player controlled unit changed - "weapon" - currently selected weapon change - "turretweapon" - currently selected turret weapon change - "muzzle" - currently selected muzzle change - "weaponMode" - currently selected weapon mode change - "loadout" - players loadout changed - "vehicle" - players current vehicle changed - "turret" - position in vehicle changed - "visionMode" - player changed to normal/night/thermal view - "cameraView" - camera mode changed ("Internal", "External", "Gunner" etc.) - "featureCamera" - camera changed (Curator, Arsenal, Spectator etc.) - "visibleMap" - opened or closed map - "group" - player group changes - "leader" - leader of player changes + "unit" - player controlled unit changed + "weapon" - currently selected weapon change + "turretweapon" - currently selected turret weapon change + "muzzle" - currently selected muzzle change + "weaponMode" - currently selected weapon mode change + "loadout" - players loadout changed + "vehicle" - players current vehicle changed + "turret" - position in vehicle changed + "turretOpticsMode" - turret zoom (FOV) changed + "visionMode" - player changed to normal/night/thermal view + "cameraView" - camera mode changed ("Internal", "External", "Gunner" etc.) + "featureCamera" - camera changed (Curator, Arsenal, Spectator etc.) + "visibleMap" - opened or closed map + "group" - player group changes + "leader" - leader of player changes Parameters: _type - Event handler type. @@ -103,6 +104,12 @@ private _id = switch (_type) do { }; [QGVAR(turretEvent), _function] call CBA_fnc_addEventHandler // return id }; + case "turretopticsmode": { + if (_applyRetroactively) then { + [GVAR(oldUnit), getTurretOpticsMode GVAR(oldUnit)] call _function; + }; + [QGVAR(turretOpticsModeEvent), _function] call CBA_fnc_addEventHandler; + }; case "visionmode": { if (_applyRetroactively) then { [GVAR(oldUnit), currentVisionMode GVAR(oldUnit), -1] call _function; @@ -158,6 +165,7 @@ if (_id != -1) then { GVAR(oldLoadoutNoAmmo) = []; GVAR(oldVehicle) = objNull; GVAR(oldTurret) = []; + GVAR(oldTurretOpticsMode) = -1; GVAR(oldVisionMode) = -1; GVAR(oldCameraView) = ""; GVAR(oldFeatureCamera) = ""; diff --git a/addons/events/fnc_playerEvent.sqf b/addons/events/fnc_playerEvent.sqf index 4bb8011f47..f3c35adabf 100644 --- a/addons/events/fnc_playerEvent.sqf +++ b/addons/events/fnc_playerEvent.sqf @@ -44,7 +44,7 @@ private _state = [ _unit, group _unit, leader _unit, currentWeapon _unit, currentMuzzle _unit, currentWeaponMode _unit, getUnitLoadout _unit, _vehicle, _turret, _vehicle currentWeaponTurret _turret, - currentVisionMode _controlledEntity, cameraView + currentVisionMode _controlledEntity, cameraView, getTurretOpticsMode _unit ]; if (_state isNotEqualTo GVAR(oldState)) then { @@ -54,7 +54,7 @@ if (_state isNotEqualTo GVAR(oldState)) then { "", "_newGroup", "_newLeader", "_newWeapon", "_newMuzzle", "_newWeaponMode", "_newLoadout", "", "", "_newTurretWeapon", - "_newVisionMode", "_newCameraView" + "_newVisionMode", "_newCameraView", "_newTurretOpticsMode" ]; // These events should fire if the context of the state has changed. @@ -137,4 +137,9 @@ if (_state isNotEqualTo GVAR(oldState)) then { [QGVAR(cameraViewEvent), [_unit, _newCameraView, GVAR(oldCameraView)]] call CBA_fnc_localEvent; GVAR(oldCameraView) = _newCameraView; // This assignment may be returned. }; + + if (_newTurretOpticsMode isNotEqualTo GVAR(oldTurretOpticsMode)) then { + [QGVAR(turretOpticsModeEvent), [_unit, _newTurretOpticsMode, GVAR(oldTurretOpticsMode)]] call CBA_fnc_localEvent; + GVAR(oldTurretOpticsMode) = _newTurretOpticsMode; + }; }; From b328751a5e34e40b0cc8debba753da5b65509859 Mon Sep 17 00:00:00 2001 From: Hypoxic <60307173+hypoxia125@users.noreply.github.com> Date: Thu, 30 May 2024 00:31:22 -0400 Subject: [PATCH 2/2] Update addons/events/fnc_addPlayerEventHandler.sqf Co-authored-by: PabstMirror --- addons/events/fnc_addPlayerEventHandler.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/events/fnc_addPlayerEventHandler.sqf b/addons/events/fnc_addPlayerEventHandler.sqf index 7fd5b1b293..7f7c3d83be 100644 --- a/addons/events/fnc_addPlayerEventHandler.sqf +++ b/addons/events/fnc_addPlayerEventHandler.sqf @@ -106,7 +106,7 @@ private _id = switch (_type) do { }; case "turretopticsmode": { if (_applyRetroactively) then { - [GVAR(oldUnit), getTurretOpticsMode GVAR(oldUnit)] call _function; + [GVAR(oldUnit), getTurretOpticsMode GVAR(oldUnit), -1] call _function; }; [QGVAR(turretOpticsModeEvent), _function] call CBA_fnc_addEventHandler; };