mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Interaction - Improve FUNC(switchWeaponAttachment)
(#10145)
* Improve swtichWeaponAttachment * change interact_SWA to use common_SAM (#10176) * change interact_SWA to use common_SAM * Directly call * exit on bad arg * Update fnc_switchAttachmentMode.sqf * Minor optimisations * Cleanup leftover code, use unit instead of target --------- Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> * Update addons/interaction/functions/fnc_switchWeaponAttachment.sqf * Revert some unnecessary changes * Remove sound, as it was part of the CBA attachment switching & pass missing parameter * Add sound back, to indicate new attachment --------- Co-authored-by: PabstMirror <pabstmirror@gmail.com>
This commit is contained in:
parent
5afe06999f
commit
4db0f7de24
@ -2,26 +2,31 @@
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Switch attachment from one mode to another - based on CBA_accessory_fnc_switchAttachment
|
||||
* ToDo: Port this to CBA?
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Unit <OBJECT>
|
||||
* 1: From <STRING>
|
||||
* 2: To <STRING>
|
||||
* 1: Weapon (String or CBA-Weapon-Index (not ace's getWeaponIndex)) <STRING|NUMBER>
|
||||
* 2: From <STRING>
|
||||
* 3: To <STRING>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [player, "ACE_DBAL_A3_Green_VP", "ACE_DBAL_A3_Green"] call ace_common_fnc_switchAttachmentMode
|
||||
* [player, 0, "ACE_DBAL_A3_Green_VP", "ACE_DBAL_A3_Green"] call ace_common_fnc_switchAttachmentMode
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
params ["_unit", "_currItem", "_switchItem"];
|
||||
TRACE_3("switchAttachmentMode",_unit,_currItem,_switchItem);
|
||||
|
||||
switch (currentWeapon _unit) do {
|
||||
case (""): {};
|
||||
params ["_unit", "_weapon", "_currItem", "_switchItem"];
|
||||
TRACE_4("switchAttachmentMode",_unit,_weapon,_currItem,_switchItem);
|
||||
|
||||
if (_weapon isEqualTo "") exitWith {};
|
||||
|
||||
private _exit = _unit != ACE_player;
|
||||
switch (_weapon) do {
|
||||
case 0;
|
||||
case (primaryWeapon _unit): {
|
||||
private _currWeaponType = 0;
|
||||
_unit removePrimaryWeaponItem _currItem;
|
||||
@ -31,6 +36,7 @@ switch (currentWeapon _unit) do {
|
||||
["CBA_attachmentSwitched", _this] call CBA_fnc_localEvent;
|
||||
}, [_unit, _currItem, _switchItem, _currWeaponType]] call CBA_fnc_execNextFrame;
|
||||
};
|
||||
case 1;
|
||||
case (handgunWeapon _unit): {
|
||||
private _currWeaponType = 1;
|
||||
_unit removeHandgunItem _currItem;
|
||||
@ -40,6 +46,7 @@ switch (currentWeapon _unit) do {
|
||||
["CBA_attachmentSwitched", _this] call CBA_fnc_localEvent;
|
||||
}, [_unit, _currItem, _switchItem, _currWeaponType]] call CBA_fnc_execNextFrame;
|
||||
};
|
||||
case 2;
|
||||
case (secondaryWeapon _unit): {
|
||||
private _currWeaponType = 2;
|
||||
_unit removeSecondaryWeaponItem _currItem;
|
||||
@ -49,13 +56,18 @@ switch (currentWeapon _unit) do {
|
||||
["CBA_attachmentSwitched", _this] call CBA_fnc_localEvent;
|
||||
}, [_unit, _currItem, _switchItem, _currWeaponType]] call CBA_fnc_execNextFrame;
|
||||
};
|
||||
default {
|
||||
ERROR_1("bad weapon - %1",_this);
|
||||
_exit = true;
|
||||
};
|
||||
};
|
||||
if (_exit) exitWith {}; // Don't notify if the unit isn't the local player or if an invalid weapon was passed
|
||||
|
||||
private _configSwitchItem = configfile >> "CfgWeapons" >> _switchItem;
|
||||
private _switchItemHintText = getText (_configSwitchItem >> "MRT_SwitchItemHintText");
|
||||
private _switchItemHintImage = getText (_configSwitchItem >> "picture");
|
||||
if (_switchItemHintText isNotEqualTo "") then {
|
||||
|
||||
playSound "click";
|
||||
if (_switchItemHintText != "") then {
|
||||
[[_switchItemHintImage, 2.0], [_switchItemHintText], true] call CBA_fnc_notify;
|
||||
};
|
||||
if (_unit == ACE_player) then {
|
||||
playSound "click";
|
||||
};
|
||||
|
@ -44,7 +44,7 @@ params ["_unit"];
|
||||
{},
|
||||
{true},
|
||||
{
|
||||
params ["_unit", "", "_args"];
|
||||
params ["", "_unit", "_args"];
|
||||
_args params ["_attachment", "_name", "_picture", "_weaponItems", "_currentWeapon"];
|
||||
|
||||
private _cfgWeapons = configFile >> "CfgWeapons";
|
||||
@ -110,10 +110,14 @@ params ["_unit"];
|
||||
QGVAR(switch_) + _x,
|
||||
format ["%1: %2", localize "str_sensortype_switch", _modeName],
|
||||
getText (_config >> "picture"),
|
||||
LINKFUNC(switchWeaponAttachment),
|
||||
{
|
||||
params ["", "_unit", "_actionParams"];
|
||||
_actionParams params ["_weapon", "_newAttachment", "_oldAttachment"];
|
||||
[_unit, _weapon, _oldAttachment, _newAttachment] call EFUNC(common,switchAttachmentMode);
|
||||
},
|
||||
{true},
|
||||
{},
|
||||
[_currentWeapon, _x, ""]
|
||||
[_currentWeapon, _x, _attachment]
|
||||
] call EFUNC(interact_menu,createAction),
|
||||
[],
|
||||
_unit
|
||||
|
@ -4,9 +4,12 @@
|
||||
* Switches weapon attachment.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Target <OBJECT>
|
||||
* 1: Player (not used) <OBJECT>
|
||||
* 0: Target (not used) <OBJECT>
|
||||
* 1: Player <OBJECT>
|
||||
* 2: Action params <ARRAY>
|
||||
* - 0: Weapon <STRING>
|
||||
* - 1: New Attachment <STRING>
|
||||
* - 2: Old Attachment <STRING>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
@ -17,11 +20,13 @@
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
params ["_unit", "", "_actionParams"];
|
||||
params ["", "_unit", "_actionParams"];
|
||||
_actionParams params ["_weapon", "_newAttachment", "_oldAttachment"];
|
||||
TRACE_3("Switching attachment",_weapon,_newAttachment,_oldAttachment);
|
||||
|
||||
[_unit, "Gear"] call EFUNC(common,doGesture);
|
||||
private _currWeaponType = [_unit, _weapon] call EFUNC(common,getWeaponIndex);
|
||||
|
||||
if (_currWeaponType == -1) exitWith {};
|
||||
|
||||
private _addNew = _newAttachment isNotEqualTo "";
|
||||
private _removeOld = _oldAttachment isNotEqualTo "";
|
||||
@ -38,22 +43,33 @@ if (_removeOld && {!([_unit, _oldAttachment] call CBA_fnc_canAddItem)}) exitWith
|
||||
};
|
||||
};
|
||||
|
||||
[_unit, "Gear"] call EFUNC(common,doGesture);
|
||||
|
||||
if (_removeOld) then {
|
||||
[{
|
||||
params ["_unit", "_weapon", "_oldAttachment"];
|
||||
switch (_weapon) do {
|
||||
case (primaryWeapon _unit): {_unit removePrimaryWeaponItem _oldAttachment;};
|
||||
case (handgunWeapon _unit): {_unit removeHandgunItem _oldAttachment;};
|
||||
default {_unit removeSecondaryWeaponItem _oldAttachment;};
|
||||
params ["_unit", "_currWeaponType", "_oldAttachment"];
|
||||
|
||||
switch (_currWeaponType) do {
|
||||
case 0: {_unit removePrimaryWeaponItem _oldAttachment};
|
||||
case 1: {_unit removeSecondaryWeaponItem _oldAttachment};
|
||||
case 2: {_unit removeHandgunItem _oldAttachment};
|
||||
default {};
|
||||
};
|
||||
|
||||
_unit addItem _oldAttachment;
|
||||
}, [_unit, _weapon, _oldAttachment], 0.3] call CBA_fnc_waitAndExecute;
|
||||
}, [_unit, _currWeaponType, _oldAttachment], 0.3] call CBA_fnc_waitAndExecute;
|
||||
};
|
||||
|
||||
if (!_addNew) exitWith {};
|
||||
|
||||
[{
|
||||
params ["_unit", "_weapon", "_newAttachment"];
|
||||
|
||||
_unit addWeaponItem [_weapon, _newAttachment];
|
||||
|
||||
if (_unit != ACE_player) exitWith {};
|
||||
|
||||
[[getText (configFile >> "CfgWeapons" >> _newAttachment >> "picture"), 4], true] call CBA_fnc_notify;
|
||||
|
||||
playSound "click";
|
||||
}, [_unit, _weapon, _newAttachment], 1] call CBA_fnc_waitAndExecute;
|
||||
|
Loading…
Reference in New Issue
Block a user