2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-08-08 00:26:09 +00:00
|
|
|
/*
|
2024-08-02 11:59:18 +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>
|
2024-08-02 11:59:18 +00:00
|
|
|
* 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
|
|
|
|
2024-08-02 11:59:18 +00:00
|
|
|
params ["_unit", "_weapon", "_muzzle", ["_hint", true]];
|
2015-08-08 00:26:09 +00:00
|
|
|
|
2024-08-02 11:59:18 +00:00
|
|
|
private _safedWeapons = _unit getVariable QGVAR(safedWeapons);
|
2015-01-17 20:32:34 +00:00
|
|
|
|
2024-08-02 11:59:18 +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
|
|
|
};
|
|
|
|
|
2024-08-02 11:59:18 +00:00
|
|
|
private _firemode = (_unit weaponState _muzzle) select 2;
|
2015-01-17 20:32:34 +00:00
|
|
|
|
2024-08-02 11:59:18 +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
|
|
|
|
2024-08-02 11:59:18 +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", {
|
2024-08-02 11:59:18 +00:00
|
|
|
params ["", "_unit"];
|
|
|
|
|
2015-09-27 06:28:55 +00:00
|
|
|
if (
|
2024-08-02 11:59:18 +00:00
|
|
|
_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
|
|
|
|
};
|
2024-08-02 11:59:18 +00:00
|
|
|
|
2015-09-27 06:28:55 +00:00
|
|
|
true
|
2024-08-02 11:59:18 +00:00
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
2015-09-27 06:28:55 +00:00
|
|
|
}
|
|
|
|
) then {
|
2024-08-02 11:59:18 +00:00
|
|
|
// Player HUD
|
|
|
|
false call FUNC(setSafeModeVisual);
|
|
|
|
|
2015-09-27 06:28:55 +00:00
|
|
|
true
|
|
|
|
} else {
|
2024-08-02 11:59:18 +00:00
|
|
|
// 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
|
|
|
};
|
|
|
|
|
2024-08-02 11:59:18 +00:00
|
|
|
// Play fire mode selector sound
|
2015-01-17 20:32:34 +00:00
|
|
|
[_unit, _weapon, _muzzle] call FUNC(playChangeFiremodeSound);
|
|
|
|
|
2024-08-02 11:59:18 +00:00
|
|
|
// Show info box unless disabled
|
2022-12-03 19:57:16 +00:00
|
|
|
if (_hint) then {
|
2024-08-02 11:59:18 +00:00
|
|
|
[LLSTRING(PutOnSafety), getText (configFile >> "CfgWeapons" >> _weapon >> "picture")] call EFUNC(common,displayTextPicture);
|
2022-12-03 19:57:16 +00:00
|
|
|
};
|