Skip to content

Commit d072568

Browse files
Added a item filter system and fixed syntax
1 parent 9881cfb commit d072568

11 files changed

Lines changed: 64 additions & 52 deletions

cScripts/CfgEquipmentTags.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
class CfgEquipmentTags {
2-
Common[] = {"G_Aviator"};
2+
Common[] = {
3+
"G_Aviator",
4+
"Medikit"
5+
};
36

47
CommonBlufor[] = {"G_Aviator"};
58

cScripts/CfgFunctions.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ class cScripts {
223223
class gear_selectLoadout {};
224224
class gear_getSideConfig {};
225225

226-
class gear_getLoadoutCompany {};
227-
228226
class gear_setupRadios {};
229227

230228
// Save and Load

cScripts/cScripts_postInit.sqf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ INFO("postInit", "Initializing...");
1010
// Change inventory content of supply crates on mission start.
1111
call EFUNC(init,vehicle);
1212

13-
// item replacement
14-
if (EGVAR(Settings,allowReplaceItem)) then {
15-
call EFUNC(init,aceItemReplace);
16-
};
17-
1813
// staging
1914
call EFUNC(init,staging);
2015

cScripts/cScripts_preInit.sqf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ EGVAR(Staging,ZoneStatus) = false;
2323
EGVAR(Staging,showAllLoadouts) = false;
2424
GVAR(isPlayer) = hasInterface || {isPlayer player};
2525
GVAR(OneLife) = !isNil{(getArray (missionconfigfile >> "respawnTemplates") select 0) == "ace_spectator"};
26+
EGVAR(DATABASE,DONE) = false;
2627

2728
#include "initSettings.inc.sqf"
2829

@@ -38,10 +39,11 @@ INFO("preInit", "Initializing...");
3839

3940

4041
// Logistical Database
41-
EGVAR(DATABASE,DONE) = false;
4242
GVAR(DATABASE) = call EFUNC(init,logistics);
43-
EGVAR(DATABASE,DONE) = true;
4443

44+
if (EGVAR(Settings,allowReplaceItem)) then {
45+
call EFUNC(init,aceItemReplace);
46+
};
4547

4648
if (EGVAR(Settings,allowCustomTagging)) then {
4749
call EFUNC(init,aceTagging);

cScripts/functions/arsenal/fn_arsenal_getWhitelist.sqf

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ private _anySideCommonItems = ["Common"] call EFUNC(gear,getTagItems);
3535

3636
// Side items
3737
private _side = [side group player] call EFUNC(gear,getSideConfig);
38-
LOG_1("DEBUG","Player side %1",_side);
3938
private _commonSideItems = switch (_side) do {
4039
case "CommonBlufor": { ["CommonBlufor"] call EFUNC(gear,getTagItems); };
4140
case "CommonOpfor": { ["CommonOpfor"] call EFUNC(gear,getTagItems); };
@@ -104,8 +103,21 @@ private _weaponSystemItems = [];
104103
} forEach _allEquipmentTags;
105104
diag_log format ["cScripts DEBUG: Weapon System: %1", _weaponSystemItems];
106105

107-
private _whitelist = _loadoutSpecificItems + _commonSideItems + _companyItems + _companyPlatoonItems + _weaponSystemItems;
108-
106+
private _whitelist = _loadoutSpecificItems + _anySideCommonItems + _commonSideItems + _companyItems + _companyPlatoonItems + _weaponSystemItems;
107+
108+
// Clean the whitelist
109+
private _finalWhitelist = [];
110+
if (!isNil{EGVAR(DATABASE,DONE)}) then {
111+
INFO_2("Arsenal", "Database ready filtering Whitelist for %1 [%2].",player,typeof player);
112+
{
113+
private _items = [_x] call FUNC(getFilteredItem);
114+
_finalWhitelist append _items;
115+
} forEach _whitelist;
116+
} else {
117+
WARNING_2("Arsenal", "Database not read skiping filtering of whitelist for %1 [%2].",player,typeof player);
118+
_finalWhitelist = _whitelist;
119+
};
120+
diag_log str _finalWhitelist;
109121

110122
INFO_2("Arsenal", "Whitelist created for %1 [%2].",player,typeof player);
111123

@@ -114,6 +126,6 @@ diag_log format["_commonSideItems: %1",_commonSideItems isEqualType []];
114126
diag_log format["_companyItems: %1",_companyItems isEqualType []];
115127
diag_log format["_companyPlatoonItems: %1",_companyPlatoonItems isEqualType []];
116128
diag_log format["_weaponSystemItems: %1",_weaponSystemItems isEqualType []];
117-
diag_log format["_whitelist: %1",_whitelist isEqualType []];
129+
diag_log format["_whitelist: %1",_finalWhitelist isEqualType []];
118130

119-
_whitelist
131+
_finalWhitelist

cScripts/functions/gear/fn_gear_getTagItems.sqf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
params [["_tag","",[""]]];
2020

21-
if (isClass (missionConfigFile >> "CfgEquipmentTags")) exitWith {
21+
if !(isClass (missionConfigFile >> "CfgEquipmentTags")) exitWith {
2222
SHOW_ERROR("Gear","cfgEquipmentTag config does not exist");
2323
[];
2424
};

cScripts/functions/init/fn_init_logistics.sqf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
* Public: No
1313
*/
1414

15-
1615
INFO("Logistics", "Creating logistical database");
16+
EGVAR(DATABASE,DONE) = false;
17+
1718
private _dataArray = [
1819
// // // // // // //
1920
// Starter Crates \\
@@ -2069,6 +2070,7 @@ private _dataArray = [
20692070
];
20702071

20712072
private _return = createHashMapFromArray _dataArray;
2073+
EGVAR(DATABASE,DONE) = true;
20722074

20732075
if (!(_return isEqualType createHashMap)) exitWith {
20742076
SHOW_CHAT_ERROR_1("LogisticsDatabase", "Fatal error creating database (database base type faulty %1)...", typeName _return);

cScripts/functions/logistics/fn_addCargo.sqf

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#define DEBUG_MODE
12
#include "..\script_component.hpp";
23
/*
34
* Author: Whitsel.M
@@ -25,6 +26,26 @@ params [
2526

2627
if ( count _inventory < 1 ) exitWith {};
2728

29+
private _fn_addFilteredItemDelay = {
30+
params ["_item", "_amount"];
31+
private _return = if (!isNil{EGVAR(DATABASE,DONE)}) then {
32+
INFO_1("addCargo","Database is done adding item: '%1'",_item);
33+
private _items = [_item] call FUNC(getFilteredItem);
34+
{_vehicle addItemCargoGlobal [_x, _amount]} forEach _items;
35+
} else {
36+
WARNING_1("addCargo","Database not ready delaying addition of item: '%1'",_item);
37+
if (_item call FUNC(checkItemValidity)) then {
38+
[{!isNil{EGVAR(DATABASE,DONE) == true}}, {
39+
params ["_vehicle", "_item", "_amount"];
40+
private _items = [_item] call FUNC(getFilteredItem);
41+
{_vehicle addItemCargoGlobal [_x, _amount]} forEach _items;
42+
}, [_vehicle, _item, _amount], 10,{
43+
params ["_vehicle", "_item"];
44+
}] call CBA_fnc_waitUntilAndExecute;
45+
};
46+
};
47+
};
48+
2849
{
2950
if !(_x isEqualTypeArray ["",0]) then {
3051
SHOW_WARNING_1("addCargo","Item not added because %1 does not contain the proper format. Must be [STRING, SCALAR].", _x);
@@ -33,6 +54,6 @@ if ( count _inventory < 1 ) exitWith {};
3354

3455
_x params [["_item", "", [""]], ["_amount", 0, [0]]];
3556
if (_item call FUNC(checkItemValidity)) then {
36-
_vehicle addItemCargoGlobal [_item, _amount];
57+
[_item, _amount] call _fn_addFilteredItemDelay;
3758
};
3859
} forEach _inventory;
Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#define DEBUG_MODE
12
#include "..\script_component.hpp";
23
/*
34
* Author: Whitsel.M
@@ -9,35 +10,21 @@
910
* 0: Item <OBJECT>
1011
*
1112
* Return Value:
12-
* item <STRING>
13+
* List of Items <ARRAY>
1314
*
1415
* Example:
1516
* ["ACE_EarPlugs"] call cScripts_fnc_getFilteredItem;
1617
*
1718
* Public: No
1819
*/
20+
1921
params[["_item", "", [""]]];
2022

2123
if (_item isEqualTo "") exitWith {
22-
SHOW_WARN("getFilteredItem","No item provided");
24+
SHOW_WARNING("getFilteredItem","No item provided");
2325
"";
2426
};
2527

26-
private _fn_testItem = {
27-
params["_item","_array"];
28-
_array params ["_oldItem", "_newItem"];
29-
if (_item isEqualTo _oldItem) then {
30-
if (_newItem isEqualType []) exitWith {_oldItem};
31-
_newItem;
32-
};
33-
_item;
34-
};
35-
36-
// FIXME: CHECK ace_common_itemReplacements i hope the format is this: [[oldItem,ReplaceItem]]
37-
{
38-
_x parmas ["_item", "_array"];
39-
[_item, _array] call _fn_testItem;
40-
if (_item isNotEqualTo _array#0) exitWith { _array#1 };
41-
} forEach ace_common_itemReplacements;
28+
private _return = ace_common_itemReplacements getVariable [_item, [_item]];
4229

43-
_item;
30+
_return

cScripts/functions/players/fn_player_getOrganization.sqf

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Public: No
1818
*/
1919

20-
params [["_showOnly", -1 [-1]]];
20+
params [["_showOnly", -1, [-1]]];
2121

2222
private _emptyOrgArray = ["",0,0,"",""];
2323

@@ -26,31 +26,24 @@ private _config = missionConfigFile >> "CfgLoadouts" >> _loadout;
2626

2727

2828
private _regiment = getText (_config >> "regiment");
29-
_regiment = GETVAR(player,EGVAR(Player,Regiment),_configPlatoon);
29+
_regiment = GETVAR(player,EGVAR(Player,Regiment),_regiment);
3030
_regiment = toLower _regiment;
3131

3232
private _company = getText (_config >> "company");
33-
_company = GETVAR(player,EGVAR(Player,Company),_configPlatoon);
33+
_company = GETVAR(player,EGVAR(Player,Company),_company);
3434
_regiment = toLower _regiment;
3535

3636
private _platoon = getNumber (_config >> "platoon");
37-
_platoon = GETVAR(player,EGVAR(Player,Platoon),_configPlatoon);
37+
_platoon = GETVAR(player,EGVAR(Player,Platoon),_platoon);
3838

3939
private _squad = getNumber (_config >> "squad");
40-
_squad = GETVAR(player,EGVAR(Player,Squad),_configPlatoon);
40+
_squad = GETVAR(player,EGVAR(Player,Squad),_squad);
4141

4242
private _team = getText (_config >> "team");
43-
_team = GETVAR(player,EGVAR(Player,Team),_configPlatoon);
43+
_team = GETVAR(player,EGVAR(Player,Team),_team);
4444
_team = toLower _team;
4545

4646

47-
private _configPlatoon = getNumber (_config >> "platoon");
48-
private _platoon = GETVAR(player,EGVAR(Player,Platoon),_configPlatoon);
49-
50-
private _configCompany = getText (_config >> "company");
51-
private _company = GETVAR(player,EGVAR(Player,Company),_configCompany);
52-
_company = toLower _company;
53-
5447
if (_showOnly isNotEqualTo -1) exitWith {
5548
[_team, _squad, _platoon, _company, _regiment] select _showOnly;
5649
};

0 commit comments

Comments
 (0)