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

Common - Add ace_common_fnc_switchAttachmentMode #10135

Merged
merged 4 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ PREP(stopGesture);
PREP(stringCompare);
PREP(stringToColoredText);
PREP(swayLoop);
PREP(switchAttachmentMode);
PREP(switchPersistentLaser);
PREP(switchToGroupSide);
PREP(throttledPublicVariable);
Expand Down
59 changes: 59 additions & 0 deletions addons/common/functions/fnc_switchAttachmentMode.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "..\script_component.hpp"
/*
* Author: PabstMirror
* Switch attachment from one mode to another - based on CBA_accessory_fnc_switchAttachment
*
* Arguments:
* 0: Unit <OBJECT>
* 1: From <STRING>
* 2: To <STRING>
*
* Return Value:
* None
*
* Example:
* [player, "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 (""): {};
case (primaryWeapon _unit): {
private _currWeaponType = 0;
_unit removePrimaryWeaponItem _currItem;
[{
params ["_unit", "", "_switchItem"];
_unit addPrimaryWeaponItem _switchItem;
["CBA_attachmentSwitched", _this] call CBA_fnc_localEvent;
}, [_unit, _currItem, _switchItem, _currWeaponType]] call CBA_fnc_execNextFrame;
};
case (handgunWeapon _unit): {
private _currWeaponType = 1;
_unit removeHandgunItem _currItem;
[{
params ["_unit", "", "_switchItem"];
_unit addHandgunItem _switchItem;
["CBA_attachmentSwitched", _this] call CBA_fnc_localEvent;
}, [_unit, _currItem, _switchItem, _currWeaponType]] call CBA_fnc_execNextFrame;
};
case (secondaryWeapon _unit): {
private _currWeaponType = 2;
_unit removeSecondaryWeaponItem _currItem;
[{
params ["_unit", "", "_switchItem"];
_unit addSecondaryWeaponItem _switchItem;
["CBA_attachmentSwitched", _this] call CBA_fnc_localEvent;
}, [_unit, _currItem, _switchItem, _currWeaponType]] call CBA_fnc_execNextFrame;
};
};
private _configSwitchItem = configfile >> "CfgWeapons" >> _switchItem;
private _switchItemHintText = getText (_configSwitchItem >> "MRT_SwitchItemHintText");
private _switchItemHintImage = getText (_configSwitchItem >> "picture");
if (_switchItemHintText isNotEqualTo "") then {
[[_switchItemHintImage, 2.0], [_switchItemHintText], true] call CBA_fnc_notify;
};
playSound "click";
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved