2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2021-03-04 17:43:11 +00:00
|
|
|
/*
|
|
|
|
* Author: mharis001, Dystopian
|
|
|
|
* Switches weapon attachment.
|
|
|
|
*
|
|
|
|
* Arguments:
|
2024-08-09 21:08:07 +00:00
|
|
|
* 0: Target (not used) <OBJECT>
|
|
|
|
* 1: Player <OBJECT>
|
2021-03-04 17:43:11 +00:00
|
|
|
* 2: Action params <ARRAY>
|
2024-08-09 21:08:07 +00:00
|
|
|
* - 0: Weapon <STRING>
|
|
|
|
* - 1: New Attachment <STRING>
|
|
|
|
* - 2: Old Attachment <STRING>
|
2021-03-04 17:43:11 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [player, player, [currentWeapon player, "acc_flashlight", ""]] call ace_interaction_fnc_switchWeaponAttachment
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2024-08-09 21:08:07 +00:00
|
|
|
params ["", "_unit", "_actionParams"];
|
2021-03-04 17:43:11 +00:00
|
|
|
_actionParams params ["_weapon", "_newAttachment", "_oldAttachment"];
|
|
|
|
TRACE_3("Switching attachment",_weapon,_newAttachment,_oldAttachment);
|
|
|
|
|
2024-08-09 21:08:07 +00:00
|
|
|
private _currWeaponType = [_unit, _weapon] call EFUNC(common,getWeaponIndex);
|
|
|
|
|
|
|
|
if (_currWeaponType == -1) exitWith {};
|
2021-03-04 17:43:11 +00:00
|
|
|
|
|
|
|
private _addNew = _newAttachment isNotEqualTo "";
|
|
|
|
private _removeOld = _oldAttachment isNotEqualTo "";
|
|
|
|
|
|
|
|
if (_addNew) then {
|
|
|
|
_unit removeItem _newAttachment;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_removeOld && {!([_unit, _oldAttachment] call CBA_fnc_canAddItem)}) exitWith {
|
|
|
|
LOG("no space");
|
|
|
|
[LELSTRING(common,Inventory_Full)] call EFUNC(common,displayTextStructured);
|
|
|
|
if (_addNew) then {
|
|
|
|
_unit addItem _newAttachment;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-09 21:08:07 +00:00
|
|
|
[_unit, "Gear"] call EFUNC(common,doGesture);
|
|
|
|
|
2021-03-04 17:43:11 +00:00
|
|
|
if (_removeOld) then {
|
|
|
|
[{
|
2024-08-09 21:08:07 +00:00
|
|
|
params ["_unit", "_currWeaponType", "_oldAttachment"];
|
|
|
|
|
|
|
|
switch (_currWeaponType) do {
|
|
|
|
case 0: {_unit removePrimaryWeaponItem _oldAttachment};
|
|
|
|
case 1: {_unit removeSecondaryWeaponItem _oldAttachment};
|
|
|
|
case 2: {_unit removeHandgunItem _oldAttachment};
|
|
|
|
default {};
|
2021-03-04 17:43:11 +00:00
|
|
|
};
|
2024-08-09 21:08:07 +00:00
|
|
|
|
2021-03-04 17:43:11 +00:00
|
|
|
_unit addItem _oldAttachment;
|
2024-08-09 21:08:07 +00:00
|
|
|
}, [_unit, _currWeaponType, _oldAttachment], 0.3] call CBA_fnc_waitAndExecute;
|
2021-03-04 17:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!_addNew) exitWith {};
|
|
|
|
|
|
|
|
[{
|
|
|
|
params ["_unit", "_weapon", "_newAttachment"];
|
2024-08-09 21:08:07 +00:00
|
|
|
|
2021-03-04 17:43:11 +00:00
|
|
|
_unit addWeaponItem [_weapon, _newAttachment];
|
2024-08-09 21:08:07 +00:00
|
|
|
|
|
|
|
if (_unit != ACE_player) exitWith {};
|
|
|
|
|
2021-03-04 17:43:11 +00:00
|
|
|
[[getText (configFile >> "CfgWeapons" >> _newAttachment >> "picture"), 4], true] call CBA_fnc_notify;
|
2024-08-09 21:08:07 +00:00
|
|
|
|
|
|
|
playSound "click";
|
2021-03-04 17:43:11 +00:00
|
|
|
}, [_unit, _weapon, _newAttachment], 1] call CBA_fnc_waitAndExecute;
|