diff --git a/addons/interaction/CfgVehicles.hpp b/addons/interaction/CfgVehicles.hpp index 2587869803..eff8a32f3d 100644 --- a/addons/interaction/CfgVehicles.hpp +++ b/addons/interaction/CfgVehicles.hpp @@ -34,7 +34,7 @@ class CfgVehicles { class ACE_PassMagazine { displayName = CSTRING(PassMagazine); - condition = QUOTE([ARR_2(_player,primaryWeapon _target)] call FUNC(canPassMagazine) || [ARR_2(_player,handgunWeapon _target)] call FUNC(canPassMagazine)); + condition = QUOTE([ARR_3(_player,_target,primaryWeapon _target)] call FUNC(canPassMagazine) || [ARR_3(_player,_target,handgunWeapon _target)] call FUNC(canPassMagazine)); statement = ""; showDisabled = 0; priority = 3.3; @@ -42,7 +42,7 @@ class CfgVehicles { class ACE_PassMagazinePrimary { displayName = CSTRING(PassMagazinePrimary); - condition = QUOTE([ARR_2(_player,primaryWeapon _target)] call FUNC(canPassMagazine)); + condition = QUOTE([ARR_3(_player,_target,primaryWeapon _target)] call FUNC(canPassMagazine)); statement = QUOTE([ARR_3(_player,_target,primaryWeapon _target)] call FUNC(passMagazine)); showDisabled = 0; priority = 3; @@ -50,7 +50,7 @@ class CfgVehicles { }; class ACE_PassMagazineHandgun { displayName = CSTRING(PassMagazineHandgun); - condition = QUOTE([ARR_2(_player,handgunWeapon _target)] call FUNC(canPassMagazine)); + condition = QUOTE([ARR_3(_player,_target,handgunWeapon _target)] call FUNC(canPassMagazine)); statement = QUOTE([ARR_3(_player,_target,handgunWeapon _target)] call FUNC(passMagazine)); showDisabled = 0; priority = 1; diff --git a/addons/interaction/XEH_preInit.sqf b/addons/interaction/XEH_preInit.sqf index 7c64e7df75..5b3283da51 100644 --- a/addons/interaction/XEH_preInit.sqf +++ b/addons/interaction/XEH_preInit.sqf @@ -29,6 +29,7 @@ PREP(openDoor); PREP(openMenuSelectUI); PREP(openSelectMenu); PREP(passMagazine); +PREP(passMagazineLocal); PREP(prepareSelectMenu); PREP(push); PREP(removeTag); diff --git a/addons/interaction/functions/fnc_canPassMagazine.sqf b/addons/interaction/functions/fnc_canPassMagazine.sqf index 3a99c3924f..20920ef63b 100644 --- a/addons/interaction/functions/fnc_canPassMagazine.sqf +++ b/addons/interaction/functions/fnc_canPassMagazine.sqf @@ -3,23 +3,29 @@ * Checks if unit has a spare magazine for the specified weapon. * * Arguments: - * 0: Unit that gets searched - * 1: Weapon classname + * 0: Unit that passes the magazine + * 1: Unit to pass the magazine to + * 2: Weapon classname * * Return Value: * None * * Example: - * [_player, "arifle_MX_F"] call ace_interaction_fnc_canPassMagazine + * [_player, _target, "arifle_MX_F"] call ace_interaction_fnc_canPassMagazine * * Public: No */ #include "script_component.hpp" -params ["_player", "_weapon"]; -private ["_compatibleMags", "_filterFunc"]; +params ["_player", "_target", "_weapon"]; +private ["_compatibleMags", "_filterFunc", "_filteredMags"]; _compatibleMags = getArray (configfile >> "CfgWeapons" >> _weapon >> "magazines"); _filterFunc = compile format ["((_this select 0) in %1) && (!(_this select 2))", _compatibleMags]; +_filteredMags = [magazinesAmmoFull _player, _filterFunc] call EFUNC(common,filter); -count ([magazinesAmmoFull _player, _filterFunc] call EFUNC(common,filter)) > 0 \ No newline at end of file +if (count _filteredMags > 0) then { + ({(_target canAddItemToUniform (_x select 0)) || (_target canAddItemToVest (_x select 0)) || (_target canAddItemToBackpack (_x select 0))} count _filteredMags) > 0 +} else { + false +}; \ No newline at end of file diff --git a/addons/interaction/functions/fnc_passMagazine.sqf b/addons/interaction/functions/fnc_passMagazine.sqf index 75762e6dea..f126577e10 100644 --- a/addons/interaction/functions/fnc_passMagazine.sqf +++ b/addons/interaction/functions/fnc_passMagazine.sqf @@ -29,7 +29,7 @@ _filteredMags = [magazinesAmmoFull _player, _filterFunc] call EFUNC(common,filte _magToPass = _filteredMags select 0; _magToPassIndex = 0; { - if ((_x select 1) > (_magToPass select 1)) then { + if (((_x select 1) > (_magToPass select 1)) && ((_target canAddItemToUniform (_x select 0)) || (_target canAddItemToVest (_x select 0)) || (_target canAddItemToBackpack (_x select 0)))) then { _magToPass = _x; _magToPassIndex = _forEachIndex; }; @@ -46,5 +46,4 @@ _player removeMagazines (_magToPass select 0); _player playActionNow "PutDown"; -_target addMagazine [_magToPass select 0, _magToPass select 1]; -[[parseText format [CSTRING(PassMagazineHint), name _player, _magToPass select 0]], QUOTE(FUNC(common,displayTextStructured)), _target] call EFUNC(common,execRemoteFnc); \ No newline at end of file +[[_player, _target, _magToPass select 0, _magToPass select 1], QUOTE(FUNC(passMagazineLocal)), _target] call EFUNC(common,execRemoteFnc); \ No newline at end of file diff --git a/addons/interaction/functions/fnc_passMagazineLocal.sqf b/addons/interaction/functions/fnc_passMagazineLocal.sqf new file mode 100644 index 0000000000..631a7c0250 --- /dev/null +++ b/addons/interaction/functions/fnc_passMagazineLocal.sqf @@ -0,0 +1,26 @@ +/* + * Author: BaerMitUmlaut + * Pass spare magazine for the specified weapon. + * + * Arguments: + * 0: Unit that passes the magazine + * 1: Unit to pass the magazine to + * 2: Magazine classname + * 3: Amount of rounds in magazine + * + * Return Value: + * None + * + * Example: + * [_unit, _player, "30Rnd_65x39_caseless_mag", 30] call ace_interaction_fnc_magToPassazine + * + * Public: No + */ + +#include "script_component.hpp" +params ["_unit", "_target", "_magazine", "_ammoCount"]; + +_target addMagazine [_magazine, _ammoCount]; +if (_target == ACE_player) then { + [parseText format [localize LSTRING(PassMagazineHint), name _unit, getText (configFile >> "CfgMagazines" >> _magazine >> "displayName")]] call EFUNC(common,displayTextStructured); +}; \ No newline at end of file