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).

79 changes: 79 additions & 0 deletions addons/interaction/functions/fnc_takeLauncher.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#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;
Cplhardcore marked this conversation as resolved.
Show resolved Hide resolved

if (_launcher isEqualTo "") exitWith {ERROR("No launcher specified.")};
if (secondaryWeapon _player != "") exitWith {ERROR("Cannot add launcher to target due to lack of inventory space.")};
Cplhardcore marked this conversation as resolved.
Show resolved Hide resolved
[_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);
fn_getWeaponStates =
{
params ["_target", "_launcher"];
private _origState = weaponState _target select [0,3];
private _muzzles = [_launcher] + (getArray (configFile >> "CfgWeapons" >> _launcher >> "muzzles") select { _x != "this" });
private _states = [];

{
_target selectWeapon _x;
_states pushBack weaponState _target;
} forEach _muzzles;

_target selectWeapon _origState;
_states;
};


private _result = [_target, _launcher] call fn_getWeaponStates;
private _attachments = _target weaponAccessories _launcher;
private _launcherAmmo = _result apply { _x select 3 };
private _launcherAmmoCount = _result apply { _x select 4 };
private _launcherMuzzle = _result apply { _x select 1 };
[_player, _launcher] call CBA_fnc_addWeaponWithoutItems;
{_player addSecondaryWeaponItem _x;} forEach _attachments;
for "_i" from 0 to (count _launcherMuzzle - 1) do {
private _muzzle = _launcherMuzzle select _i;
private _ammo = _launcherAmmo select _i;
private _count = _launcherAmmoCount select _i;
_player addWeaponItem [_launcher, [_ammo, _count, _muzzle]];

};

{_player addWeaponItem [_launcher, [_launcherAmmo, _launcherAmmoCount, _launcherMuzzle], true];} forEach _result;
_target removeWeapon _launcher;
[_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;
Cplhardcore marked this conversation as resolved.
Show resolved Hide resolved
[_player, _target, 0] call FUNC(tapShoulder);
},
{}, LLSTRING(PassingLauncher)] call EFUNC(common,progressBar);
16 changes: 16 additions & 0 deletions addons/interaction/initSettings.inc.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,19 @@
[[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",
Cplhardcore marked this conversation as resolved.
Show resolved Hide resolved
LSTRING(takeLauncherTime),
format ["ACE %1", LLSTRING(DisplayName)],
[1, 20, 5, 0],
true
Cplhardcore marked this conversation as resolved.
Show resolved Hide resolved
] 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