ACE3/addons/safemode/functions/fnc_lockSafety.sqf

92 lines
2.7 KiB
Plaintext
Raw Normal View History

#include "..\script_component.hpp"
2015-08-08 00:26:09 +00:00
/*
* Author: commy2, johnb43
* Puts weapon on safety, or take it off safety if safety is already put on.
2015-08-08 00:26:09 +00:00
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Weapon <STRING>
* 2: Muzzle <STRING>
* 3: Show hint <BOOL> (default: true)
2015-08-08 00:26:09 +00:00
*
* 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
params ["_unit", "_weapon", "_muzzle", ["_hint", true]];
2015-08-08 00:26:09 +00:00
private _safedWeapons = _unit getVariable QGVAR(safedWeapons);
2015-01-17 20:32:34 +00:00
if (isNil "_safedWeapons") then {
_safedWeapons = createHashMap;
_unit setVariable [QGVAR(safedWeapons), _safedWeapons];
};
// See if the current weapon has locked muzzles
private _safedWeaponMuzzles = _safedWeapons getOrDefault [_weapon, createHashMap, true];
// If muzzle is locked, unlock it (toggle)
if (_muzzle in _safedWeaponMuzzles) exitWith {
[_unit, _weapon, _muzzle, _hint] call FUNC(unlockSafety);
2015-01-17 20:32:34 +00:00
};
private _firemode = (_unit weaponState _muzzle) select 2;
2015-01-17 20:32:34 +00:00
// This syntax of selectWeapon doesn't mess with gun lights and lasers
_unit selectWeapon [_weapon, _muzzle, _firemode];
2015-01-17 20:32:34 +00:00
// Store new muzzle & firemode
_safedWeaponMuzzles set [_muzzle, _firemode];
// Lock muzzle
if (isNil {_unit getVariable QGVAR(actionID)}) then {
2015-09-27 06:28:55 +00:00
_unit setVariable [QGVAR(actionID), [
_unit, "DefaultAction", {
params ["", "_unit"];
2015-09-27 06:28:55 +00:00
if (
_unit call CBA_fnc_canUseWeapon && {
(weaponState _unit) params ["_currentWeapon", "_currentMuzzle"];
// Block firing the muzzle in safe mode
if (_currentMuzzle in ((_unit getVariable [QGVAR(safedWeapons), createHashMap]) getOrDefault [_currentWeapon, createHashMap])) then {
if (inputAction "nextWeapon" > 0 || {inputAction "prevWeapon" > 0}) exitWith {
[_unit, _currentWeapon, _currentMuzzle] call FUNC(unlockSafety);
2015-09-27 06:28:55 +00:00
false
};
2015-09-27 06:28:55 +00:00
true
} else {
false
}
2015-09-27 06:28:55 +00:00
}
) then {
// Player HUD
false call FUNC(setSafeModeVisual);
2015-09-27 06:28:55 +00:00
true
} else {
// Player HUD
true call FUNC(setSafeModeVisual);
2015-09-27 06:28:55 +00:00
false
};
}, {}
] call EFUNC(common,addActionEventHandler)];
2015-01-17 20:32:34 +00:00
};
// Play fire mode selector sound
2015-01-17 20:32:34 +00:00
[_unit, _weapon, _muzzle] call FUNC(playChangeFiremodeSound);
// Show info box unless disabled
if (_hint) then {
[LLSTRING(PutOnSafety), getText (configFile >> "CfgWeapons" >> _weapon >> "picture")] call EFUNC(common,displayTextPicture);
};