mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
59af3e1f6d
* medical_treatment * advanced_throwing * common, csw * Update fnc_replaceRegisteredItems.sqf * Sanitised numerous components * Update XEH_postInit.sqf * Update XEH_postInit.sqf * FUNC -> LINKFUNC * Changed tagging hashmap * Reverted some changes * Reverted some changes * Update XEH_clientInit.sqf * Tweaks and fixes * Fix number replacements * Minor cleanup * Update fnc_getMagazineName.sqf * Update fnc_getMagazineName.sqf * Minor improvement * Made factions case-sensitive and added `toLowerANSI` to be safe * Update fnc_getDetectedObject.sqf * Update addons/common/functions/fnc_actionKeysNamesConverted.sqf Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> * Throw error if item doesn't exist --------- Co-authored-by: Salluci <69561145+Salluci@users.noreply.github.com> Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
76 lines
2.3 KiB
Plaintext
76 lines
2.3 KiB
Plaintext
#include "..\script_component.hpp"
|
|
/*
|
|
* Author: commy2
|
|
* Select the next grenade.
|
|
*
|
|
* Arguments:
|
|
* 0: Unit <OBJECT>
|
|
* 1: Grenade type [0: all, 1: frags, 2: non-frags] (default: 0) <NUMBER>
|
|
*
|
|
* Return Value:
|
|
* Selecting successful? <BOOL>
|
|
*
|
|
* Example:
|
|
* [player] call ace_weaponselect_fnc_selectNextGrenade
|
|
*
|
|
* Public: Yes
|
|
*/
|
|
|
|
params ["_unit", ["_type", 0]];
|
|
|
|
// get currently selected grenade
|
|
private _currentGrenade = currentThrowable _unit;
|
|
|
|
// get correct array format if no grenade is selected
|
|
if (_currentGrenade isEqualTo []) then {
|
|
_currentGrenade = ["", ""];
|
|
};
|
|
|
|
_currentGrenade = _currentGrenade select 0;
|
|
|
|
// get available magazines for that unit
|
|
private _magazines = magazines _unit;
|
|
|
|
private _grenades = [];
|
|
|
|
{
|
|
if (_x in _magazines) then {
|
|
_grenades pushBack _x;
|
|
};
|
|
} forEach ([GVAR(GrenadesAll), GVAR(GrenadesFrag), GVAR(GrenadesNonFrag)] select _type);
|
|
|
|
// abort if no grenades are available
|
|
if (_grenades isEqualTo []) exitWith {false};
|
|
|
|
// get next grenade muzzle
|
|
private _nextGrenadeIndex = (_grenades find _currentGrenade) + 1;
|
|
|
|
// roll over if the last grenade was selected
|
|
if (_nextGrenadeIndex >= count _grenades) then {
|
|
_nextGrenadeIndex = 0;
|
|
};
|
|
|
|
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);
|
|
|
|
true
|