Skip to content

Commit

Permalink
Merge pull request #1294 from CBATeam/switchableAttachments
Browse files Browse the repository at this point in the history
add CBA_fnc_switchableAttachments
  • Loading branch information
commy2 committed Mar 13, 2020
2 parents d58b709 + 19d6f24 commit de9851a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
11 changes: 11 additions & 0 deletions addons/accessory/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));
};
};

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
7 changes: 7 additions & 0 deletions addons/accessory/CfgFunctions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CfgFunctions {
class CBA {
class Inventory {
PATHTO_FNC(switchableAttachments);
};
};
};
13 changes: 2 additions & 11 deletions addons/accessory/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,5 @@ class CfgPatches {
};
};

class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));
};
};

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
#include "CfgEventHandlers.hpp"
#include "CfgFunctions.hpp"
42 changes: 42 additions & 0 deletions addons/accessory/fnc_switchableAttachments.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_switchableAttachments
Description:
Returns all attachments the item can eventually switch to.
Parameters:
0: _item - Attachment classname <STRING>
Returns:
_items - List of switchable items, contains original item. <ARRAY>
Examples:
(begin example)
"acc_pointer_IR" call CBA_fnc_switchableAttachments
(end)
Author:
commy2
---------------------------------------------------------------------------- */

params ["_item"];

private _cfgWeapons = configfile >> "CfgWeapons";
private _config = _cfgWeapons >> _item;

private _forward = [];
while {
_config = _cfgWeapons >> getText (_config >> "MRT_SwitchItemNextClass");
isClass _config && {_forward pushBackUnique configName _config != -1}
} do {};

_config = _cfgWeapons >> _item;
private _backward = [];
while {
_config = _cfgWeapons >> getText (_config >> "MRT_SwitchItemPrevClass");
isClass _config && {_backward pushBackUnique configName _config != -1}
} do {};

_forward = _forward + _backward;
_forward arrayIntersect _forward // return

0 comments on commit de9851a

Please sign in to comment.