ACE3/addons/explosives/functions/fnc_cycleActiveTrigger.sqf
Fabio Schick 2f9b7002c3
Explosives - Add Cellphone/Detonator Keybinds (#9687)
Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
2024-02-07 17:47:01 -03:00

54 lines
1.6 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: mrschick
* Cycles the "Active Trigger" of a unit and shows a CBA Hint that displays the new Active Trigger.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [ACE_player] call ace_explosives_fnc_cycleActiveTrigger;
*
* Public: No
*/
params ["_unit"];
TRACE_1("params",_unit);
private _detonators = _unit call FUNC(getDetonators);
// Remove ACE_Cellphone from list, as it should never be the active trigger due to having its own keybind
_detonators deleteAt (_detonators findIf {_x == "ACE_Cellphone"});
// Reset Active Trigger if none available
if (_detonators isEqualTo []) exitWith {
GVAR(activeTrigger) = "";
};
private _activeTrigger = GVAR(activeTrigger);
private _index = _detonators findIf {_x == _activeTrigger};
private _count = count _detonators;
if (_activeTrigger != "" && {_index != -1} && {_count > 1}) then {
// If active trigger is set and among current detonators, switch to the next one
if (_index < _count - 1) then {
_index = _index + 1;
} else {
_index = 0;
};
_activeTrigger = _detonators select _index;
} else {
// Assign first detonator in list as the active one
_activeTrigger = _detonators select 0;
};
GVAR(activeTrigger) = _activeTrigger;
private _triggerConfig = configFile >> "CfgWeapons" >> _activeTrigger;
private _triggerName = getText (_triggerConfig >> "displayName");
private _triggerIcon = getText (_triggerConfig >> "picture");
[format ["%1: %2", LLSTRING(ActiveTrigger), _triggerName], _triggerIcon] call EFUNC(common,displayTextPicture);