ACE3/addons/safemode/functions/fnc_unlockSafety.sqf

83 lines
2.3 KiB
Plaintext
Raw Normal View History

#include "script_component.hpp"
2015-08-08 00:26:09 +00:00
/*
* Author: commy2
* Take weapon of safety lock.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Weapon <STRING>
* 2: Muzzle <STRING>
*
* Return Value:
* None
*
* Example:
* [ACE_player, currentWeapon ACE_player, currentMuzzle ACE_player] call ace_safemode_fnc_unlockSafety
*
* Public: No
*/
2015-08-08 00:26:09 +00:00
params ["_unit", "_weapon", "_muzzle"];
private _safedWeapons = _unit getVariable [QGVAR(safedWeapons), []];
2015-09-27 06:28:55 +00:00
_safedWeapons deleteAt (_safedWeapons find _weapon);
2015-09-27 06:28:55 +00:00
_unit setVariable [QGVAR(safedWeapons), _safedWeapons];
2015-09-27 06:28:55 +00:00
// remove action if all weapons have put their safety on
if (_safedWeapons isEqualTo []) then {
[_unit, "DefaultAction", _unit getVariable [QGVAR(actionID), -1]] call EFUNC(common,removeActionEventHandler);
_unit setVariable [QGVAR(actionID), -1];
};
private _laserEnabled = _unit isIRLaserOn _weapon || {_unit isFlashlightOn _weapon};
_unit selectWeapon _muzzle;
if (
_laserEnabled
&& {
_muzzle == primaryWeapon _unit // prevent UGL switch
|| {"" == primaryWeapon _unit} // Arma switches to primary weapon if exists
}
) then {
{_unit action [_x, _unit]} forEach ["GunLightOn", "IRLaserOn"];
};
if (inputAction "nextWeapon" > 0) then {
2015-05-15 13:41:41 +00:00
// switch to the last mode to roll over to first after the default nextWeapon action
// get weapon modes
private _modes = [];
2015-05-15 13:41:41 +00:00
{
if (getNumber (configFile >> "CfgWeapons" >> _weapon >> _x >> "showToPlayer") == 1) then {
_modes pushBack _x;
};
if (_x == "this") then {
_modes pushBack _weapon;
};
2015-08-08 00:26:09 +00:00
nil
2015-11-30 16:23:02 +00:00
} count getArray (configFile >> "CfgWeapons" >> _weapon >> "modes");
2015-05-15 13:41:41 +00:00
// select last mode
private _mode = _modes select (count _modes - 1);
2015-05-15 13:41:41 +00:00
// switch to last mode
private _index = 0;
2015-05-15 13:41:41 +00:00
while {
_index < 299 && {currentMuzzle _unit != _weapon || {currentWeaponMode _unit != _mode}}
2015-05-15 13:41:41 +00:00
} do {
_unit action ["SwitchWeapon", _unit, _unit, _index];
_index = _index + 1;
};
} else {
2015-05-15 13:41:41 +00:00
// play fire mode selector sound
[_unit, _weapon, _muzzle] call FUNC(playChangeFiremodeSound);
};
// player hud
2015-01-17 20:32:34 +00:00
[true] call FUNC(setSafeModeVisual);
2015-09-27 06:28:55 +00:00
// show info box
private _picture = getText (configFile >> "CfgWeapons" >> _weapon >> "picture");
2015-05-28 19:59:04 +00:00
[localize LSTRING(TookOffSafety), _picture] call EFUNC(common,displayTextPicture);