Interaction - Pass Magazine fixes (#6894)

Use CBA_fnc_compatibleMagazines
Fix nil return if no mags
Ensure target canAdd
This commit is contained in:
PabstMirror 2019-03-30 20:49:59 -05:00 committed by GitHub
parent 30b99fa20a
commit 0052dd3af2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 9 deletions

View File

@ -21,9 +21,9 @@ params ["_player", "_target", "_weapon"];
if (!GVAR(enableMagazinePassing)) exitWith {false};
if (((vehicle _target) != _target) && {(vehicle _target) != (vehicle _player)}) exitWith {false};
private _compatibleMags = getArray (configfile >> "CfgWeapons" >> _weapon >> "magazines");
{
private _compatibleMags = [_weapon] call CBA_fnc_compatibleMagazines;
(magazinesAmmoFull _player) findIf {
_x params ["_className", "", "_loaded"];
if ((_className in _compatibleMags) && {!_loaded} && {_target canAdd _className}) exitWith {true};
false
} foreach (magazinesAmmoFull _player);
(_className in _compatibleMags) && {!_loaded} && {_target canAdd _className}
} > -1

View File

@ -12,21 +12,24 @@
* None
*
* Example:
* [_player, _target, "arifle_MX_F"] call ace_interaction_fnc_magToPassazine
* [_player, _target, "arifle_MX_F"] call ace_interaction_fnc_passMagazine
*
* Public: No
*/
params ["_player", "_target", "_weapon"];
private _compatibleMags = getArray (configfile >> "CfgWeapons" >> _weapon >> "magazines");
private _filteredMags = magazinesAmmoFull _player select {(_x select 0) in _compatibleMags && {!(_x select 2)}};
private _compatibleMags = [_weapon] call CBA_fnc_compatibleMagazines;
private _filteredMags = magazinesAmmoFull _player select {
_x params ["_className", "", "_loaded"];
(_className in _compatibleMags) && {!_loaded} && {_target canAdd _className}
};
//select magazine with most ammo
private _magToPass = _filteredMags select 0;
private _magToPassIndex = 0;
{
_x params ["_className", "_ammoCount"];
if ((_ammoCount > (_magToPass select 1)) && (_target canAdd _className)) then {
if (_ammoCount > (_magToPass select 1)) then {
_magToPass = _x;
_magToPassIndex = _forEachIndex;
};