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

IR Light - Fix bad item replacements and switching to primary weapons #10119

Merged
merged 9 commits into from
Aug 11, 2024
47 changes: 25 additions & 22 deletions addons/irlight/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
#include "script_component.hpp"

[] call FUNC(initItemContextMenu);
call FUNC(initItemContextMenu);

addUserActionEventHandler ["headlights", "Deactivate", LINKFUNC(onLightToggled)];
//addUserActionEventHandler ["headlights", "Activate", {LINKFUNC(onLightToggled) call CBA_fnc_execNextFrame}];

["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;

// call FUNC(onLightToggled);

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];

action ["GunLightOff", ACE_player];
action ["IRLaserOff", ACE_player];

["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;
ACE_player selectWeapon _weaponState;

// call FUNC(onLightToggled);
}] call CBA_fnc_addKeybind;
31 changes: 17 additions & 14 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 @@ -25,23 +25,26 @@
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");

ACE_player removePrimaryWeaponItem _item;
ACE_player addPrimaryWeaponItem (_baseClass + _variant);
playSound "click";

if (_turnedOn) then {
PabstMirror marked this conversation as resolved.
Show resolved Hide resolved
// Force update of flashlight
ACE_player action ["GunLightOff", ACE_player];

{
ACE_player action ["GunLightOn", ACE_player];
ACE_player action ["IRLaserOn", ACE_player];
} call CBA_fnc_execNextFrame;
switch (_slot) do {
case "RIFLE_POINTER": {
_unit removePrimaryWeaponItem _item;
_unit addPrimaryWeaponItem (_baseClass + _variant);
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
};
case "LAUNCHER_POINTER": {
_unit removeSecondaryWeaponItem _item;
_unit addSecondaryWeaponItem (_baseClass + _variant);
};
case "PISTOL_POINTER": {
_unit removeHandgunItem _item;
_unit addHandgunItem (_baseClass + _variant);
};
};

playSound "click";
}, false, _variant
] call CBA_fnc_addItemContextMenuOption;
} forEach [
Expand Down