2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2019-10-08 01:19:04 +00:00
|
|
|
/*
|
2024-08-02 11:59:18 +00:00
|
|
|
* Author: Brostrom.A, johnb43
|
|
|
|
* Lock or unlock the given weapon based on weapon state.
|
2019-10-08 01:19:04 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Unit <OBJECT>
|
|
|
|
* 1: Weapon <STRING>
|
|
|
|
* 2: State <BOOL>
|
2022-12-03 19:57:16 +00:00
|
|
|
* 3: Show hint <BOOL> (default: true)
|
2024-08-02 11:59:18 +00:00
|
|
|
* 4: Muzzle <STRING> (default: current muzzle of weapon)
|
2019-10-08 01:19:04 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [ACE_player, currentWeapon ACE_player, true] call ace_safemode_fnc_setWeaponSafety
|
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
|
|
|
params [
|
|
|
|
["_unit", objNull, [objNull]],
|
|
|
|
["_weapon", "", [""]],
|
2022-12-03 19:57:16 +00:00
|
|
|
["_state", true, [true]],
|
2024-08-02 11:59:18 +00:00
|
|
|
["_hint", true, [true]],
|
|
|
|
["_muzzle", nil, [""]]
|
2019-10-08 01:19:04 +00:00
|
|
|
];
|
|
|
|
|
2024-08-02 11:59:18 +00:00
|
|
|
// Don't allow to set weapon safety if unit doesn't have one (but allow removing safety, in case unit doesn't have weapon anymore)
|
|
|
|
if (_weapon == "" || {_state && {!(_unit hasWeapon _weapon)}}) exitWith {};
|
2019-10-08 01:19:04 +00:00
|
|
|
|
2024-08-02 11:59:18 +00:00
|
|
|
// Check if weapon is a binocular
|
|
|
|
if ((_weapon call EFUNC(common,getItemType)) select 1 == "binocular") exitWith {};
|
2019-10-08 01:19:04 +00:00
|
|
|
|
2024-08-02 11:59:18 +00:00
|
|
|
// Check for invalid muzzles
|
|
|
|
_muzzle = if (isNil "_muzzle") then {
|
|
|
|
// Get current weapon muzzle if not defined
|
|
|
|
(_unit weaponState _weapon) select 1
|
|
|
|
} else {
|
|
|
|
// Get config case muzzle names
|
|
|
|
private _muzzles = _weapon call EFUNC(common,getWeaponMuzzles);
|
2019-10-08 01:19:04 +00:00
|
|
|
|
2024-08-02 11:59:18 +00:00
|
|
|
_muzzles param [_muzzles findIf {_x == _muzzle}, ""]
|
2019-10-08 01:19:04 +00:00
|
|
|
};
|
2024-08-02 11:59:18 +00:00
|
|
|
|
|
|
|
// Weapon is not available
|
|
|
|
if (_muzzle == "") exitWith {};
|
|
|
|
|
|
|
|
// If the weapon is already in the desired state, don't do anything
|
|
|
|
if (_state == (_muzzle in ((_unit getVariable [QGVAR(safedWeapons), createHashMap]) getOrDefault [_weapon, createHashMap]))) exitWith {};
|
|
|
|
|
|
|
|
[_unit, _weapon, _muzzle, _hint] call FUNC(lockSafety);
|