Skip to content

Commit

Permalink
Added a item filter system and fixed syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBrostrom committed Apr 30, 2024
1 parent 1ca3d28 commit 2879b77
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 52 deletions.
5 changes: 4 additions & 1 deletion cScripts/CfgEquipmentTags.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class CfgEquipmentTags {
Common[] = {"G_Aviator"};
Common[] = {
"G_Aviator",
"Medikit"
};

CommonBlufor[] = {"G_Aviator"};

Expand Down
2 changes: 0 additions & 2 deletions cScripts/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ class cScripts {
class gear_selectLoadout {};
class gear_getSideConfig {};

class gear_getLoadoutCompany {};

class gear_setupRadios {};

// Save and Load
Expand Down
5 changes: 0 additions & 5 deletions cScripts/cScripts_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ INFO("postInit", "Initializing...");
// Change inventory content of supply crates on mission start.
call EFUNC(init,vehicle);

// item replacement
if (EGVAR(Settings,allowReplaceItem)) then {
call EFUNC(init,aceItemReplace);
};

// staging
call EFUNC(init,staging);

Expand Down
6 changes: 4 additions & 2 deletions cScripts/cScripts_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ EGVAR(Staging,ZoneStatus) = false;
EGVAR(Staging,showAllLoadouts) = false;
GVAR(isPlayer) = hasInterface || {isPlayer player};
GVAR(OneLife) = !isNil{(getArray (missionconfigfile >> "respawnTemplates") select 0) == "ace_spectator"};
EGVAR(DATABASE,DONE) = false;

#include "initSettings.inc.sqf"

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


// Logistical Database
EGVAR(DATABASE,DONE) = false;
GVAR(DATABASE) = call EFUNC(init,logistics);
EGVAR(DATABASE,DONE) = true;

if (EGVAR(Settings,allowReplaceItem)) then {
call EFUNC(init,aceItemReplace);
};

if (EGVAR(Settings,allowCustomTagging)) then {
call EFUNC(init,aceTagging);
Expand Down
22 changes: 17 additions & 5 deletions cScripts/functions/arsenal/fn_arsenal_getWhitelist.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ private _anySideCommonItems = ["Common"] call EFUNC(gear,getTagItems);

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

private _whitelist = _loadoutSpecificItems + _commonSideItems + _companyItems + _companyPlatoonItems + _weaponSystemItems;

private _whitelist = _loadoutSpecificItems + _anySideCommonItems + _commonSideItems + _companyItems + _companyPlatoonItems + _weaponSystemItems;

// Clean the whitelist
private _finalWhitelist = [];
if (!isNil{EGVAR(DATABASE,DONE)}) then {
INFO_2("Arsenal", "Database ready filtering Whitelist for %1 [%2].",player,typeof player);
{
private _items = [_x] call FUNC(getFilteredItem);
_finalWhitelist append _items;
} forEach _whitelist;
} else {
WARNING_2("Arsenal", "Database not read skiping filtering of whitelist for %1 [%2].",player,typeof player);
_finalWhitelist = _whitelist;
};
diag_log str _finalWhitelist;

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

Expand All @@ -114,6 +126,6 @@ diag_log format["_commonSideItems: %1",_commonSideItems isEqualType []];
diag_log format["_companyItems: %1",_companyItems isEqualType []];
diag_log format["_companyPlatoonItems: %1",_companyPlatoonItems isEqualType []];
diag_log format["_weaponSystemItems: %1",_weaponSystemItems isEqualType []];
diag_log format["_whitelist: %1",_whitelist isEqualType []];
diag_log format["_whitelist: %1",_finalWhitelist isEqualType []];

_whitelist
_finalWhitelist
2 changes: 1 addition & 1 deletion cScripts/functions/gear/fn_gear_getTagItems.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

params [["_tag","",[""]]];

if (isClass (missionConfigFile >> "CfgEquipmentTags")) exitWith {
if !(isClass (missionConfigFile >> "CfgEquipmentTags")) exitWith {
SHOW_ERROR("Gear","cfgEquipmentTag config does not exist");
[];
};
Expand Down
4 changes: 3 additions & 1 deletion cScripts/functions/init/fn_init_logistics.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
* Public: No
*/


INFO("Logistics", "Creating logistical database");
EGVAR(DATABASE,DONE) = false;

private _dataArray = [
// // // // // // //
// Starter Crates \\
Expand Down Expand Up @@ -2087,6 +2088,7 @@ private _dataArray = [
];

private _return = createHashMapFromArray _dataArray;
EGVAR(DATABASE,DONE) = true;

if (!(_return isEqualType createHashMap)) exitWith {
SHOW_CHAT_ERROR_1("LogisticsDatabase", "Fatal error creating database (database base type faulty %1)...", typeName _return);
Expand Down
23 changes: 22 additions & 1 deletion cScripts/functions/logistics/fn_addCargo.sqf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define DEBUG_MODE
#include "..\script_component.hpp";
/*
* Author: Whitsel.M
Expand Down Expand Up @@ -25,6 +26,26 @@ params [

if ( count _inventory < 1 ) exitWith {};

private _fn_addFilteredItemDelay = {
params ["_item", "_amount"];
private _return = if (!isNil{EGVAR(DATABASE,DONE)}) then {
INFO_1("addCargo","Database is done adding item: '%1'",_item);
private _items = [_item] call FUNC(getFilteredItem);
{_vehicle addItemCargoGlobal [_x, _amount]} forEach _items;
} else {
WARNING_1("addCargo","Database not ready delaying addition of item: '%1'",_item);
if (_item call FUNC(checkItemValidity)) then {
[{!isNil{EGVAR(DATABASE,DONE) == true}}, {
params ["_vehicle", "_item", "_amount"];
private _items = [_item] call FUNC(getFilteredItem);
{_vehicle addItemCargoGlobal [_x, _amount]} forEach _items;
}, [_vehicle, _item, _amount], 10,{
params ["_vehicle", "_item"];
}] call CBA_fnc_waitUntilAndExecute;
};
};
};

{
if !(_x isEqualTypeArray ["",0]) then {
SHOW_WARNING_1("addCargo","Item not added because %1 does not contain the proper format. Must be [STRING, SCALAR].", _x);
Expand All @@ -33,6 +54,6 @@ if ( count _inventory < 1 ) exitWith {};

_x params [["_item", "", [""]], ["_amount", 0, [0]]];
if (_item call FUNC(checkItemValidity)) then {
_vehicle addItemCargoGlobal [_item, _amount];
[_item, _amount] call _fn_addFilteredItemDelay;
};
} forEach _inventory;
25 changes: 6 additions & 19 deletions cScripts/functions/logistics/fn_getFilteredItem.sqf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define DEBUG_MODE
#include "..\script_component.hpp";
/*
* Author: Whitsel.M
Expand All @@ -9,35 +10,21 @@
* 0: Item <OBJECT>
*
* Return Value:
* item <STRING>
* List of Items <ARRAY>
*
* Example:
* ["ACE_EarPlugs"] call cScripts_fnc_getFilteredItem;
*
* Public: No
*/

params[["_item", "", [""]]];

if (_item isEqualTo "") exitWith {
SHOW_WARN("getFilteredItem","No item provided");
SHOW_WARNING("getFilteredItem","No item provided");
"";
};

private _fn_testItem = {
params["_item","_array"];
_array params ["_oldItem", "_newItem"];
if (_item isEqualTo _oldItem) then {
if (_newItem isEqualType []) exitWith {_oldItem};
_newItem;
};
_item;
};

// FIXME: CHECK ace_common_itemReplacements i hope the format is this: [[oldItem,ReplaceItem]]
{
_x parmas ["_item", "_array"];
[_item, _array] call _fn_testItem;
if (_item isNotEqualTo _array#0) exitWith { _array#1 };
} forEach ace_common_itemReplacements;
private _return = ace_common_itemReplacements getVariable [_item, [_item]];

_item;
_return
19 changes: 6 additions & 13 deletions cScripts/functions/players/fn_player_getOrganization.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Public: No
*/

params [["_showOnly", -1 [-1]]];
params [["_showOnly", -1, [-1]]];

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

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


private _regiment = getText (_config >> "regiment");
_regiment = GETVAR(player,EGVAR(Player,Regiment),_configPlatoon);
_regiment = GETVAR(player,EGVAR(Player,Regiment),_regiment);
_regiment = toLower _regiment;

private _company = getText (_config >> "company");
_company = GETVAR(player,EGVAR(Player,Company),_configPlatoon);
_company = GETVAR(player,EGVAR(Player,Company),_company);
_regiment = toLower _regiment;

private _platoon = getNumber (_config >> "platoon");
_platoon = GETVAR(player,EGVAR(Player,Platoon),_configPlatoon);
_platoon = GETVAR(player,EGVAR(Player,Platoon),_platoon);

private _squad = getNumber (_config >> "squad");
_squad = GETVAR(player,EGVAR(Player,Squad),_configPlatoon);
_squad = GETVAR(player,EGVAR(Player,Squad),_squad);

private _team = getText (_config >> "team");
_team = GETVAR(player,EGVAR(Player,Team),_configPlatoon);
_team = GETVAR(player,EGVAR(Player,Team),_team);
_team = toLower _team;


private _configPlatoon = getNumber (_config >> "platoon");
private _platoon = GETVAR(player,EGVAR(Player,Platoon),_configPlatoon);

private _configCompany = getText (_config >> "company");
private _company = GETVAR(player,EGVAR(Player,Company),_configCompany);
_company = toLower _company;

if (_showOnly isNotEqualTo -1) exitWith {
[_team, _squad, _platoon, _company, _regiment] select _showOnly;
};
Expand Down
3 changes: 1 addition & 2 deletions cScripts/functions/players/fn_player_setOrganization.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ params [

private _team = toLower _team;
SETVAR(player,EGVAR(Player,Team),_team);
private _squad = toLower _squad;
SETVAR(player,EGVAR(Player,Squad),_squad);
SETVAR(player,EGVAR(Player,Platoon),_platoon);
private _company = toLower _company;
SETVAR(player,EGVAR(Player,Company),_company);
private _regiment = toLower _regiment;
SETVAR(player,EGVAR(Player,Regiment),_regiment);

INFO_3("Player", "Player %1 [%2] organizationArray set to %3.",player,typeOf player,[_team, _squad, _platoon, _company, _regiment]);
INFO_7("Player", "Player %1 [%2] organizationArray set to [%3, %4, %5, %6, %7].",player,typeOf player,_team,_squad,_platoon,_company,_regiment);

[_team, _squad, _platoon, _company, _regiment]

0 comments on commit 2879b77

Please sign in to comment.