Skip to content

Commit d6f8e15

Browse files
Add Toggle Laser keybind (#721)
* Add Toggle Laser keybind * Update addons/editor/stringtable.xml Co-authored-by: Jouni Järvinen <[email protected]> --------- Co-authored-by: Jouni Järvinen <[email protected]>
1 parent f1653f1 commit d6f8e15

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

addons/common/XEH_PREP.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ PREP(setLampState);
6868
PREP(setMagazineAmmo);
6969
PREP(setTurretAmmo);
7070
PREP(setVehicleAmmo);
71+
PREP(setVehicleLaserState);
7172
PREP(showMessage);
7273
PREP(spawnLargeObject);
7374
PREP(teleportIntoVehicle);

addons/common/XEH_postInit.sqf

+1
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@
351351
[QGVAR(setLampState), LINKFUNC(setLampState)] call CBA_fnc_addEventHandler;
352352
[QGVAR(setMagazineAmmo), LINKFUNC(setMagazineAmmo)] call CBA_fnc_addEventHandler;
353353
[QGVAR(setTurretAmmo), LINKFUNC(setTurretAmmo)] call CBA_fnc_addEventHandler;
354+
[QGVAR(setVehicleLaserState), LINKFUNC(setVehicleLaserState)] call CBA_fnc_addEventHandler;
354355
[QGVAR(showMessage), LINKFUNC(showMessage)] call CBA_fnc_addEventHandler;
355356

356357
if (isServer) then {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "script_component.hpp"
2+
/*
3+
* Author: mharis001
4+
* Sets the state (on/off) of the given vehicle turret's laser weapon.
5+
*
6+
* Arguments:
7+
* 0: Vehicle <OBJECT>
8+
* 1: State <BOOL> (default: nil)
9+
* - Toggles the laser's state when unspecified.
10+
* 2: Turret Path <ARRAY> (default: [0])
11+
* - The primary gunner turret is used by default.
12+
*
13+
* Return Value:
14+
* None
15+
*
16+
* Example:
17+
* [_vehicle, true] call zen_common_fnc_setVehicleLaserState
18+
*
19+
* Public: No
20+
*/
21+
22+
params [["_vehicle", objNull, [objNull]], ["_state", nil, [true]], ["_turretPath", [0], [[]]]];
23+
24+
if (!local _vehicle) exitWith {
25+
[QGVAR(setVehicleLaserState), _this, _vehicle] call CBA_fnc_targetEvent;
26+
};
27+
28+
// Exit if the laser is already turned on/off and we are not toggling it
29+
if (!isNil "_state" && {_vehicle isLaserOn _turretPath isEqualTo _state}) exitWith {};
30+
31+
// Find the correct magazine id and owner and force the laser weapon to fire
32+
{
33+
_x params ["_xMagazine", "_xTurretPath", "_xAmmoCount", "_id", "_owner"];
34+
35+
if (
36+
_turretPath isEqualTo _xTurretPath
37+
&& {_xAmmoCount > 0}
38+
&& {
39+
private _ammo = getText (configFile >> "CfgMagazines" >> _xMagazine >> "ammo");
40+
private _ammoSimulation = getText (configFile >> "CfgAmmo" >> _ammo >> "simulation");
41+
_ammoSimulation == "laserDesignate"
42+
}
43+
) exitWith {
44+
_vehicle action ["UseMagazine", _vehicle, _vehicle turretUnit _turretPath, _owner, _id];
45+
};
46+
} forEach magazinesAllTurrets _vehicle;

addons/editor/initKeybinds.sqf

+12
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@
190190
[QEGVAR(common,forceFire), [[], CBA_clientID]] call CBA_fnc_globalEvent;
191191
}, [0, [false, false, false]]] call CBA_fnc_addKeybind; // Default: Unbound
192192

193+
[[ELSTRING(main,DisplayName), LSTRING(AIControl)], QGVAR(toggleLaser), [LSTRING(ToggleLaser), LSTRING(ToggleLaser_Description)], {
194+
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
195+
{
196+
if (!isNull group _x && {!isPlayer _x}) then {
197+
[_x] call EFUNC(common,setVehicleLaserState);
198+
};
199+
} forEach SELECTED_OBJECTS;
200+
201+
true // handled
202+
};
203+
}, {}, [0, [false, false, false]]] call CBA_fnc_addKeybind; // Default: Unbound
204+
193205
[[ELSTRING(main,DisplayName), LSTRING(AIControl)], QGVAR(moveToCursor), [LSTRING(MoveToCursor), LSTRING(MoveToCursor_Description)], {
194206
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
195207
private _position = ASLToAGL ([] call EFUNC(common,getPosFromScreen));

addons/editor/stringtable.xml

+6
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,12 @@
393393
<Key ID="STR_ZEN_Editor_ForceFire_Description">
394394
<English>Makes selected AI units fire their current weapon while the key is held down. Vehicles will fire their first available turret with a weapon.</English>
395395
</Key>
396+
<Key ID="STR_ZEN_Editor_ToggleLaser">
397+
<English>Toggle Laser</English>
398+
</Key>
399+
<Key ID="STR_ZEN_Editor_ToggleLaser_Description">
400+
<English>Makes selected AI units in vehicles toggle their turret laser weapons on or off.</English>
401+
</Key>
396402
<Key ID="STR_ZEN_Editor_MoveToCursor">
397403
<English>Move To Cursor</English>
398404
</Key>

0 commit comments

Comments
 (0)