From b6822265242352a5da1b1aa9b74a4f1deda4867a Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:38:14 -0300 Subject: [PATCH] Weapon Select - Use `selectThrowable` command (#9488) * use selectThrowable * Update addons/weaponselect/functions/fnc_selectNextGrenade.sqf Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> * use throwables command --------- Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> --- .../functions/fnc_selectNextGrenade.sqf | 34 +++---------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/addons/weaponselect/functions/fnc_selectNextGrenade.sqf b/addons/weaponselect/functions/fnc_selectNextGrenade.sqf index ad17c7f18d9..03840de2013 100644 --- a/addons/weaponselect/functions/fnc_selectNextGrenade.sqf +++ b/addons/weaponselect/functions/fnc_selectNextGrenade.sqf @@ -28,16 +28,10 @@ if (_currentGrenade isEqualTo []) then { _currentGrenade = _currentGrenade select 0; -// get available magazines for that unit -private _magazines = magazines _unit; +private _grenadeType = [GVAR(GrenadesAll), GVAR(GrenadesFrag), GVAR(GrenadesNonFrag)] select _type; -private _grenades = []; - -{ - if (_x in _magazines) then { - _grenades pushBack _x; - }; -} forEach ([GVAR(GrenadesAll), GVAR(GrenadesFrag), GVAR(GrenadesNonFrag)] select _type); +// This is faster than checking magazines +private _grenades = (throwables _unit) apply {_x select 0} select {_x in _grenadeType}; // abort if no grenades are available if (_grenades isEqualTo []) exitWith {false}; @@ -52,24 +46,6 @@ if (_nextGrenadeIndex >= count _grenades) then { private _nextGrenade = _grenades select _nextGrenadeIndex; -// abort if the same grenade would be selected -if (_currentGrenade == _nextGrenade) exitWith {false}; - -// current best method to select a grenade: remove all grenades except the one you want to select, then add them back -private _uniformGrenades = uniformItems _unit select {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}; -private _vestGrenades = vestItems _unit select {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}; -private _backpackGrenades = backpackItems _unit select {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}; - -// remove all grenades except those we are switching to --> this breaks the selector -{_unit removeItemFromUniform _x} forEach _uniformGrenades; -{_unit removeItemFromVest _x} forEach _vestGrenades; -{_unit removeItemFromBackpack _x} forEach _backpackGrenades; - -// readd grenades -{_unit addItemToUniform _x} forEach _uniformGrenades; -{_unit addItemToVest _x} forEach _vestGrenades; -{_unit addItemToBackpack _x} forEach _backpackGrenades; - -[_nextGrenade, {_x == _nextGrenade} count _magazines] call FUNC(displayGrenadeTypeAndNumber); +[_nextGrenade, {_x == _nextGrenade} count (magazines _unit)] call FUNC(displayGrenadeTypeAndNumber); -true +_unit selectThrowable _nextGrenade // return