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 Interaction to take another players launcher #10541

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
8 changes: 8 additions & 0 deletions addons/interaction/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ class CfgVehicles {
};
};

class ACE_TakeLauncher {
displayName = CSTRING(takeLauncher);
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTakeLauncher));
statement = QUOTE([ARR_3(_player,_target,(secondaryWeapon _target))] call FUNC(takeLauncher));
exceptions[] = {"isNotSwimming"};
showDisabled = 0;
};

class ACE_PassThrowable {
displayName = CSTRING(PassThrowable);
condition = QUOTE([ARR_3(_player,_target,(currentThrowable _player) param [ARR_2(0,'')])] call FUNC(canPassThrowable));
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 @@ -39,6 +39,8 @@ PREP(pullOutBody);
PREP(canRenameGroup);
PREP(renameGroupUI);
PREP(renameGroup);
PREP(canTakeLauncher);
PREP(takeLauncher);

// Weapon Attachments
PREP(getWeaponAttachmentsActions);
Expand Down
28 changes: 28 additions & 0 deletions addons/interaction/functions/fnc_canTakeLauncher.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "..\script_component.hpp"
/*
* Author: Timi007, Cplhardcore
* Checks if target unit can accept given launcher.
* Does not check if the launcher exists in the inventory of the player.
*
* Arguments:
* 0: Unit that passes the launcher <OBJECT>
* 1: Unit to pass the launcher to <OBJECT>
* 2: Launcher classname <STRING>
*
* Return Value:
* Unit can pass launcher <BOOL>
*
* Example:
* [_player, _target, "launch_NLAW_F"] call ace_interaction_fnc_canTakeLauncher
*
* Public: No
*/

params ["_player", "_target"];
if (GVAR(enableLauncherTaking) &&
secondaryWeapon _target != "" &&
secondaryWeapon _player == "" &&
isNull objectParent _target &&
isNull objectParent _player &&
side _target == side _player) exitWith {true};
false
Comment on lines +22 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (GVAR(enableLauncherTaking) &&
secondaryWeapon _target != "" &&
secondaryWeapon _player == "" &&
isNull objectParent _target &&
isNull objectParent _player &&
side _target == side _player) exitWith {true};
false
GVAR(enableLauncherTaking) &&
secondaryWeapon _target != "" &&
secondaryWeapon _player == "" &&
isNull objectParent _target &&
isNull objectParent _player &&
side _target == side _player

I'd personally also wrap every single statement in a lazy eval, but I haven't tested the performance impact.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this would work when the target is unconscious, as side changes. Imo would be better to check if the sides have friendly relations (using the sides of the group).

59 changes: 59 additions & 0 deletions addons/interaction/functions/fnc_takeLauncher.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "..\script_component.hpp"
/*
* Author: Timi007. Cplhardcore
* Pass launcher to another unit.
*
* Arguments:
* 0: Unit that passes the launcher <OBJECT>
* 1: Unit to pass the launcher to <OBJECT>
* 2: Launcher classname <STRING>
*
*
* Return Value:
* None
*
* Example:
* [_player, _target, "launch_NLAW_F"] call ace_interaction_fnc_passLauncher
*
* Public: No
*/
params ["_player", "_target", "_launcher"];
TRACE_3("Take launcher params",_player,_target,_launcher);

private _playerName = [_player] call EFUNC(common,getName);
private _cfgWeapons = configFile >> "CfgWeapons" >> _launcher;
private _displayName = getText (_cfgWeapons >> "displayName");
[QEGVAR(common,displayTextStructured), [[LSTRING(TakingLauncherHint), _playerName, _displayName], 1.5, _target], _target] call CBA_fnc_targetEvent;

if (_launcher isEqualTo "") exitWith {ERROR("No launcher specified.")};
if (secondaryWeapon _player isNotEqualTo "") exitWith {ERROR("Cannot add launcher to target due to lack of inventory space.")};
[_player, _target, 0] call FUNC(tapShoulder);
[GVAR(launcherTime),
[_player, _target, _launcher, _displayName],
{
params ["_args"];
_args params ["_player", "_target", "_launcher", "_displayName"];
TRACE_4("launcher params",_player,_target,_launcher,_displayName);
private _items = (getUnitLoadout _target) select 1;

private _magazines = _items select [4, 2];
_items deleteRange [4, 2];

_target removeWeapon _launcher;

[_player, _launcher, true, _magazines] call EFUNC(common,addWeapon);

// Add attachments
{
_player addWeaponItem [_launcher, _x, true];
} forEach (_items select {_x != ""});

[_player, "PutDown"] call EFUNC(common,doGesture);

private _playerName = [_player] call EFUNC(common,getName);
private _targetName = [_target] call EFUNC(common,getName);
[QEGVAR(common,displayTextStructured), [[LSTRING(GaveLauncherHint), _playerName, _displayName], 1.5, _target], _target] call CBA_fnc_targetEvent;
[QEGVAR(common,displayTextStructured), [[LSTRING(TookLauncherHint), _targetName, _displayName], 1.5, _player], _player] call CBA_fnc_targetEvent;
[_player, _target, 0] call FUNC(tapShoulder);
},
{}, LLSTRING(PassingLauncher)] call EFUNC(common,progressBar);
15 changes: 15 additions & 0 deletions addons/interaction/initSettings.inc.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,18 @@
[[0, 1, 2], [ELSTRING(common,Never), LSTRING(interactWithEnemyCrew_allowCSW), ELSTRING(common,Always)], 0],
true
] call CBA_fnc_addSetting;

[
QGVAR(enableLauncherTaking), "CHECKBOX",
LSTRING(takeLauncherSetting),
format ["ACE %1", LLSTRING(DisplayName)],
true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Not a fan of the default value, imo it should be off.
  2. This should be a synced setting imo.

] call CBA_fnc_addSetting;

[
QGVAR(launcherTime), "SLIDER",
LSTRING(takeLauncherTime),
format ["ACE %1", LLSTRING(DisplayName)],
[1, 20, 5, 0],
1
] call CBA_fnc_addSetting;
21 changes: 21 additions & 0 deletions addons/interaction/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1425,5 +1425,26 @@
<Japanese>インタラクションから使用中の武器に対してのアタッチメント取り外しを可能にします。</Japanese>
<Chinesesimp>启用当前武器的附加/拆卸武器配件的动作。</Chinesesimp>
</Key>
<Key ID="STR_ACE_Interaction_takeLauncher">
<English>Take Launcher</English>
</Key>
<Key ID="STR_ACE_Interaction_takeLauncherSetting">
<English>Allow people to take Launchers</English>
</Key>
<Key ID="STR_ACE_Interaction_PassLauncherHint">
<English>%1 is taking your %2 off your back</English>
</Key>
<Key ID="STR_ACE_Interaction_GaveLauncherHint">
<English>%1 took your %2 off your back</English>
</Key>
<Key ID="STR_ACE_Interaction_TookLauncherHint">
<English>You took %1's %2</English>
</Key>
<Key ID="STR_ACE_Interaction_PassingLauncher">
<English>Taking Launcher</English>
</Key>
<Key ID="STR_ACE_Interaction_takeLauncherTime">
<English>How long it takes to take a launcher</English>
</Key>
</Package>
</Project>
Loading