Skip to content

Commit

Permalink
Interaction - Add "pass grenade" interaction (#10463)
Browse files Browse the repository at this point in the history
* Add "pass grenade" interaction

* Fix docs

* Correct spelling

* Change to one node and pass only currently selected grenade

* Handle currentThrowable returns empty array

* Add documentation

* Update addons/interaction/functions/fnc_canPassThrowable.sqf

Co-authored-by: johnb432 <[email protected]>

* Handle throwables with ammo count greater 1

* Update single quotes to double quotes

* Switch target and player parameters & remove default values

* Update stringtable.xml

---------

Co-authored-by: johnb432 <[email protected]>
  • Loading branch information
Timi007 and johnb432 authored Nov 16, 2024
1 parent a2f3783 commit 0d1089d
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 0 deletions.
9 changes: 9 additions & 0 deletions addons/interaction/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)});
Expand Down
2 changes: 2 additions & 0 deletions addons/interaction/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ PREP(modifyTeamManagementAction);
PREP(canJoinTeam);
PREP(joinTeam);
PREP(canPassMagazine);
PREP(canPassThrowable);
PREP(passMagazine);
PREP(passThrowable);
PREP(canBecomeLeader);
PREP(doBecomeLeader);
PREP(doRemoteControl);
Expand Down
28 changes: 28 additions & 0 deletions addons/interaction/functions/fnc_canPassThrowable.sqf
Original file line number Diff line number Diff line change
@@ -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 <OBJECT>
* 1: Unit to pass the throwable to <OBJECT>
* 2: Throwable classname <STRING>
*
* Return Value:
* Unit can pass throwable <BOOL>
*
* 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
57 changes: 57 additions & 0 deletions addons/interaction/functions/fnc_passThrowable.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "..\script_component.hpp"
/*
* Author: Timi007
* Pass throwable to another unit.
*
* Arguments:
* 0: Unit that passes the throwable <OBJECT>
* 1: Unit to pass the throwable to <OBJECT>
* 2: Throwable classname <STRING>
* 3: Play passing animation <BOOL> (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;
7 changes: 7 additions & 0 deletions addons/interaction/initSettings.inc.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand Down
12 changes: 12 additions & 0 deletions addons/interaction/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,18 @@
<Chinese>顯示"給予彈匣"互動動作</Chinese>
<Chinesesimp>显示"给予弹匣"互动动作</Chinesesimp>
</Key>
<Key ID="STR_ACE_Interaction_PassThrowable">
<English>Pass grenade</English>
<German>Granate geben</German>
</Key>
<Key ID="STR_ACE_Interaction_PassThrowableHint">
<English>%1 passed you %2.</English>
<German>%1 hat dir %2 gegeben.</German>
</Key>
<Key ID="STR_ACE_Interaction_PassThrowableSetting">
<English>Show "pass grenade" interaction</English>
<German>Zeige "Granate geben" Interaktion</German>
</Key>
<Key ID="STR_ACE_Interaction_Passengers">
<English>Passengers</English>
<Czech>Pasažéři</Czech>
Expand Down
3 changes: 3 additions & 0 deletions docs/wiki/feature/interaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kbd>G</kbd>) to another unit.

0 comments on commit 0d1089d

Please sign in to comment.