Skip to content

Commit

Permalink
Handle "" and non-existing weapons
Browse files Browse the repository at this point in the history
  • Loading branch information
johnb432 committed Jul 28, 2024
1 parent 3c45072 commit 8a26916
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions addons/common/fnc_selectWeapon.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ if (!local _unit) exitWith {false};

private _vehicle = [vehicle _unit, _unit] select (_unit call CBA_fnc_canUseWeapon);

// Holster weapon
if (_weapon == "") exitWith {
_unit action ["SwitchWeapon", _vehicle, _unit, 299];

currentMuzzle _unit == "" // return
};

// If on foot or in FFV
if (_unit isEqualTo _vehicle) then {
private _weaponState = (_unit weaponState _weapon) select [0, 3];
Expand All @@ -45,7 +52,7 @@ if (_unit isEqualTo _vehicle) then {
_unit selectWeapon _weaponState // return
} else {
private _turretPath = _vehicle unitTurret _unit;
(weaponState [_vehicle, _turretPath, _weapon]) params ["_weapon", "_muzzle", "_currentMode"];
(weaponState [_vehicle, _turretPath, _weapon]) params ["", "_muzzle", "_currentMode"];

if (_mode == "") then {
_mode = _currentMode;
Expand All @@ -54,7 +61,7 @@ if (_unit isEqualTo _vehicle) then {
_vehicle selectWeaponTurret [_weapon, _turretPath, _muzzle, _mode];

// Get updated state
(weaponState [_vehicle, _turretPath, _weapon]) params ["_newWeapon", "_newMuzzle", "_newMode"];
(weaponState [_vehicle, _turretPath]) params ["_newWeapon", "_newMuzzle", "_newMode"];

_newWeapon == _weapon && {_newMuzzle == _muzzle} && {_newMode == _mode} // return
};

0 comments on commit 8a26916

Please sign in to comment.