Skip to content

Commit

Permalink
Merge pull request #1503 from BrettMayson/extended_loadout
Browse files Browse the repository at this point in the history
Extended Loadout Framework
  • Loading branch information
PabstMirror committed May 17, 2022
2 parents a48dbf3 + db40acd commit 33eef5c
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/loadout/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x\cba\addons\loadout
5 changes: 5 additions & 0 deletions addons/loadout/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
};
};
8 changes: 8 additions & 0 deletions addons/loadout/CfgFunctions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CfgFunctions {
class CBA {
class Loadout {
PATHTO_FNC(getLoadout);
PATHTO_FNC(setLoadout);
};
};
};
3 changes: 3 additions & 0 deletions addons/loadout/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

ADDON = true;
17 changes: 17 additions & 0 deletions addons/loadout/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
name = "Community Base Addons - Loadout Framework";
units[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"cba_common", "cba_events"};
author = "$STR_CBA_Author";
authors[] = {"Brett Mayson"};
url = "$STR_CBA_URL";
VERSION_CONFIG;
};
};

#include "CfgEventHandlers.hpp"
#include "CfgFunctions.hpp"
32 changes: 32 additions & 0 deletions addons/loadout/fnc_getLoadout.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_getLoadout
Description:
Get a unit's extended loadout
Parameters:
_unit - The unit to set the loadout on. <UNIT>
Returns:
Extended Loadout <ARRAY>
Examples:
(begin example)
[player] call CBA_fnc_getLoadout
(end)
Author:
Brett Mayson
---------------------------------------------------------------------------- */

params [
["_unit", objNull, [objNull]]
];

if (_unit isEqualTo objNull) exitWith {[]};

private _loadout = getUnitLoadout _unit;
private _extendedInfo = createHashMap;

["CBA_loadoutGet", [_unit, _loadout, _extendedInfo]] call CBA_fnc_localEvent;

[
_loadout,
_extendedInfo
]
39 changes: 39 additions & 0 deletions addons/loadout/fnc_setLoadout.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_setLoadout
Description:
Set a unit's extended loadout
Parameters:
_unit - The unit to set the loadout on. <UNIT>
_loadout - The extended loadout to set. <ARRAY>
_fullMagazines - Partially emptied magazines will be refilled when the loadout is applied. <BOOL>
Returns:
Nothing
Examples:
(begin example)
[player] call CBA_fnc_setLoadout
(end)
Author:
Brett Mayson
---------------------------------------------------------------------------- */

params [
["_unit", objNull, [objNull]],
["_loadout", [], [[]]],
["_fullMagazines", false, [false]]
];

if (isNull _unit) exitWith {};

// A regular loadout array was passed in
if (count _loadout == 10) exitWith {
_unit setUnitLoadout [_loadout, _fullMagazines];
};

_loadout params ["_loadoutArray", "_extendedInfo"];

_unit setUnitLoadout [_loadoutArray, _fullMagazines];

if (_extendedInfo isEqualType []) then { _extendedInfo = createHashMapFromArray _extendedInfo; };

["CBA_loadoutSet", [_unit, _loadout, _extendedInfo]] call CBA_fnc_localEvent;
12 changes: 12 additions & 0 deletions addons/loadout/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#define COMPONENT loadout
#include "\x\cba\addons\main\script_mod.hpp"

#ifdef DEBUG_ENABLED_LOADOUT
#define DEBUG_MODE_FULL
#endif

#ifdef DEBUG_SETTINGS_LOADOUT
#define DEBUG_SETTINGS DEBUG_SETTINGS_LOADOUT
#endif

#include "\x\cba\addons\main\script_macros.hpp"

0 comments on commit 33eef5c

Please sign in to comment.