-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Interaction - Add "pass grenade" interaction (#10463)
* 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
Showing
7 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters