mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
IR Light - Fix bad item replacements and switching to primary weapons (#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
This commit is contained in:
parent
ff31bc69a8
commit
b7f48a912f
@ -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
|
||||
@ -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 {};
|
||||
|
||||
|
@ -1,3 +1 @@
|
||||
PREP(getGlowOffset);
|
||||
PREP(initItemContextMenu);
|
||||
PREP(onLightToggled);
|
||||
|
@ -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
|
||||
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];
|
||||
|
||||
ACE_player selectWeapon _weaponState;
|
||||
}] call CBA_fnc_addKeybind;
|
||||
|
||||
["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;
|
||||
|
@ -1,41 +0,0 @@
|
||||
#include "..\script_component.hpp"
|
||||
/*
|
||||
* Author: BaerMitUmlaut
|
||||
* Gets the player model offset of the IR laser origin.
|
||||
* Currently unused, see onLightToggled.
|
||||
*
|
||||
* Arguments:
|
||||
* None
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [] call ace_irlight_fnc_getGlowOffset
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
if (isNil QGVAR(offsetCache)) then {
|
||||
GVAR(offsetCache) = createHashMap;
|
||||
};
|
||||
|
||||
private _weapon = currentWeapon ACE_player;
|
||||
private _laser = ((weaponsItems ACE_player) select {_x#0 == _weapon})#0#2;
|
||||
|
||||
GVAR(offsetCache) getOrDefaultCall [[_weapon, _laser], {
|
||||
private _model = getText (configFile >> "CfgWeapons" >> _weapon >> "model");
|
||||
private _dummy = createSimpleObject [_model, [0, 0, 0], true];
|
||||
private _proxyOffset = _dummy selectionPosition ["\a3\data_f\proxies\weapon_slots\SIDE.001", 1];
|
||||
_proxyOffset = [_proxyOffset#1, _proxyOffset#0 * -1, _proxyOffset#2];
|
||||
deleteVehicle _dummy;
|
||||
|
||||
_model = getText (configFile >> "CfgWeapons" >> _laser >> "model");
|
||||
_dummy = createSimpleObject [_model, [0, 0, 0], true];
|
||||
private _selection = getText (configFile >> "CfgWeapons" >> _laser >> "ItemInfo" >> "Pointer" >> "irLaserPos");
|
||||
private _laserOffset = _dummy selectionPosition [_selection, "Memory"];
|
||||
_laserOffset = [_laserOffset#1, _laserOffset#0 * -1, _laserOffset#2 * -1];
|
||||
deleteVehicle _dummy;
|
||||
|
||||
_proxyOffset vectorAdd _laserOffset
|
||||
}, true];
|
@ -10,7 +10,7 @@
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [] call ace_irlight_fnc_initItemContextMenu
|
||||
* call ace_irlight_fnc_initItemContextMenu
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
@ -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 _weapon = switch (_slot) do {
|
||||
case "RIFLE_POINTER": {primaryWeapon _unit};
|
||||
case "LAUNCHER_POINTER": {secondaryWeapon _unit};
|
||||
case "PISTOL_POINTER": {handgunWeapon _unit};
|
||||
default {""};
|
||||
};
|
||||
|
||||
if (_weapon == "") exitWith {};
|
||||
|
||||
private _baseClass = getText (configFile >> "CfgWeapons" >> _item >> "baseWeapon");
|
||||
|
||||
ACE_player removePrimaryWeaponItem _item;
|
||||
ACE_player addPrimaryWeaponItem (_baseClass + _variant);
|
||||
playSound "click";
|
||||
|
||||
if (_turnedOn) then {
|
||||
// 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;
|
||||
};
|
||||
}, false, _variant
|
||||
[_unit, _weapon, _item, _baseClass + _variant] call EFUNC(common,switchAttachmentMode);
|
||||
},
|
||||
false,
|
||||
_variant
|
||||
] call CBA_fnc_addItemContextMenuOption;
|
||||
} forEach [
|
||||
["", LSTRING(Mode_IRDual)],
|
||||
|
@ -1,36 +0,0 @@
|
||||
#include "..\script_component.hpp"
|
||||
/*
|
||||
* Author: BaerMitUmlaut
|
||||
* Handles toggling flashlights on and off.
|
||||
*
|
||||
* Arguments:
|
||||
* None
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [] call ace_irlight_fnc_onLightToggled
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
private _isTurnedOn = ACE_player isFlashlightOn primaryWeapon ACE_player
|
||||
|| ACE_player isIRLaserOn primaryWeapon ACE_player;
|
||||
ACE_player setVariable [QGVAR(isTurnedOn), _isTurnedOn];
|
||||
|
||||
// This is a surprise tool that will help us later
|
||||
// Requires: https://feedback.bistudio.com/T170774
|
||||
/*
|
||||
deleteVehicle (ACE_player getVariable [QGVAR(glow), objNull]);
|
||||
|
||||
if (ACE_player isIRLaserOn currentWeapon ACE_player) then {
|
||||
private _offset = [] call FUNC(getGlowOffset);
|
||||
private _glow = createSimpleObject [QPATHTOF(data\irglow.p3d), [0, 0, 0]];
|
||||
_glow attachTo [ACE_player, _offset, "proxy:\a3\characters_f\proxies\weapon.001", true];
|
||||
_glow setObjectTexture [0, "#(rgb,8,8,3)color(0.35,0,0.38,0.1)"];
|
||||
_glow setObjectScale 0.1;
|
||||
|
||||
ACE_player setVariable [QGVAR(glow), _glow];
|
||||
};
|
||||
*/
|
Loading…
Reference in New Issue
Block a user