From 6d5211874f7e14768976fb0e04f0bf3fb2ce66e6 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Tue, 16 Jul 2024 20:17:50 +0200 Subject: [PATCH 1/6] Improve persistent lasers --- .../functions/fnc_switchPersistentLaser.sqf | 112 ++++++++++++------ 1 file changed, 78 insertions(+), 34 deletions(-) diff --git a/addons/common/functions/fnc_switchPersistentLaser.sqf b/addons/common/functions/fnc_switchPersistentLaser.sqf index a2b7b9c1a8d..0dfbbca7f97 100644 --- a/addons/common/functions/fnc_switchPersistentLaser.sqf +++ b/addons/common/functions/fnc_switchPersistentLaser.sqf @@ -1,6 +1,6 @@ #include "..\script_component.hpp" /* - * Author: Dystopian + * Author: Dystopian, johnb43 * Controls persistent laser state. * * Arguments: @@ -17,51 +17,95 @@ params ["_enabled"]; +// Reset state +{ + ACE_player setVariable [QGVAR(laserEnabled_) + str _x, nil]; +} forEach [0, 1, 2]; + if (!_enabled) exitWith { if (isNil QGVAR(laserKeyDownEH)) exitWith {}; - ["KeyDown", GVAR(laserKeyDownEH)] call CBA_fnc_removeDisplayHandler; + + removeUserActionEventHandler ["headlights", "Activate", GVAR(laserKeyDownEH)]; + ["loadout", GVAR(laserLoadoutEH)] call CBA_fnc_removePlayerEventHandler; ["turret", GVAR(laserTurretEH)] call CBA_fnc_removePlayerEventHandler; ["vehicle", GVAR(laserVehicleEH)] call CBA_fnc_removePlayerEventHandler; ["weapon", GVAR(laserWeaponEH)] call CBA_fnc_removePlayerEventHandler; }; -GVAR(laserKeyDownEH) = ["KeyDown", { - if !((_this select 1) in actionKeys "headlights") exitWith {false}; - private _weapon = currentWeapon ACE_player; +private _fnc_getLightLaserState = { + private _currentWeapon = currentWeapon ACE_player; + + if (_currentWeapon == "") exitWith {}; + + // Ignore in vehicle except FFV + if !(ACE_player call CBA_fnc_canUseWeapon) exitWith {}; + + // Light/laser state only changes in the next frame + [{ + ACE_player setVariable [ + QGVAR(laserEnabled_) + str ([ACE_player, _this] call FUNC(getWeaponIndex)), + ACE_player isIRLaserOn _this || {ACE_player isFlashlightOn _this} + ]; + }, _currentWeapon] call CBA_fnc_execNextFrame; +}; + +// Get current weapon light/laser state +call _fnc_getLightLaserState; + +// Update state every time it's changed +GVAR(laserKeyDownEH) = addUserActionEventHandler ["headlights", "Activate", _fnc_getLightLaserState]; + +private _fnc_lightLaserEH = { + params ["_unit"]; + + if !(_unit call CBA_fnc_canUseWeapon) exitWith {}; + + // Save current weapon state to reapply later + private _weaponState = (weaponState _unit) select [0, 3]; + + if (_weaponState select 0 == "") exitWith {}; + + // Turn off old light/laser + action ["GunLightOff", _unit]; + action ["IRLaserOff", _unit]; + + // Light/laser is off + if !(_unit getVariable ["ace_common_laserEnabled_" + str ([_unit, _weaponState select 0] call EFUNC(common,getWeaponIndex)), false]) exitWith { + _unit selectWeapon _weaponState; + }; + + private _fnc_turnOnLightLaser = { + params ["_unit", "_weaponState"]; + + if (currentWeapon _unit != _weaponState select 0) exitWith {}; + + action ["GunLightOn", _unit]; + action ["IRLaserOn", _unit]; + + _unit selectWeapon _weaponState; + }; + [ + // Wait for weapon in "ready to fire" direction + // If the unit changes weapons during the transition, let weapon EH handle it { - params ["_weapon", "_laserWasEnabled"]; - private _laserEnabled = ACE_player isIRLaserOn _weapon || {ACE_player isFlashlightOn _weapon}; - if (_laserEnabled && {_laserWasEnabled} || {!_laserEnabled && {!_laserWasEnabled}}) exitWith {}; - private _weaponIndex = [ACE_player, _weapon] call FUNC(getWeaponIndex); - ACE_player setVariable [QGVAR(laserEnabled_) + str _weaponIndex, [nil, true] select _laserEnabled]; + params ["_unit", "_weaponState"]; + + private _currentWeapon = currentWeapon _unit; + + _currentWeapon != _weaponState select 0 || + {0.01 > (getCameraViewDirection _unit) vectorDistance (_unit weaponDirection _currentWeapon)} }, - [_weapon, ACE_player isIRLaserOn _weapon || {ACE_player isFlashlightOn _weapon}] - ] call CBA_fnc_execNextFrame; - false -}] call CBA_fnc_addDisplayHandler; - -private _laserEH = { - if (sunOrMoon == 1) exitWith {}; - params ["_player"]; - private _weaponIndex = [_player, currentWeapon _player] call FUNC(getWeaponIndex); - if ( - !(_player getVariable [QGVAR(laserEnabled_) + str _weaponIndex, false]) - || {_weaponIndex > 0 && {"" != primaryWeapon _player}} // Arma switches to primary weapon if exists - || {!(_player call CBA_fnc_canUseWeapon)} // ignore in vehicle except FFV - ) exitWith {}; - [ - // wait for weapon in "ready to fire" direction - {0.01 > getCameraViewDirection _this vectorDistance (_this weaponDirection currentWeapon _this)}, - {{_this action [_x, _this]} forEach ["GunLightOn", "IRLaserOn"]}, - _player, + _fnc_turnOnLightLaser, + [_unit, _weaponState], 3, - {{_this action [_x, _this]} forEach ["GunLightOn", "IRLaserOn"]} + _fnc_turnOnLightLaser ] call CBA_fnc_waitUntilAndExecute; }; -GVAR(laserLoadoutEH) = ["loadout", _laserEH] call CBA_fnc_addPlayerEventHandler; -GVAR(laserTurretEH) = ["turret", _laserEH] call CBA_fnc_addPlayerEventHandler; -GVAR(laserVehicleEH) = ["vehicle", _laserEH] call CBA_fnc_addPlayerEventHandler; -GVAR(laserWeaponEH) = ["weapon", _laserEH] call CBA_fnc_addPlayerEventHandler; +// Dropping weapons turns off lights/lasers +GVAR(laserLoadoutEH) = ["loadout", _fnc_lightLaserEH] call CBA_fnc_addPlayerEventHandler; +GVAR(laserTurretEH) = ["turret", _fnc_lightLaserEH] call CBA_fnc_addPlayerEventHandler; +GVAR(laserVehicleEH) = ["vehicle", _fnc_lightLaserEH] call CBA_fnc_addPlayerEventHandler; +GVAR(laserWeaponEH) = ["weapon", _fnc_lightLaserEH] call CBA_fnc_addPlayerEventHandler; From 8f815fd8b843a77fe521ed14a6bbe7f17c8549bf Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Wed, 17 Jul 2024 09:13:54 +0200 Subject: [PATCH 2/6] Update addons/common/functions/fnc_switchPersistentLaser.sqf Co-authored-by: PabstMirror --- addons/common/functions/fnc_switchPersistentLaser.sqf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/common/functions/fnc_switchPersistentLaser.sqf b/addons/common/functions/fnc_switchPersistentLaser.sqf index 0dfbbca7f97..560a3b85b93 100644 --- a/addons/common/functions/fnc_switchPersistentLaser.sqf +++ b/addons/common/functions/fnc_switchPersistentLaser.sqf @@ -43,8 +43,12 @@ private _fnc_getLightLaserState = { // Light/laser state only changes in the next frame [{ + private _weaponIndex = [ACE_player, _this] call FUNC(getWeaponIndex); + + if (_index == -1) exitWith {}; + ACE_player setVariable [ - QGVAR(laserEnabled_) + str ([ACE_player, _this] call FUNC(getWeaponIndex)), + QGVAR(laserEnabled_) + str _weaponIndex, ACE_player isIRLaserOn _this || {ACE_player isFlashlightOn _this} ]; }, _currentWeapon] call CBA_fnc_execNextFrame; From 5808107f4ccab70969e5c933c49a180940875df1 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Wed, 17 Jul 2024 15:28:46 +0200 Subject: [PATCH 3/6] Fix inventory changes toggling laser, removed alignment code --- addons/common/XEH_PREP.hpp | 1 + .../functions/fnc_switchPersistentLaser.sqf | 74 +++++-------------- .../functions/fnc_switchPersistentLaserEH.sqf | 48 ++++++++++++ 3 files changed, 69 insertions(+), 54 deletions(-) create mode 100644 addons/common/functions/fnc_switchPersistentLaserEH.sqf diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index 3a5838a230f..5fc1aa9aef4 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -190,6 +190,7 @@ PREP(stringCompare); PREP(stringToColoredText); PREP(swayLoop); PREP(switchPersistentLaser); +PREP(switchPersistentLaserEH); PREP(switchToGroupSide); PREP(throttledPublicVariable); PREP(toBin); diff --git a/addons/common/functions/fnc_switchPersistentLaser.sqf b/addons/common/functions/fnc_switchPersistentLaser.sqf index 560a3b85b93..8943a1b5d85 100644 --- a/addons/common/functions/fnc_switchPersistentLaser.sqf +++ b/addons/common/functions/fnc_switchPersistentLaser.sqf @@ -41,17 +41,17 @@ private _fnc_getLightLaserState = { // Ignore in vehicle except FFV if !(ACE_player call CBA_fnc_canUseWeapon) exitWith {}; + private _weaponIndex = [ACE_player, _currentWeapon] call FUNC(getWeaponIndex); + + if (_weaponIndex == -1) exitWith {}; + // Light/laser state only changes in the next frame [{ - private _weaponIndex = [ACE_player, _this] call FUNC(getWeaponIndex); - - if (_index == -1) exitWith {}; - ACE_player setVariable [ - QGVAR(laserEnabled_) + str _weaponIndex, - ACE_player isIRLaserOn _this || {ACE_player isFlashlightOn _this} + QGVAR(laserEnabled_) + str (_this select 1), + ACE_player isIRLaserOn (_this select 0) || {ACE_player isFlashlightOn (_this select 0)} ]; - }, _currentWeapon] call CBA_fnc_execNextFrame; + }, [_currentWeapon, _weaponIndex]] call CBA_fnc_execNextFrame; }; // Get current weapon light/laser state @@ -60,56 +60,22 @@ call _fnc_getLightLaserState; // Update state every time it's changed GVAR(laserKeyDownEH) = addUserActionEventHandler ["headlights", "Activate", _fnc_getLightLaserState]; -private _fnc_lightLaserEH = { - params ["_unit"]; - - if !(_unit call CBA_fnc_canUseWeapon) exitWith {}; - - // Save current weapon state to reapply later - private _weaponState = (weaponState _unit) select [0, 3]; - - if (_weaponState select 0 == "") exitWith {}; - - // Turn off old light/laser - action ["GunLightOff", _unit]; - action ["IRLaserOff", _unit]; - - // Light/laser is off - if !(_unit getVariable ["ace_common_laserEnabled_" + str ([_unit, _weaponState select 0] call EFUNC(common,getWeaponIndex)), false]) exitWith { - _unit selectWeapon _weaponState; - }; - - private _fnc_turnOnLightLaser = { - params ["_unit", "_weaponState"]; - - if (currentWeapon _unit != _weaponState select 0) exitWith {}; +// Dropping weapons turns off lights/lasers +GVAR(lastWeapons) = [primaryWeapon ACE_player, handgunWeapon ACE_player, secondaryWeapon ACE_player]; - action ["GunLightOn", _unit]; - action ["IRLaserOn", _unit]; +// Monitor weapon addition/removal here +GVAR(laserLoadoutEH) = ["loadout", { + params ["_unit"]; - _unit selectWeapon _weaponState; - }; + private _weapons = [primaryWeapon _unit, handgunWeapon _unit, secondaryWeapon _unit]; - [ - // Wait for weapon in "ready to fire" direction - // If the unit changes weapons during the transition, let weapon EH handle it - { - params ["_unit", "_weaponState"]; + if (_weapons isEqualTo GVAR(lastWeapons)) exitWith {}; - private _currentWeapon = currentWeapon _unit; + GVAR(lastWeapons) = _weapons; - _currentWeapon != _weaponState select 0 || - {0.01 > (getCameraViewDirection _unit) vectorDistance (_unit weaponDirection _currentWeapon)} - }, - _fnc_turnOnLightLaser, - [_unit, _weaponState], - 3, - _fnc_turnOnLightLaser - ] call CBA_fnc_waitUntilAndExecute; -}; + _unit call FUNC(switchPersistentLaserEH); +}] call CBA_fnc_addPlayerEventHandler; -// Dropping weapons turns off lights/lasers -GVAR(laserLoadoutEH) = ["loadout", _fnc_lightLaserEH] call CBA_fnc_addPlayerEventHandler; -GVAR(laserTurretEH) = ["turret", _fnc_lightLaserEH] call CBA_fnc_addPlayerEventHandler; -GVAR(laserVehicleEH) = ["vehicle", _fnc_lightLaserEH] call CBA_fnc_addPlayerEventHandler; -GVAR(laserWeaponEH) = ["weapon", _fnc_lightLaserEH] call CBA_fnc_addPlayerEventHandler; +GVAR(laserTurretEH) = ["turret", LINKFUNC(switchPersistentLaserEH)] call CBA_fnc_addPlayerEventHandler; +GVAR(laserVehicleEH) = ["vehicle", LINKFUNC(switchPersistentLaserEH)] call CBA_fnc_addPlayerEventHandler; +GVAR(laserWeaponEH) = ["weapon", LINKFUNC(switchPersistentLaserEH)] call CBA_fnc_addPlayerEventHandler; diff --git a/addons/common/functions/fnc_switchPersistentLaserEH.sqf b/addons/common/functions/fnc_switchPersistentLaserEH.sqf new file mode 100644 index 00000000000..98e8fab711e --- /dev/null +++ b/addons/common/functions/fnc_switchPersistentLaserEH.sqf @@ -0,0 +1,48 @@ +#include "..\script_component.hpp" +/* + * Author: johnb43 + * Toggles weapon light/laser to match persistent behaviour. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Example: + * player call ace_common_fnc_switchPersistentLaserEH + * + * Public: No + */ + +params ["_unit"]; + +if !(_unit call CBA_fnc_canUseWeapon) exitWith {}; + +// Save current weapon state to reapply later +private _weaponState = (weaponState _unit) select [0, 3]; + +if (_weaponState select 0 == "") exitWith {}; + +// Turn off old light/laser +action ["GunLightOff", _unit]; +action ["IRLaserOff", _unit]; + +// Light/laser is off +if !(_unit getVariable [QGVAR(laserEnabled_) + str ([_unit, _weaponState select 0] call EFUNC(common,getWeaponIndex)), false]) exitWith { + _unit selectWeapon _weaponState; +}; + +// Turn laser back on next frame (if weapon hasn't changed) +[{ + params ["_unit", "_weaponState"]; + + if (currentWeapon _unit != _weaponState select 0) exitWith {}; + + action ["GunLightOn", _unit]; + action ["IRLaserOn", _unit]; + + _unit selectWeapon _weaponState; +}, [_unit, _weaponState]] call CBA_fnc_execNextFrame; + +nil From 7e3275d99806018efbfcdf1b04a63cfadea86481 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Thu, 18 Jul 2024 07:07:35 +0200 Subject: [PATCH 4/6] Update addons/common/functions/fnc_switchPersistentLaser.sqf Co-authored-by: PabstMirror --- addons/common/functions/fnc_switchPersistentLaser.sqf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/common/functions/fnc_switchPersistentLaser.sqf b/addons/common/functions/fnc_switchPersistentLaser.sqf index 8943a1b5d85..9799b13ade9 100644 --- a/addons/common/functions/fnc_switchPersistentLaser.sqf +++ b/addons/common/functions/fnc_switchPersistentLaser.sqf @@ -17,6 +17,8 @@ params ["_enabled"]; +if (!hasInterface) exitwith {}; + // Reset state { ACE_player setVariable [QGVAR(laserEnabled_) + str _x, nil]; From fe71cbed05b30417a103a484cb8e2964c08a8d66 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Thu, 18 Jul 2024 09:23:18 +0200 Subject: [PATCH 5/6] Added API for setting weapon lights/lasers --- addons/common/XEH_PREP.hpp | 2 +- .../fnc_setWeaponLightLaserState.sqf | 59 +++++++++++++++++++ .../functions/fnc_switchPersistentLaser.sqf | 26 ++++++-- .../functions/fnc_switchPersistentLaserEH.sqf | 48 --------------- 4 files changed, 82 insertions(+), 53 deletions(-) create mode 100644 addons/common/functions/fnc_setWeaponLightLaserState.sqf delete mode 100644 addons/common/functions/fnc_switchPersistentLaserEH.sqf diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index 5fc1aa9aef4..d5f8a4484fb 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -177,6 +177,7 @@ PREP(setupLocalUnitsHandler); PREP(setVariableJIP); PREP(setVariablePublic); PREP(setVolume); +PREP(setWeaponLightLaserState); PREP(showHud); PREP(statusEffect_addType); PREP(statusEffect_get); @@ -190,7 +191,6 @@ PREP(stringCompare); PREP(stringToColoredText); PREP(swayLoop); PREP(switchPersistentLaser); -PREP(switchPersistentLaserEH); PREP(switchToGroupSide); PREP(throttledPublicVariable); PREP(toBin); diff --git a/addons/common/functions/fnc_setWeaponLightLaserState.sqf b/addons/common/functions/fnc_setWeaponLightLaserState.sqf new file mode 100644 index 00000000000..7f50573acb7 --- /dev/null +++ b/addons/common/functions/fnc_setWeaponLightLaserState.sqf @@ -0,0 +1,59 @@ +#include "..\script_component.hpp" +/* + * Author: johnb43 + * Toggles the unit's current weapon's light & laser. + * API for persistent lasers. Doesn't work on AI, as they have their own logic. + * + * Arguments: + * 0: Unit + * 1: Weapon light/laser state (default: false) + * + * Return Value: + * None + * + * Example: + * [player, true] call ace_common_fnc_setWeaponLightLaserState + * + * Public: Yes + */ + +params [["_unit", objNull, [objNull]], ["_state", false, [false]]]; + +if (!local _unit || {!alive _unit} || {!(_unit call FUNC(isPlayer))}) exitWith {}; + +if !(_unit call CBA_fnc_canUseWeapon) exitWith {}; + +private _currentWeapon = currentWeapon _unit; + +// Exit if unit has no weapon selected +if (_currentWeapon == "") exitWith {}; + +private _weaponIndex = [_unit, _currentWeapon] call FUNC(getWeaponIndex); + +// Ignore binoculars +if (_weaponIndex == -1) exitWith {}; + +_unit setVariable [QGVAR(laserEnabled_) + str _weaponIndex, _state]; + +// Turn off light/laser (switching between weapons can leave previous weapon laser on) +action ["GunLightOff", _unit]; +action ["IRLaserOff", _unit]; + +// Light/laser is off, don't need to do anything more +if (!_state) exitWith {}; + +// Turn laser on next frame (if weapon hasn't changed) +[{ + params ["_unit", "_currentWeapon"]; + + private _weaponState = (weaponState _unit) select [0, 3]; + + if (_weaponState select 0 != _currentWeapon) exitWith {}; + + action ["GunLightOn", _unit]; + action ["IRLaserOn", _unit]; + + _unit selectWeapon _weaponState; +}, [_unit, _currentWeapon]] call CBA_fnc_execNextFrame; + +nil diff --git a/addons/common/functions/fnc_switchPersistentLaser.sqf b/addons/common/functions/fnc_switchPersistentLaser.sqf index 9799b13ade9..adde7e01cb1 100644 --- a/addons/common/functions/fnc_switchPersistentLaser.sqf +++ b/addons/common/functions/fnc_switchPersistentLaser.sqf @@ -33,6 +33,12 @@ if (!_enabled) exitWith { ["turret", GVAR(laserTurretEH)] call CBA_fnc_removePlayerEventHandler; ["vehicle", GVAR(laserVehicleEH)] call CBA_fnc_removePlayerEventHandler; ["weapon", GVAR(laserWeaponEH)] call CBA_fnc_removePlayerEventHandler; + + GVAR(laserKeyDownEH) = nil; + GVAR(laserLoadoutEH) = nil; + GVAR(laserTurretEH) = nil; + GVAR(laserVehicleEH) = nil; + GVAR(laserWeaponEH) = nil; }; private _fnc_getLightLaserState = { @@ -75,9 +81,21 @@ GVAR(laserLoadoutEH) = ["loadout", { GVAR(lastWeapons) = _weapons; - _unit call FUNC(switchPersistentLaserEH); + [ + _unit, + _unit getVariable [QGVAR(laserEnabled_) + str ([_unit, _currentWeapon] call FUNC(getWeaponIndex)), false] + ] call FUNC(setWeaponLightLaserState); }] call CBA_fnc_addPlayerEventHandler; -GVAR(laserTurretEH) = ["turret", LINKFUNC(switchPersistentLaserEH)] call CBA_fnc_addPlayerEventHandler; -GVAR(laserVehicleEH) = ["vehicle", LINKFUNC(switchPersistentLaserEH)] call CBA_fnc_addPlayerEventHandler; -GVAR(laserWeaponEH) = ["weapon", LINKFUNC(switchPersistentLaserEH)] call CBA_fnc_addPlayerEventHandler; +private _fnc_switchPersistentLaserEH = { + params ["_unit"]; + + [ + _unit, + _unit getVariable [QGVAR(laserEnabled_) + str ([_unit, _currentWeapon] call FUNC(getWeaponIndex)), false] + ] call FUNC(setWeaponLightLaserState); +}; + +GVAR(laserTurretEH) = ["turret", _fnc_switchPersistentLaserEH] call CBA_fnc_addPlayerEventHandler; +GVAR(laserVehicleEH) = ["vehicle", _fnc_switchPersistentLaserEH] call CBA_fnc_addPlayerEventHandler; +GVAR(laserWeaponEH) = ["weapon", _fnc_switchPersistentLaserEH] call CBA_fnc_addPlayerEventHandler; diff --git a/addons/common/functions/fnc_switchPersistentLaserEH.sqf b/addons/common/functions/fnc_switchPersistentLaserEH.sqf deleted file mode 100644 index 98e8fab711e..00000000000 --- a/addons/common/functions/fnc_switchPersistentLaserEH.sqf +++ /dev/null @@ -1,48 +0,0 @@ -#include "..\script_component.hpp" -/* - * Author: johnb43 - * Toggles weapon light/laser to match persistent behaviour. - * - * Arguments: - * 0: Unit - * - * Return Value: - * None - * - * Example: - * player call ace_common_fnc_switchPersistentLaserEH - * - * Public: No - */ - -params ["_unit"]; - -if !(_unit call CBA_fnc_canUseWeapon) exitWith {}; - -// Save current weapon state to reapply later -private _weaponState = (weaponState _unit) select [0, 3]; - -if (_weaponState select 0 == "") exitWith {}; - -// Turn off old light/laser -action ["GunLightOff", _unit]; -action ["IRLaserOff", _unit]; - -// Light/laser is off -if !(_unit getVariable [QGVAR(laserEnabled_) + str ([_unit, _weaponState select 0] call EFUNC(common,getWeaponIndex)), false]) exitWith { - _unit selectWeapon _weaponState; -}; - -// Turn laser back on next frame (if weapon hasn't changed) -[{ - params ["_unit", "_weaponState"]; - - if (currentWeapon _unit != _weaponState select 0) exitWith {}; - - action ["GunLightOn", _unit]; - action ["IRLaserOn", _unit]; - - _unit selectWeapon _weaponState; -}, [_unit, _weaponState]] call CBA_fnc_execNextFrame; - -nil From 8e13e99ae4d65043d1bd45c9c0c7dc41f95f5c20 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Thu, 8 Aug 2024 09:55:13 +0200 Subject: [PATCH 6/6] Fix undefined variables --- addons/common/functions/fnc_switchPersistentLaser.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/common/functions/fnc_switchPersistentLaser.sqf b/addons/common/functions/fnc_switchPersistentLaser.sqf index adde7e01cb1..d258284edb6 100644 --- a/addons/common/functions/fnc_switchPersistentLaser.sqf +++ b/addons/common/functions/fnc_switchPersistentLaser.sqf @@ -83,7 +83,7 @@ GVAR(laserLoadoutEH) = ["loadout", { [ _unit, - _unit getVariable [QGVAR(laserEnabled_) + str ([_unit, _currentWeapon] call FUNC(getWeaponIndex)), false] + _unit getVariable [QGVAR(laserEnabled_) + str ([_unit, currentWeapon _unit] call FUNC(getWeaponIndex)), false] ] call FUNC(setWeaponLightLaserState); }] call CBA_fnc_addPlayerEventHandler; @@ -92,7 +92,7 @@ private _fnc_switchPersistentLaserEH = { [ _unit, - _unit getVariable [QGVAR(laserEnabled_) + str ([_unit, _currentWeapon] call FUNC(getWeaponIndex)), false] + _unit getVariable [QGVAR(laserEnabled_) + str ([_unit, currentWeapon _unit] call FUNC(getWeaponIndex)), false] ] call FUNC(setWeaponLightLaserState); };