From b514541bec6f3335bfbb55f08ebc3d6c44433244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brostr=C3=B6m=2EA=20=7C=20Evul?= Date: Tue, 8 Oct 2019 03:19:04 +0200 Subject: [PATCH] Safemode - add public setWeaponSafety function (#7092) * Create fn_safeWeapon.sqf * Update XEH_PREP.hpp * Adjustments to script to meet demands not tested * adjustment according to review * minor adjustments * Update fn_safeWeapon.sqf * Rename and adjustments * Adjustments * Fixed typo Co-Authored-By: commy2 * Update addons/safemode/functions/fn_setWeaponSafety.sqf Co-Authored-By: commy2 * Update addons/safemode/functions/fn_setWeaponSafety.sqf Co-Authored-By: commy2 * Fixed missing param in exsample * Test fixes * Update addons/safemode/functions/fnc_setWeaponSafety.sqf Co-Authored-By: Filip Maciejewski --- addons/safemode/XEH_PREP.hpp | 1 + .../functions/fnc_setWeaponSafety.sqf | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 addons/safemode/functions/fnc_setWeaponSafety.sqf diff --git a/addons/safemode/XEH_PREP.hpp b/addons/safemode/XEH_PREP.hpp index ab2a755a663..2f23aa02c9e 100644 --- a/addons/safemode/XEH_PREP.hpp +++ b/addons/safemode/XEH_PREP.hpp @@ -3,3 +3,4 @@ PREP(lockSafety); PREP(playChangeFiremodeSound); PREP(setSafeModeVisual); PREP(unlockSafety); +PREP(setWeaponSafety); diff --git a/addons/safemode/functions/fnc_setWeaponSafety.sqf b/addons/safemode/functions/fnc_setWeaponSafety.sqf new file mode 100644 index 00000000000..4ad0174b202 --- /dev/null +++ b/addons/safemode/functions/fnc_setWeaponSafety.sqf @@ -0,0 +1,36 @@ +#include "script_component.hpp" +/* + * Author: Brostrom.A + * Safe or unsafe the given weapon based on weapon state; locked or unlocked. + * + * Arguments: + * 0: Unit + * 1: Weapon + * 2: State + * + * Return Value: + * None + * + * Example: + * [ACE_player, currentWeapon ACE_player, true] call ace_safemode_fnc_setWeaponSafety + * + * Public: Yes + */ + +params [ + ["_unit", objNull, [objNull]], + ["_weapon", "", [""]], + ["_state", true, [true]] +]; + +if (_weapon == "") exitWith {}; + +private _safedWeapons = _unit getVariable [QGVAR(safedWeapons), []]; + +_weapon = configName (configFile >> "CfgWeapons" >> _weapon); + +private _muzzle = currentMuzzle _unit; + +if !(_state isEqualTo (_weapon in _safedWeapons)) then { + [_unit, _weapon, _muzzle] call FUNC(lockSafety); +};