Skip to content

Commit

Permalink
Safemode - Stop selecting weapons when toggling safemode (#10406)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnb432 authored Oct 13, 2024
1 parent 631db9d commit 5c4b912
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 8 additions & 3 deletions addons/safemode/functions/fnc_lockSafety.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "..\script_component.hpp"
/*
* Author: commy2, johnb43
* Puts weapon on safety, or take it off safety if safety is already put on.
* Puts weapon on safety, or takes it off safety if safety is already put on.
*
* Arguments:
* 0: Unit <OBJECT>
Expand Down Expand Up @@ -36,10 +36,13 @@ if (_muzzle in _safedWeaponMuzzles) exitWith {
[_unit, _weapon, _muzzle, _hint] call FUNC(unlockSafety);
};

private _weaponSelected = currentWeapon _unit == _weapon;
private _firemode = (_unit weaponState _muzzle) select 2;

// This syntax of selectWeapon doesn't mess with gun lights and lasers
_unit selectWeapon [_weapon, _muzzle, _firemode];
if (_weaponSelected) then {
_unit selectWeapon [_weapon, _muzzle, _firemode];
};

// Store new muzzle & firemode
_safedWeaponMuzzles set [_muzzle, _firemode];
Expand Down Expand Up @@ -83,7 +86,9 @@ if (isNil {_unit getVariable QGVAR(actionID)}) then {
};

// Play fire mode selector sound
[_unit, _weapon, _muzzle] call FUNC(playChangeFiremodeSound);
if (_weaponSelected) then {
[_unit, _weapon, _muzzle] call FUNC(playChangeFiremodeSound);
};

// Show info box unless disabled
if (_hint) then {
Expand Down
8 changes: 6 additions & 2 deletions addons/safemode/functions/fnc_unlockSafety.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ if (_safedWeaponMuzzles isEqualTo createHashMap) then {
};
};

private _weaponSelected = currentWeapon _unit == _weapon;

// Let engine handle switching to next firemode/muzzle
if (inputAction "nextWeapon" == 0 && {inputAction "prevWeapon" == 0}) then {
if (_weaponSelected && {inputAction "nextWeapon" == 0} && {inputAction "prevWeapon" == 0}) then {
// This syntax of selectWeapon doesn't mess with gun lights and lasers
_unit selectWeapon [_weapon, _muzzle, _firemode];

Expand All @@ -46,7 +48,9 @@ if (inputAction "nextWeapon" == 0 && {inputAction "prevWeapon" == 0}) then {
};

// Player HUD
true call FUNC(setSafeModeVisual);
if (_weaponSelected) then {
true call FUNC(setSafeModeVisual);
};

// Show info box unless disabled
if (_hint) then {
Expand Down

0 comments on commit 5c4b912

Please sign in to comment.