Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interaction - Add "pass grenade" interaction #10463

Merged
merged 13 commits into from
Nov 16, 2024
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(_target,_player,(currentThrowable _player) param [ARR_2(0,'')])] call FUNC(canPassThrowable));
statement = QUOTE([ARR_3(_target,_player,(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 grenade
};

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 to pass the throwable to <OBJECT>
* 1: Unit that passes the throwable <OBJECT>
Timi007 marked this conversation as resolved.
Show resolved Hide resolved
* 2: Throwable classname <STRING>
*
* Return Value:
* Unit can pass throwables <BOOL>
Timi007 marked this conversation as resolved.
Show resolved Hide resolved
*
* Example:
* [_target, _player, "HandGrenade"] call ace_interaction_fnc_canPassThrowable
Timi007 marked this conversation as resolved.
Show resolved Hide resolved
*
* Public: No
*/

params [["_target", objNull, [objNull]], ["_player", objNull, [objNull]], ["_throwable", "", [""]]];
Timi007 marked this conversation as resolved.
Show resolved Hide resolved

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
36 changes: 36 additions & 0 deletions addons/interaction/functions/fnc_passThrowable.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "..\script_component.hpp"
/*
* Author: Timi007
* Pass throwable to another unit.
*
* Arguments:
* 0: Unit to pass the throwable to <OBJECT>
* 1: Unit that passes the throwable <OBJECT>
Timi007 marked this conversation as resolved.
Show resolved Hide resolved
* 2: Throwable classname <STRING>
* 3: Play passing animation <BOOL> (default: true)
*
* Return Value:
* None
*
* Example:
* [_target, _player, "HandGrenade"] call ace_interaction_fnc_passThrowable
Timi007 marked this conversation as resolved.
Show resolved Hide resolved
*
* Public: No
*/

params [["_target", objNull, [objNull]], ["_player", objNull, [objNull]], ["_throwable", "", [""]], ["_animate", true, [true]]];
Timi007 marked this conversation as resolved.
Show resolved Hide resolved
TRACE_4("Pass throwable params",_player,_target,_throwable,_animate);

if (isNull _target) exitWith {ERROR("Target is null.")};
if (isNull _player) exitWith {ERROR("Player is null.")};
Timi007 marked this conversation as resolved.
Show resolved Hide resolved
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.")};

if (_animate) then {[_player, "PutDown"] call EFUNC(common,doGesture)};

_player removeItem _throwable;
_target addItem _throwable;
Timi007 marked this conversation as resolved.
Show resolved Hide resolved

private _displayName = getText (configFile >> 'CfgMagazines' >> _throwable >> 'displayName');
private _playerName = [_player] call EFUNC(common,getName);
[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 @@ -1260,6 +1260,18 @@
<Chinesesimp>显示"给予弹匣"互动动作</Chinesesimp>
<Chinese>顯示"給予彈匣"互動動作</Chinese>
</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_PullOutBody">
<English>Pull out body</English>
<German>Person herausziehen</German>
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.