diff --git a/addons/interaction/CfgVehicles.hpp b/addons/interaction/CfgVehicles.hpp index 614cd3e0e06..cc4742d0dab 100644 --- a/addons/interaction/CfgVehicles.hpp +++ b/addons/interaction/CfgVehicles.hpp @@ -68,6 +68,15 @@ class CfgVehicles { }; }; + class ACE_PassThrowable { + displayName = CSTRING(PassThrowable); + condition = QUOTE([ARR_3(_player,_target,(currentThrowable _player) param [ARR_2(0,'')])] call FUNC(canPassThrowable)); + statement = QUOTE([ARR_3(_player,_target,(currentThrowable _player) param [ARR_2(0,'')])] call FUNC(passThrowable)); + exceptions[] = {"isNotSwimming"}; + showDisabled = 0; + modifierFunction = QUOTE(_this select 3 set [ARR_2(2,getText (configFile >> 'CfgMagazines' >> (currentThrowable (_this select 1)) param [ARR_2(0,'HandGrenade')] >> 'picture'))];); // Set picture of the current throwable + }; + class ACE_TeamManagement { displayName = CSTRING(TeamManagement); condition = QUOTE([ARR_2(_player,_target)] call DFUNC(canJoinTeam) && {GVAR(EnableTeamManagement)}); diff --git a/addons/interaction/XEH_PREP.hpp b/addons/interaction/XEH_PREP.hpp index 63053fd5122..dc6e5f41a23 100644 --- a/addons/interaction/XEH_PREP.hpp +++ b/addons/interaction/XEH_PREP.hpp @@ -24,7 +24,9 @@ PREP(modifyTeamManagementAction); PREP(canJoinTeam); PREP(joinTeam); PREP(canPassMagazine); +PREP(canPassThrowable); PREP(passMagazine); +PREP(passThrowable); PREP(canBecomeLeader); PREP(doBecomeLeader); PREP(doRemoteControl); diff --git a/addons/interaction/functions/fnc_canPassThrowable.sqf b/addons/interaction/functions/fnc_canPassThrowable.sqf new file mode 100644 index 00000000000..a15e851d66a --- /dev/null +++ b/addons/interaction/functions/fnc_canPassThrowable.sqf @@ -0,0 +1,28 @@ +#include "..\script_component.hpp" +/* + * Author: Timi007 + * Checks if target unit can accept given throwable. + * Does not check if the throwable exists in the inventory of the player. + * + * Arguments: + * 0: Unit that passes the throwable + * 1: Unit to pass the throwable to + * 2: Throwable classname + * + * Return Value: + * Unit can pass throwable + * + * Example: + * [_player, _target, "HandGrenade"] call ace_interaction_fnc_canPassThrowable + * + * Public: No + */ + +params ["_player", "_target", "_throwable"]; + +if (!GVAR(enableThrowablePassing)) exitWith {false}; +if (_throwable isEqualTo "") exitWith {false}; +if !(_target call EFUNC(common,isAwake)) exitWith {false}; +if ((!isNull objectParent _target) && {(vehicle _target) isNotEqualTo (vehicle _player)}) exitWith {false}; + +[_target, _throwable] call CBA_fnc_canAddItem diff --git a/addons/interaction/functions/fnc_passThrowable.sqf b/addons/interaction/functions/fnc_passThrowable.sqf new file mode 100644 index 00000000000..e765b0e0697 --- /dev/null +++ b/addons/interaction/functions/fnc_passThrowable.sqf @@ -0,0 +1,57 @@ +#include "..\script_component.hpp" +/* + * Author: Timi007 + * Pass throwable to another unit. + * + * Arguments: + * 0: Unit that passes the throwable + * 1: Unit to pass the throwable to + * 2: Throwable classname + * 3: Play passing animation (default: true) + * + * Return Value: + * None + * + * Example: + * [_player, _target, "HandGrenade"] call ace_interaction_fnc_passThrowable + * + * Public: No + */ + +params ["_player", "_target", "_throwable", ["_animate", true, [true]]]; +TRACE_4("Pass throwable params",_player,_target,_throwable,_animate); + +if (_throwable isEqualTo "") exitWith {ERROR("No throwable specified.")}; +if !([_target, _throwable] call CBA_fnc_canAddItem) exitWith {ERROR("Cannot add throwable to target due to lack of inventory space.")}; + +private _allOccurrencesOfThrowable = (magazinesAmmoFull _player) select {(_x select 0) == _throwable}; +if (_allOccurrencesOfThrowable isEqualTo []) exitWith {ERROR("Throwable not in the inventory of player.")}; + +private _cfgThrowable = configFile >> "CfgMagazines" >> _throwable; +if ((getNumber (_cfgThrowable >> "count")) == 1) then { + // Optimized and straightforward case, as most throwables only have an ammo count of 1 + _player removeItem _throwable; + _target addItem _throwable; +} else { + // Some throwables have more than 1 ammo count ("vn_v40_grenade_mag") + + // Get highest ammo count available + private _highestAmmoCount = (_allOccurrencesOfThrowable select 0) select 1; + { + _x params ["", "_ammoCount"]; + + if (_ammoCount > _highestAmmoCount) then { + _highestAmmoCount = _ammoCount; + }; + } forEach _allOccurrencesOfThrowable; + + TRACE_2("Passing throwable with most ammo",_throwable,_highestAmmoCount); + [_player, _throwable, _highestAmmoCount] call EFUNC(common,removeSpecificMagazine); + _target addMagazine [_throwable, _highestAmmoCount]; +}; + +if (_animate) then {[_player, "PutDown"] call EFUNC(common,doGesture)}; + +private _playerName = [_player] call EFUNC(common,getName); +private _displayName = getText (_cfgThrowable >> "displayName"); +[QEGVAR(common,displayTextStructured), [[LSTRING(PassThrowableHint), _playerName, _displayName], 1.5, _target], [_target]] call CBA_fnc_targetEvent; diff --git a/addons/interaction/initSettings.inc.sqf b/addons/interaction/initSettings.inc.sqf index f634b44313f..6ff2f17ffb0 100644 --- a/addons/interaction/initSettings.inc.sqf +++ b/addons/interaction/initSettings.inc.sqf @@ -21,6 +21,13 @@ true ] call CBA_fnc_addSetting; +[ + QGVAR(enableThrowablePassing), "CHECKBOX", + LSTRING(PassThrowableSetting), + format ["ACE %1", LLSTRING(DisplayName)], + true +] call CBA_fnc_addSetting; + [ QGVAR(disableNegativeRating), "CHECKBOX", [LSTRING(DisableNegativeRating_DisplayName), LSTRING(DisableNegativeRating_Description)], diff --git a/addons/interaction/stringtable.xml b/addons/interaction/stringtable.xml index 4d4e2d61e50..adc4b7ef417 100644 --- a/addons/interaction/stringtable.xml +++ b/addons/interaction/stringtable.xml @@ -849,6 +849,18 @@ 顯示"給予彈匣"互動動作 显示"给予弹匣"互动动作 + + Pass grenade + Granate geben + + + %1 passed you %2. + %1 hat dir %2 gegeben. + + + Show "pass grenade" interaction + Zeige "Granate geben" Interaktion + Passengers Pasažéři diff --git a/docs/wiki/feature/interaction.md b/docs/wiki/feature/interaction.md index 7e34645687f..8ab548dc3ed 100644 --- a/docs/wiki/feature/interaction.md +++ b/docs/wiki/feature/interaction.md @@ -45,3 +45,6 @@ Some of the zeus actions are also available (while in zeus) in the interaction m - Open the interaction menu. - Select `Waypoints`. - From here you can modify the speed / formation / behavior of the units / groups that are moving to that waypoint. + +### 2.4 Passing a grenade +- Using the "Pass grenade" action, you can pass the currently selected grenade or throwable (which will be thrown if you press G) to another unit.