Skip to content

Commit

Permalink
Add Toggle Laser keybind (#721)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
mharis001 and rautamiekka authored Mar 22, 2023
1 parent f1653f1 commit d6f8e15
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ PREP(setLampState);
PREP(setMagazineAmmo);
PREP(setTurretAmmo);
PREP(setVehicleAmmo);
PREP(setVehicleLaserState);
PREP(showMessage);
PREP(spawnLargeObject);
PREP(teleportIntoVehicle);
Expand Down
1 change: 1 addition & 0 deletions addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
[QGVAR(setLampState), LINKFUNC(setLampState)] call CBA_fnc_addEventHandler;
[QGVAR(setMagazineAmmo), LINKFUNC(setMagazineAmmo)] call CBA_fnc_addEventHandler;
[QGVAR(setTurretAmmo), LINKFUNC(setTurretAmmo)] call CBA_fnc_addEventHandler;
[QGVAR(setVehicleLaserState), LINKFUNC(setVehicleLaserState)] call CBA_fnc_addEventHandler;
[QGVAR(showMessage), LINKFUNC(showMessage)] call CBA_fnc_addEventHandler;

if (isServer) then {
Expand Down
46 changes: 46 additions & 0 deletions addons/common/functions/fnc_setVehicleLaserState.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Sets the state (on/off) of the given vehicle turret's laser weapon.
*
* Arguments:
* 0: Vehicle <OBJECT>
* 1: State <BOOL> (default: nil)
* - Toggles the laser's state when unspecified.
* 2: Turret Path <ARRAY> (default: [0])
* - The primary gunner turret is used by default.
*
* Return Value:
* None
*
* Example:
* [_vehicle, true] call zen_common_fnc_setVehicleLaserState
*
* Public: No
*/

params [["_vehicle", objNull, [objNull]], ["_state", nil, [true]], ["_turretPath", [0], [[]]]];

if (!local _vehicle) exitWith {
[QGVAR(setVehicleLaserState), _this, _vehicle] call CBA_fnc_targetEvent;
};

// Exit if the laser is already turned on/off and we are not toggling it
if (!isNil "_state" && {_vehicle isLaserOn _turretPath isEqualTo _state}) exitWith {};

// Find the correct magazine id and owner and force the laser weapon to fire
{
_x params ["_xMagazine", "_xTurretPath", "_xAmmoCount", "_id", "_owner"];

if (
_turretPath isEqualTo _xTurretPath
&& {_xAmmoCount > 0}
&& {
private _ammo = getText (configFile >> "CfgMagazines" >> _xMagazine >> "ammo");
private _ammoSimulation = getText (configFile >> "CfgAmmo" >> _ammo >> "simulation");
_ammoSimulation == "laserDesignate"
}
) exitWith {
_vehicle action ["UseMagazine", _vehicle, _vehicle turretUnit _turretPath, _owner, _id];
};
} forEach magazinesAllTurrets _vehicle;
12 changes: 12 additions & 0 deletions addons/editor/initKeybinds.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,18 @@
[QEGVAR(common,forceFire), [[], CBA_clientID]] call CBA_fnc_globalEvent;
}, [0, [false, false, false]]] call CBA_fnc_addKeybind; // Default: Unbound

[[ELSTRING(main,DisplayName), LSTRING(AIControl)], QGVAR(toggleLaser), [LSTRING(ToggleLaser), LSTRING(ToggleLaser_Description)], {
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
{
if (!isNull group _x && {!isPlayer _x}) then {
[_x] call EFUNC(common,setVehicleLaserState);
};
} forEach SELECTED_OBJECTS;

true // handled
};
}, {}, [0, [false, false, false]]] call CBA_fnc_addKeybind; // Default: Unbound

[[ELSTRING(main,DisplayName), LSTRING(AIControl)], QGVAR(moveToCursor), [LSTRING(MoveToCursor), LSTRING(MoveToCursor_Description)], {
if (!isNull curatorCamera && {!GETMVAR(RscDisplayCurator_search,false)}) then {
private _position = ASLToAGL ([] call EFUNC(common,getPosFromScreen));
Expand Down
6 changes: 6 additions & 0 deletions addons/editor/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@
<Key ID="STR_ZEN_Editor_ForceFire_Description">
<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>
</Key>
<Key ID="STR_ZEN_Editor_ToggleLaser">
<English>Toggle Laser</English>
</Key>
<Key ID="STR_ZEN_Editor_ToggleLaser_Description">
<English>Makes selected AI units in vehicles toggle their turret laser weapons on or off.</English>
</Key>
<Key ID="STR_ZEN_Editor_MoveToCursor">
<English>Move To Cursor</English>
</Key>
Expand Down

0 comments on commit d6f8e15

Please sign in to comment.