ACE3/addons/safemode/functions/fnc_lockSafety.sqf

82 lines
2.4 KiB
Plaintext
Raw Normal View History

2015-08-08 00:26:09 +00:00
/*
* Author: commy2
* Put weapon on safety, or take it off safety if safety is already put on.
*
* 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_lockSafety
*
* Public: No
*/
2015-01-17 20:32:34 +00:00
#include "script_component.hpp"
// don't immediately switch back
if (inputAction "nextWeapon" > 0) exitWith {};
2015-08-08 00:26:09 +00:00
private ["_safedWeapons", "_condition", "_statement", "_id", "_picture"];
params ["_unit", "_weapon", "_muzzle"];
2015-01-17 20:32:34 +00:00
_safedWeapons = _unit getVariable [QGVAR(safedWeapons), []];
if (_weapon in _safedWeapons) exitWith {
2015-05-15 13:41:41 +00:00
_this call FUNC(unlockSafety);
2015-01-17 20:32:34 +00:00
};
_safedWeapons pushBack _weapon;
_unit setVariable [QGVAR(safedWeapons), _safedWeapons];
if (_unit getVariable [QGVAR(actionID), -1] == -1) then {
2015-05-15 13:41:41 +00:00
_condition = {
2015-08-08 00:26:09 +00:00
params ["", "_caller"];
2015-05-15 13:41:41 +00:00
if (
2015-08-08 00:26:09 +00:00
[_caller] call EFUNC(common,canUseWeapon)
2015-05-15 13:41:41 +00:00
&& {
2015-08-08 00:26:09 +00:00
if (currentMuzzle _caller in (_caller getVariable [QGVAR(safedWeapons), []])) then {
2015-05-15 13:41:41 +00:00
if (inputAction "nextWeapon" > 0) exitWith {
2015-08-08 00:26:09 +00:00
[_this select 1, currentWeapon _caller, currentMuzzle _caller] call FUNC(unlockSafety);
2015-05-15 13:41:41 +00:00
false
};
true
} else {false}
}
) then {
// player hud
[false] call FUNC(setSafeModeVisual);
true
} else {
// player hud
[true] call FUNC(setSafeModeVisual);
2015-01-17 20:32:34 +00:00
false
2015-05-15 13:41:41 +00:00
}
};
_statement = {
2015-08-08 00:26:09 +00:00
params ["", "_caller"];
[_caller, currentWeapon _caller, currentMuzzle _caller] call FUNC(unlockSafety);
2015-05-15 13:41:41 +00:00
};
2015-05-28 19:59:04 +00:00
//_id = [_unit, format ["<t color=""#FFFF00"" >%1</t>", localize LSTRING(TakeOffSafety)], "DefaultAction", _condition, {}, {true}, _statement, 10] call EFUNC(common,addActionMenuEventHandler);
2015-05-15 13:41:41 +00:00
_id = [_unit, "DefaultAction", _condition, {}] call EFUNC(common,addActionEventHandler);
_unit setVariable [QGVAR(actionID), _id];
2015-01-17 20:32:34 +00:00
};
if ((typeName _muzzle) == (typeName "")) then {
2015-08-08 00:26:09 +00:00
_unit selectWeapon _muzzle; //_weapon
};
2015-01-17 20:32:34 +00:00
// play fire mode selector sound
[_unit, _weapon, _muzzle] call FUNC(playChangeFiremodeSound);
_picture = getText (configFile >> "CfgWeapons" >> _weapon >> "picture");
2015-05-28 19:59:04 +00:00
[localize LSTRING(PutOnSafety), _picture] call EFUNC(common,displayTextPicture);