Skip to content

Commit

Permalink
IR Light - Fix bad item replacements and switching to primary weapons (
Browse files Browse the repository at this point in the history
…#10119)

* Fix bad item replacements and switching to primary weapons

* Update addons/irlight/functions/fnc_initItemContextMenu.sqf

* Update fnc_initItemContextMenu.sqf

* Remove unused funtions

* Various fixes/tweaks

- Added a weapon parameter to `switchAttachmentMode`
- Made `switchPersistentLaser` take pointer switching into account
- Fixed IR light attachments being added to the wrong weapon
  • Loading branch information
johnb432 committed Aug 11, 2024
1 parent ff31bc6 commit b7f48a9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 123 deletions.
12 changes: 7 additions & 5 deletions addons/common/functions/fnc_switchPersistentLaser.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ private _fnc_getLightLaserState = {
if (_weaponIndex == -1) exitWith {};

// Light/laser state only changes in the next frame
// However, as by default changing attachment modes is CTRL + L, the vanilla EH triggers when lights are bound to L (even despite CBA intercepting keystroke)
// Therefore, add an extra frame of delay, after which the previous laser state will have been restored
[{
ACE_player setVariable [
QGVAR(laserEnabled_) + str (_this select 1),
ACE_player isIRLaserOn (_this select 0) || {ACE_player isFlashlightOn (_this select 0)}
];
}, [_currentWeapon, _weaponIndex]] call CBA_fnc_execNextFrame;
}, [_currentWeapon, _weaponIndex], 2] call CBA_fnc_execAfterNFrames;
};

// Get current weapon light/laser state
Expand All @@ -68,14 +70,14 @@ call _fnc_getLightLaserState;
// Update state every time it's changed
GVAR(laserKeyDownEH) = addUserActionEventHandler ["headlights", "Activate", _fnc_getLightLaserState];

// Dropping weapons turns off lights/lasers
GVAR(lastWeapons) = [primaryWeapon ACE_player, handgunWeapon ACE_player, secondaryWeapon ACE_player];
// Dropping weapons, as well as switching light/laser attachments turns off lights/lasers
GVAR(lastWeapons) = (getUnitLoadout ACE_player) select [0, 3];

// Monitor weapon addition/removal here
GVAR(laserLoadoutEH) = ["loadout", {
params ["_unit"];
params ["_unit", "_loadout"];

private _weapons = [primaryWeapon _unit, handgunWeapon _unit, secondaryWeapon _unit];
private _weapons = _loadout select [0, 3];

if (_weapons isEqualTo GVAR(lastWeapons)) exitWith {};

Expand Down
2 changes: 0 additions & 2 deletions addons/irlight/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
PREP(getGlowOffset);
PREP(initItemContextMenu);
PREP(onLightToggled);
43 changes: 20 additions & 23 deletions addons/irlight/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
#include "script_component.hpp"

[] call FUNC(initItemContextMenu);

addUserActionEventHandler ["headlights", "Deactivate", LINKFUNC(onLightToggled)];
call FUNC(initItemContextMenu);

["ACE3 Equipment", QGVAR(hold), LLSTRING(MomentarySwitch), {
ACE_player action ["GunLightOn", ACE_player];
ACE_player action ["IRLaserOn", ACE_player];
[] call FUNC(onLightToggled);
if !(ACE_player call CBA_fnc_canUseWeapon) exitWith {};

// Save current weapon state to reapply later
private _weaponState = (weaponState ACE_player) select [0, 3];

action ["GunLightOn", ACE_player];
action ["IRLaserOn", ACE_player];

ACE_player selectWeapon _weaponState;

true
}, {
ACE_player action ["GunLightOff", ACE_player];
ACE_player action ["IRLaserOff", ACE_player];
[] call FUNC(onLightToggled);
true
}] call CBA_fnc_addKeybind;
if !(ACE_player call CBA_fnc_canUseWeapon) exitWith {};

// Save current weapon state to reapply later
private _weaponState = (weaponState ACE_player) select [0, 3];

["CBA_attachmentSwitched", {
params ["", "", "_item"];

private _substr = _item select [0, 8];
if (
ACE_player getVariable [QGVAR(isTurnedOn), false]
&& {_substr == "ACE_SPIR" || {_substr == "ACE_DBAL"}}
) then {
ACE_player action ["GunLightOn", ACE_player];
ACE_player action ["IRLaserOn", ACE_player];
};
}] call CBA_fnc_addEventHandler;
action ["GunLightOff", ACE_player];
action ["IRLaserOff", ACE_player];

ACE_player selectWeapon _weaponState;
}] call CBA_fnc_addKeybind;
41 changes: 0 additions & 41 deletions addons/irlight/functions/fnc_getGlowOffset.sqf

This file was deleted.

36 changes: 20 additions & 16 deletions addons/irlight/functions/fnc_initItemContextMenu.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* None
*
* Example:
* [] call ace_irlight_fnc_initItemContextMenu
* call ace_irlight_fnc_initItemContextMenu
*
* Public: No
*/
Expand All @@ -19,30 +19,34 @@
_x params ["_variant", "_displayName"];

[
"ACE_DBAL_A3_Red", "POINTER", _displayName, [], "", {
"ACE_DBAL_A3_Red",
"POINTER",
_displayName,
[],
"",
{
params ["", "", "_item", "", "_variant"];

private _baseClass = getText (configFile >> "CfgWeapons" >> _item >> "baseWeapon");
_item != _baseClass + _variant
}, {
params ["", "", "_item", "", "_variant"];
params ["_unit", "", "_item", "_slot", "_variant"];

private _baseClass = getText (configFile >> "CfgWeapons" >> _item >> "baseWeapon");
private _weapon = switch (_slot) do {
case "RIFLE_POINTER": {primaryWeapon _unit};
case "LAUNCHER_POINTER": {secondaryWeapon _unit};
case "PISTOL_POINTER": {handgunWeapon _unit};
default {""};
};

ACE_player removePrimaryWeaponItem _item;
ACE_player addPrimaryWeaponItem (_baseClass + _variant);
playSound "click";
if (_weapon == "") exitWith {};

if (_turnedOn) then {
// Force update of flashlight
ACE_player action ["GunLightOff", ACE_player];
private _baseClass = getText (configFile >> "CfgWeapons" >> _item >> "baseWeapon");

{
ACE_player action ["GunLightOn", ACE_player];
ACE_player action ["IRLaserOn", ACE_player];
} call CBA_fnc_execNextFrame;
};
}, false, _variant
[_unit, _weapon, _item, _baseClass + _variant] call EFUNC(common,switchAttachmentMode);
},
false,
_variant
] call CBA_fnc_addItemContextMenuOption;
} forEach [
["", LSTRING(Mode_IRDual)],
Expand Down
36 changes: 0 additions & 36 deletions addons/irlight/functions/fnc_onLightToggled.sqf

This file was deleted.

0 comments on commit b7f48a9

Please sign in to comment.