ACE3/addons/laserpointer/XEH_postInit.sqf
BaerMitUmlaut d6faac5881
Add IR Flashlights (#6563)
* Initial IR flashlight tests

* More experiments

* Rewrite using engine IR lights

* Rework ranges, fix bugs, add docs

* Fix uncommented DISABLE_COMPILE_CACHE

Co-authored-by: jonpas <jonpas33@gmail.com>

* Markdown fixes

Co-authored-by: jonpas <jonpas33@gmail.com>

* Markdown fixes

Co-authored-by: jonpas <jonpas33@gmail.com>

* Markdown fixes

Co-authored-by: jonpas <jonpas33@gmail.com>

* Markdown fixes

Co-authored-by: jonpas <jonpas33@gmail.com>

* Markdown fixes

Co-authored-by: jonpas <jonpas33@gmail.com>

* Use baseWeapon instead of custom property

* Add baseWeapon to SPIR

---------

Co-authored-by: jonpas <jonpas33@gmail.com>
2023-09-17 09:32:39 +02:00

99 lines
3.7 KiB
Plaintext

// by commy2
#include "script_component.hpp"
// fixes laser when being captured. Needed, because the selectionPosition of the right hand is used
[QEGVAR(captives,setHandcuffed), {if (_this select 1) then {(_this select 0) action ["GunLightOff", _this select 0]};}] call CBA_fnc_addEventHandler;
if (!hasInterface) exitWith {};
GVAR(nearUnits) = [];
GVAR(index) = -1;
GVAR(laserClassesCache) = [] call CBA_fnc_createNamespace;
GVAR(redLaserUnits) = [];
GVAR(greenLaserUnits) = [];
["CBA_settingsInitialized", {
// If not enabled, dont't add draw eventhandler or PFEH (for performance)
if (!GVAR(enabled)) exitWith {
["ACE_acc_pointer_red", { false }] call CBA_fnc_addAttachmentCondition;
["ACE_acc_pointer_green", { false }] call CBA_fnc_addAttachmentCondition;
["CBA_attachmentSwitched", {
params ["_unit", "_prevItem", "_newItem", "_currWeaponType"];
TRACE_4("CBA_attachmentSwitched eh",_unit,_prevItem,_newItem,_currWeaponType);
if ((getNumber (configFile >> "CfgWeapons" >> _newItem >> "ACE_laserpointer")) > 0) then {
TRACE_1("removing ACE_laserpointer",getNumber (configFile >> "CfgWeapons" >> _newItem >> "ACE_laserpointer"));
[1, "next"] call CBA_accessory_fnc_switchAttachment;
};
}] call CBA_fnc_addEventHandler;
};
[{
private _oldNearUnits = GVAR(nearUnits);
GVAR(nearUnits) = call FUNC(getNearUnits);
// remove units that moved away
{
GVAR(redLaserUnits) deleteAt (GVAR(redLaserUnits) find _x);
GVAR(greenLaserUnits) deleteAt (GVAR(greenLaserUnits) find _x);
} forEach (_oldNearUnits - GVAR(nearUnits));
}, 5, []] call CBA_fnc_addPerFrameHandler;
private _fnc_processUnit = {
params ["_unit"];
private _weapon = currentWeapon _unit;
if (!(_unit isFlashlightOn _weapon)) exitWith {
GVAR(redLaserUnits) deleteAt (GVAR(redLaserUnits) find _unit);
GVAR(greenLaserUnits) deleteAt (GVAR(greenLaserUnits) find _unit);
};
private _laser = [(_unit weaponAccessories _weapon) select 1] param [0, ""];
if (_laser isEqualTo "") exitWith {
GVAR(redLaserUnits) deleteAt (GVAR(redLaserUnits) find _unit);
GVAR(greenLaserUnits) deleteAt (GVAR(greenLaserUnits) find _unit);
};
private _laserID = GVAR(laserClassesCache) getVariable _laser;
if (isNil "_laserID") then {
_laserID = getNumber (configFile >> "CfgWeapons" >> _laser >> "ACE_laserpointer");
GVAR(laserClassesCache) setVariable [_laser, _laserID];
};
TRACE_3("",_weapon,_laser,_laserID);
switch (_laserID) do {
case 0: {
GVAR(redLaserUnits) deleteAt (GVAR(redLaserUnits) find _unit);
GVAR(greenLaserUnits) deleteAt (GVAR(greenLaserUnits) find _unit);
};
case 1: {
GVAR(redLaserUnits) pushBackUnique _unit;
GVAR(greenLaserUnits) deleteAt (GVAR(greenLaserUnits) find _unit);
};
case 2: {
GVAR(greenLaserUnits) pushBackUnique _unit;
GVAR(redLaserUnits) deleteAt (GVAR(redLaserUnits) find _unit);
};
};
};
// custom scheduler
[{
params ["_fnc_processUnit"];
ACE_player call _fnc_processUnit;
GVAR(index) = GVAR(index) + 1;
private _unit = GVAR(nearUnits) param [GVAR(index), objNull];
if (isNull _unit) exitWith {
GVAR(index) = -1;
};
_unit call _fnc_processUnit;
}, 0.1, _fnc_processUnit] call CBA_fnc_addPerFrameHandler;
addMissionEventHandler ["Draw3D", {call FUNC(onDraw)}];
}] call CBA_fnc_addEventHandler;