From 270d409c305e4027d59fb9d2b99495d93b17fd8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brostr=C3=B6m=2EA=20=7C=20Evul?= Date: Thu, 7 Dec 2023 13:58:44 +0100 Subject: [PATCH] Updated and adjusted the eventhandler setup and fixed arsenal (#1093) * Improved and adjusted the eventhandler setup and arsenal Moved eventhandlers to respective init functions Added new handling for Ace Arsenal and default loadous. Zeus and Debug now have access to all gear as well as all loadouts Improved documentation * Added missing function * Fixed function call * Updated and fixed arsenal * Removed Dewbugging --- cScripts/CfgFunctions.hpp | 13 +++++-- cScripts/cScripts_preInit.sqf | 2 +- .../functions/gear/fn_gear_getLoadoutName.sqf | 3 +- .../functions/init/fn_init_aceArsenal.sqf | 37 +++++++++++++++++++ .../functions/init/fn_init_eventHandlers.sqf | 32 ---------------- cScripts/functions/init/fn_init_staging.sqf | 3 ++ cScripts/functions/init/fn_init_vehicle.sqf | 15 ++++++++ .../players/fn_player_getCompany.sqf | 2 +- .../functions/players/fn_player_isCurator.sqf | 24 ++++++++++++ cScripts/functions/systems/fn_addArsenal.sqf | 8 +++- ...lt.sqf => fn_addDefaultArsenalLoadout.sqf} | 20 +++++++--- .../fn_addDefaultArsenalLoadouts.sqf} | 21 +++++++---- .../functions/systems/fn_allowLoadout.sqf | 8 +--- .../fn_clearDefaultArsenalLoadouts.sqf | 14 +++++++ .../systems/fn_getArsenalWhitelist.sqf | 2 +- 15 files changed, 142 insertions(+), 62 deletions(-) create mode 100644 cScripts/functions/init/fn_init_aceArsenal.sqf create mode 100644 cScripts/functions/players/fn_player_isCurator.sqf rename cScripts/functions/systems/{fn_getUnitArsenalDefault.sqf => fn_addDefaultArsenalLoadout.sqf} (60%) rename cScripts/functions/{init/fn_init_aceArsenalDefault.sqf => systems/fn_addDefaultArsenalLoadouts.sqf} (67%) create mode 100644 cScripts/functions/systems/fn_clearDefaultArsenalLoadouts.sqf diff --git a/cScripts/CfgFunctions.hpp b/cScripts/CfgFunctions.hpp index 7c554530f..cfa38136d 100644 --- a/cScripts/CfgFunctions.hpp +++ b/cScripts/CfgFunctions.hpp @@ -1,7 +1,7 @@ class cScripts { class init { file = "cScripts\functions\init"; - class init_aceArsenalDefault {}; + class init_aceArsenal {}; class init_aceTagging {}; class init_aceItemReplace {}; @@ -64,6 +64,8 @@ class cScripts { class player_setRank {}; class player_getRole {}; + class player_isCurator {}; + class unit_setTeamColor {}; class unit_getName {}; @@ -76,6 +78,7 @@ class cScripts { class setRadioChannel {}; class setActiveRadio {}; + class player_getCompany {}; class player_setCompany {}; // Other Functions @@ -111,6 +114,12 @@ class cScripts { class setupLoadoutCategories {}; class addLoadoutSelection {}; + // Arsenal releated + class getArsenalWhitelist {}; + class addDefaultArsenalLoadout {}; + class addDefaultArsenalLoadouts {}; + class clearDefaultArsenalLoadouts {}; + class checkStagingZone {}; class deleteDroppedObjects {}; @@ -129,8 +138,6 @@ class cScripts { class addReGear {}; class addHeal {}; class addArsenal {}; - class getArsenalWhitelist {}; - class getUnitArsenalDefault {}; class createActionCategory {}; diff --git a/cScripts/cScripts_preInit.sqf b/cScripts/cScripts_preInit.sqf index 2e1ed269e..d04f641f8 100644 --- a/cScripts/cScripts_preInit.sqf +++ b/cScripts/cScripts_preInit.sqf @@ -348,7 +348,7 @@ private _cScriptSettings = "cScripts Mission Settings"; INFO(if (is3DEN) then {"EDEN"} else {"preInit"}, "Initialization of CBA Settings completed..."); // Ace Arsenal -call EFUNC(init,aceArsenalDefault); +call EFUNC(init,aceArsenal); // Load preInit mission settings diff --git a/cScripts/functions/gear/fn_gear_getLoadoutName.sqf b/cScripts/functions/gear/fn_gear_getLoadoutName.sqf index 8bb743bce..82363fafa 100644 --- a/cScripts/functions/gear/fn_gear_getLoadoutName.sqf +++ b/cScripts/functions/gear/fn_gear_getLoadoutName.sqf @@ -17,6 +17,7 @@ params [["_unit", objNull, [objNull]]]; -private _return = GETVAR(_unit,EGVAR(Gear,loadoutClass),typeOf player); + +private _return = GETVAR(_unit,EGVAR(Gear,loadoutClass), typeOf player); _return \ No newline at end of file diff --git a/cScripts/functions/init/fn_init_aceArsenal.sqf b/cScripts/functions/init/fn_init_aceArsenal.sqf new file mode 100644 index 000000000..1d9065886 --- /dev/null +++ b/cScripts/functions/init/fn_init_aceArsenal.sqf @@ -0,0 +1,37 @@ +#include "..\script_component.hpp"; +/* + * Author: CPL.Brostrom.A + * This function initzialise ace arsenal default loadouts in eden and in mission. + * + * Example: + * call cScripts_fnc_init_aceArsenal + * + * Public: No + */ + +if (!EGVAR(patches,usesACEArsenal)) exitWith {}; + +call FUNC(addDefaultArsenalLoadouts); + +if (is3DEN) exitWith {}; + +GVAR(StagingArsenalOpen) = false; + +// Event Handlers +["ace_arsenal_displayClosed", { + if (GVAR(StagingArsenalOpen)) then { + [QEGVAR(EH_StagingArsenal,displayClose)] call CBA_fnc_localEvent; + }; +}] call CBA_fnc_addEventHandler; + +[QEGVAR(EH_StagingArsenal,displayOpen), { + GVAR(StagingArsenalOpen) = true; +}] call CBA_fnc_addEventHandler; + +[QEGVAR(EH_StagingArsenal,displayClosed), { + [player, true] call ace_arsenal_fnc_removeBox; + GVAR(StagingArsenalOpen) = false; + + // Reset default loadouts + call FUNC(addDefaultArsenalLoadouts); +}] call CBA_fnc_addEventHandler; \ No newline at end of file diff --git a/cScripts/functions/init/fn_init_eventHandlers.sqf b/cScripts/functions/init/fn_init_eventHandlers.sqf index b83c33039..889c5f7d3 100644 --- a/cScripts/functions/init/fn_init_eventHandlers.sqf +++ b/cScripts/functions/init/fn_init_eventHandlers.sqf @@ -15,18 +15,6 @@ INFO("InitEventHandlers","Creating Global EventHandlers"); call FUNC(getAttendance); }] call CBA_fnc_addEventHandler; -[QEGVAR(EH_Vehicle,addFunctions), { - params ["_vehicle"]; - INFO_2("EH_InitVehicle_addFunctions", "Applying function to %1 [%2]", _vehicle, typeOf _vehicle); - _vehicle call EFUNC(vehicle,addFunctions); -}] call CBA_fnc_addEventHandler; - -[QEGVAR(EH_Vehicle,addStagingActions), { - params ["_vehicle"]; - INFO_2("EH_InitVehicle_addStagingActions", "Applying function to %1 [%2]", _vehicle, typeOf _vehicle); - _vehicle call EFUNC(vehicle,addStagingActions); -}] call CBA_fnc_addEventHandler; - // Player Events if (GVAR(isPlayer)) then { @@ -40,26 +28,6 @@ if (GVAR(isPlayer)) then { //["zen_common_createZeus", { // _this params ["_zeus"]; //}] call CBA_fnc_addEventHandler; - - // CavArsenal - ["ace_arsenal_displayClosed", { - if (GVAR(StagingArsenalOpen)) then { - [QEGVAR(EH_StagingArsenal,displayClose)] call CBA_fnc_localEvent; - }; - }] call CBA_fnc_addEventHandler; - - [QEGVAR(EH_StagingArsenal,displayOpen), { - GVAR(StagingArsenalOpen) = true; - }] call CBA_fnc_addEventHandler; - - [QEGVAR(EH_StagingArsenal,displayClosed), { - [player, true] call ace_arsenal_fnc_removeBox; - GVAR(StagingArsenalOpen) = false; - - // Reset default loadouts - call EFUNC(init,aceArsenalDefault); - - }] call CBA_fnc_addEventHandler; }; diff --git a/cScripts/functions/init/fn_init_staging.sqf b/cScripts/functions/init/fn_init_staging.sqf index 73e5b9a1f..aeca02234 100644 --- a/cScripts/functions/init/fn_init_staging.sqf +++ b/cScripts/functions/init/fn_init_staging.sqf @@ -37,8 +37,11 @@ private _stagingZoneMarkers = []; [_zone, _size] call FUNC(addStagingZone); } forEach _stagingZoneMarkers; + +// Player specific actions if !(GVAR(isPlayer)) exitWith {}; +// Interaction system private _condition = { call FUNC(checkStagingZone) }; private _stagingCat = [QEGVAR(Actions,StagingCategory), "Staging Zone", "cScripts\Data\Icon\icon_00.paa", {true}, _condition] call ace_interact_menu_fnc_createAction; [player, 1, ["ACE_SelfActions"], _stagingCat] call ace_interact_menu_fnc_addActionToObject; diff --git a/cScripts/functions/init/fn_init_vehicle.sqf b/cScripts/functions/init/fn_init_vehicle.sqf index a2b40b234..bcfdfffba 100644 --- a/cScripts/functions/init/fn_init_vehicle.sqf +++ b/cScripts/functions/init/fn_init_vehicle.sqf @@ -16,6 +16,21 @@ INFO("InitVehicle","Applying Event Handers (init) to vehicles for function expan if !(EGVAR(Settings,enableVehicleSystem)) exitWith {}; +// Event Handlers +[QEGVAR(EH_Vehicle,addFunctions), { + params ["_vehicle"]; + INFO_2("EH_InitVehicle_addFunctions", "Applying function to %1 [%2]", _vehicle, typeOf _vehicle); + _vehicle call EFUNC(vehicle,addFunctions); +}] call CBA_fnc_addEventHandler; + +[QEGVAR(EH_Vehicle,addStagingActions), { + params ["_vehicle"]; + INFO_2("EH_InitVehicle_addStagingActions", "Applying function to %1 [%2]", _vehicle, typeOf _vehicle); + _vehicle call EFUNC(vehicle,addStagingActions); +}] call CBA_fnc_addEventHandler; + + +// Vehicle init ["AllVehicles", "init", { params ["_vehicle"]; INFO_2("VehicleInit", "Applying Init to %1 [%2]...", _vehicle, typeOf _vehicle); diff --git a/cScripts/functions/players/fn_player_getCompany.sqf b/cScripts/functions/players/fn_player_getCompany.sqf index 2eb1a84f5..b0c350ce7 100644 --- a/cScripts/functions/players/fn_player_getCompany.sqf +++ b/cScripts/functions/players/fn_player_getCompany.sqf @@ -15,7 +15,7 @@ * Public: No */ -private _company = GETVAR(player,EGVAR(Player,Company),""); +private _company = GETVAR(player,EGVAR(Player,Company), ""); _company = toLower _company; _company \ No newline at end of file diff --git a/cScripts/functions/players/fn_player_isCurator.sqf b/cScripts/functions/players/fn_player_isCurator.sqf new file mode 100644 index 000000000..44cd82d48 --- /dev/null +++ b/cScripts/functions/players/fn_player_isCurator.sqf @@ -0,0 +1,24 @@ +#include "..\script_component.hpp"; +/* + * Author: SGT.Brostrom.A + * This function return true if a player is curator + * + * Arguments: + * None + * + * Return Value: + * true/False + * + * Example: + * call cScripts_fnc_unit_setInsignia + * + */ + +private _curator = player getVariable [QEGVAR(Player,Unit), ""]; +_curator = toLower _curator; +if (_curator == "s3") exitWith {true}; +if (_curator == "zeus") exitWith {true}; +if (_curator == "curator") exitWith {true}; +if (_curator == "debug") exitWith {true}; + +false \ No newline at end of file diff --git a/cScripts/functions/systems/fn_addArsenal.sqf b/cScripts/functions/systems/fn_addArsenal.sqf index bad977000..1882869da 100644 --- a/cScripts/functions/systems/fn_addArsenal.sqf +++ b/cScripts/functions/systems/fn_addArsenal.sqf @@ -19,10 +19,13 @@ private _icon = "cScripts\Data\Icon\icon_arsenal_ca.paa"; private _arsenalStatement = { INFO_2("Staging Arsenal", "Creating staging arsenal for %1 (%2)", player, typeOf player); - ace_arsenal_defaultLoadoutsList = []; - call FUNC(getUnitArsenalDefault); + call FUNC(clearDefaultArsenalLoadouts); + waitUntil { count ace_arsenal_defaultLoadoutsList == 0 }; + call FUNC(addDefaultArsenalLoadout); + waitUntil { count ace_arsenal_defaultLoadoutsList != 0 }; private _items = call FUNC(getArsenalWhitelist); + INFO_3("Staging Arsenal", "Whitleist containing %1 items added to %2 (%3)", count _items, player, typeOf player); if (count _items == 0) exitWith { [ [], @@ -32,6 +35,7 @@ private _arsenalStatement = { ] call CBA_fnc_notify; }; + [player, _items] call ace_arsenal_fnc_initBox; [{ diff --git a/cScripts/functions/systems/fn_getUnitArsenalDefault.sqf b/cScripts/functions/systems/fn_addDefaultArsenalLoadout.sqf similarity index 60% rename from cScripts/functions/systems/fn_getUnitArsenalDefault.sqf rename to cScripts/functions/systems/fn_addDefaultArsenalLoadout.sqf index 2ccdcb0ae..c19d66598 100644 --- a/cScripts/functions/systems/fn_getUnitArsenalDefault.sqf +++ b/cScripts/functions/systems/fn_addDefaultArsenalLoadout.sqf @@ -1,24 +1,29 @@ #include "..\script_component.hpp"; /* - * Author: CPL.Brostrom.A - * This function creates a defualt loadout based on your current selected loadout class + * Author: SGT.Brostrom.A + * This function creates a default loadouts and adds it to the arsenal based on the config loadout name. + * The loadout is added to the players arsenal. * * Arguments: * None * * Return: - * Nothing + * True on success * * Example: - * [] call cScripts_fnc_getUnitArsenalDefault; + * call cScripts_fnc_addDefaultArsenalLoadout */ +if (!EGVAR(patches,usesACEArsenal)) exitWith {}; + +INFO("Default Arsenal", "Setting up default arsenal loadout for unit..."); + private _empty = [[],[],[],[],[],[],"","",[],["","","","","",""]]; ["", _empty, false] call ace_arsenal_fnc_addDefaultLoadout; private _loadout = [player] call EFUNC(gear,getLoadoutName); if !(isClass (missionConfigFile >> "CfgLoadouts" >> _loadout)) exitWith { - SHOW_CHAT_WARNING_1("ArsenalDefault", "Loadout '%1' does not exist inside of mission config. No default arsenal will be created.", _loadout); + SHOW_CHAT_WARNING_1("Default Arsenal", "Loadout '%1' does not exist inside of mission config. No default arsenal will be created.", _loadout); }; private _name = getText (missionConfigFile >> "CfgLoadouts" >> _loadout >> "displayName"); @@ -30,4 +35,7 @@ _name = format["[7CAV] %1 %2 (Default)", _company, _name]; private _loadout = parseSimpleArray getText (missionConfigFile >> "CfgLoadouts" >> _loadout >> "loadout"); if (EGVAR(patches,usesACRE)) then { _loadout = [_loadout] call acre_api_fnc_filterUnitLoadout }; -[_name, _loadout, false] call ace_arsenal_fnc_addDefaultLoadout; \ No newline at end of file +[_name, _loadout, false] call ace_arsenal_fnc_addDefaultLoadout; +INFO_1("Default Arsenal", "Loadout name %1 created for player arsenal", _name); + +true \ No newline at end of file diff --git a/cScripts/functions/init/fn_init_aceArsenalDefault.sqf b/cScripts/functions/systems/fn_addDefaultArsenalLoadouts.sqf similarity index 67% rename from cScripts/functions/init/fn_init_aceArsenalDefault.sqf rename to cScripts/functions/systems/fn_addDefaultArsenalLoadouts.sqf index 9cb6cd74c..49a67f8bd 100644 --- a/cScripts/functions/init/fn_init_aceArsenalDefault.sqf +++ b/cScripts/functions/systems/fn_addDefaultArsenalLoadouts.sqf @@ -1,18 +1,23 @@ #include "..\script_component.hpp"; /* - * Author: CPL.Brostrom.A - * This function initzialise ace arsenal default loadouts in eden and in mission. + * Author: SGT.Brostrom.A + * This adds default arsenal loadouts based on cfgLoadouts gear system loadouts. + * + * Arguments: + * None + * + * Return: + * True on success * * Example: - * call cScripts_fnc_init_aceArsenalDefault + * call cScripts_fnc_addDefaultArsenalLoadouts * * Public: No */ -if (isServer) exitWith {}; if (!EGVAR(patches,usesACEArsenal)) exitWith {}; -INFO(if (is3DEN) then {"EDENArsenal"} else {"Arsenal"}, "Setting up Default ACE Arsenal loadouts."); +INFO(if (is3DEN) then {"EDEN Default Arsenal"} else {"Default Arsenal"}, "Setting up default arsenal loadouts..."); private _empty = [[],[],[],[],[],[],"","",[],["","","","","",""]]; ["", _empty] call ace_arsenal_fnc_addDefaultLoadout; @@ -29,14 +34,14 @@ private _classnameList = configProperties [missionconfigfile >> "CfgLoadouts", " if (EGVAR(patches,usesACRE)) then { _loadout = [_loadout] call acre_api_fnc_filterUnitLoadout }; private _name = format["[%1] %2 - %3", EGVAR(Settings,primaryClanTag), _company, _displayName]; - INFO_1(if (is3DEN) then {"EDENArsenal"} else {"Arsenal"}, "Setting up default arsenal loadout '%1'.", _displayName); + INFO_1(if (is3DEN) then {"EDEN Default Arsenal"} else {"Default Arsenal"}, "Setting up default arsenal loadout '%1'.", _displayName); // Error if if (_displayName == "") exitWith { private _scope = getNumber (missionConfigFile >> 'CfgLoadouts' >> _class >> "scope"); - SHOW_ERROR_2(if (is3DEN) then {"EDENArsenal"} else {"Arsenal"}, "No displayName for %1 with scope %2.", _class, _scope); + SHOW_ERROR_2(if (is3DEN) then {"EDEN Default Arsenal"} else {"Default Arsenal"}, "No displayName for %1 with scope %2.", _class, _scope); }; [_name, _loadout] call ace_arsenal_fnc_addDefaultLoadout; } forEach _classnameList; -INFO(if (is3DEN) then { "EDENArsenal"} else {"Arsenal"}, "Default ACE Arsenal loadouts setup completed."); \ No newline at end of file +true \ No newline at end of file diff --git a/cScripts/functions/systems/fn_allowLoadout.sqf b/cScripts/functions/systems/fn_allowLoadout.sqf index 6220f0cd1..b75f3445f 100644 --- a/cScripts/functions/systems/fn_allowLoadout.sqf +++ b/cScripts/functions/systems/fn_allowLoadout.sqf @@ -29,13 +29,7 @@ if (EGVAR(Staging,showAllLoadouts)) exitWith {true}; // Check if player is Zeus or Debug -private _curator = player getVariable [QEGVAR(Player,Unit), ""]; -_curator = toLower _curator; -if (_curator == "s3") exitWith {true}; -if (_curator == "zeus") exitWith {true}; -if (_curator == "curator") exitWith {true}; -if (_curator == "debug") exitWith {true}; - +if (call EFUNC(player,isCurator)) exitWith {true}; // Check if does not have any company private _playerCompany = call EFUNC(player,getCompany); diff --git a/cScripts/functions/systems/fn_clearDefaultArsenalLoadouts.sqf b/cScripts/functions/systems/fn_clearDefaultArsenalLoadouts.sqf new file mode 100644 index 000000000..aa9c2a12c --- /dev/null +++ b/cScripts/functions/systems/fn_clearDefaultArsenalLoadouts.sqf @@ -0,0 +1,14 @@ +#include "..\script_component.hpp"; +/* + * Author: SGT.Brostrom.A + * This function remove all ace arsenal default loadouts. + * + * Example: + * call cScripts_fnc_removeDefaultArsenalLoadouts + * + * Public: No + */ + +if (!EGVAR(patches,usesACEArsenal)) exitWith {}; + +ace_arsenal_defaultLoadoutsList = []; diff --git a/cScripts/functions/systems/fn_getArsenalWhitelist.sqf b/cScripts/functions/systems/fn_getArsenalWhitelist.sqf index d065a4fa9..69df823dd 100644 --- a/cScripts/functions/systems/fn_getArsenalWhitelist.sqf +++ b/cScripts/functions/systems/fn_getArsenalWhitelist.sqf @@ -10,7 +10,7 @@ * ARRAY of items * * Example: - * [] call cScripts_fnc_getArsenalWhitelist; + * call cScripts_fnc_getArsenalWhitelist; */ private _classname = [player] call EFUNC(gear,getLoadoutName);