From 79bd885d607ba9b8e82a947f80f3bea920abb3c0 Mon Sep 17 00:00:00 2001 From: AndreasBrostrom Date: Thu, 4 Apr 2024 18:42:59 +0200 Subject: [PATCH 1/2] Added alternative function setCargo that replace cargo and addCargo that append to the cargo container. --- cScripts/CfgFunctions.hpp | 1 + cScripts/functions/logistics/fn_addCargo.sqf | 7 +-- .../logistics/fn_createCargoCrate.sqf | 2 +- .../logistics/fn_doFieldHospital.sqf | 2 +- .../logistics/fn_doStarterCrateSupplies.sqf | 2 +- .../functions/logistics/fn_doSupplyCrate.sqf | 2 +- cScripts/functions/logistics/fn_setCargo.sqf | 45 ++++++++++++++ .../vehicle/fn_vehicle_addInventory.sqf | 60 +++++++++---------- 8 files changed, 81 insertions(+), 40 deletions(-) create mode 100644 cScripts/functions/logistics/fn_setCargo.sqf diff --git a/cScripts/CfgFunctions.hpp b/cScripts/CfgFunctions.hpp index 75b0e02aa..2095c11a0 100644 --- a/cScripts/CfgFunctions.hpp +++ b/cScripts/CfgFunctions.hpp @@ -39,6 +39,7 @@ class cScripts { class logistics { file = "cScripts\functions\logistics"; class addCargo {}; + class setCargo {}; class setCargoAttributes {}; class checkItemValidity {}; class createCargoCrate {}; diff --git a/cScripts/functions/logistics/fn_addCargo.sqf b/cScripts/functions/logistics/fn_addCargo.sqf index 6280913ec..249a94f0a 100644 --- a/cScripts/functions/logistics/fn_addCargo.sqf +++ b/cScripts/functions/logistics/fn_addCargo.sqf @@ -2,7 +2,7 @@ /* * Author: Whitsel.M * This function add given supplies to a container. - * If nothing in the array is defined the container will be empty. + * If nothing in the array is defined the container will not add anything. * * Arguments: * 0: Vehicle or Crate @@ -25,11 +25,6 @@ params [ ["_crateName", "", [""]] ]; -clearWeaponCargoGlobal _vehicle; -clearMagazineCargoGlobal _vehicle; -clearItemCargoGlobal _vehicle; -clearBackpackCargoGlobal _vehicle; - if ( count _inventory < 1 ) exitWith {}; { diff --git a/cScripts/functions/logistics/fn_createCargoCrate.sqf b/cScripts/functions/logistics/fn_createCargoCrate.sqf index 9e784c21e..56f6b59a8 100644 --- a/cScripts/functions/logistics/fn_createCargoCrate.sqf +++ b/cScripts/functions/logistics/fn_createCargoCrate.sqf @@ -51,7 +51,7 @@ if (!isNil{_resize}) then { if (_hasCargo) then { if (_inventory isEqualTo true) then { _inventory = [] }; - [_crate, _inventory] call FUNC(addCargo); + [_crate, _inventory] call FUNC(setCargo); }; if (_isInCargo) then { diff --git a/cScripts/functions/logistics/fn_doFieldHospital.sqf b/cScripts/functions/logistics/fn_doFieldHospital.sqf index 05a0efcd3..3ac388b7e 100644 --- a/cScripts/functions/logistics/fn_doFieldHospital.sqf +++ b/cScripts/functions/logistics/fn_doFieldHospital.sqf @@ -31,7 +31,7 @@ if (_isFacility) then { // If isServer add medical equipment if (isServer) then { private _crateContent = ["atlas"] call FUNC(getMedicalCrate); - [_crate, _crateContent] call FUNC(addCargo); + [_crate, _crateContent] call FUNC(setCargo); }; // Change ace logistics size of crate diff --git a/cScripts/functions/logistics/fn_doStarterCrateSupplies.sqf b/cScripts/functions/logistics/fn_doStarterCrateSupplies.sqf index f4d82f2ad..6afaa99ef 100644 --- a/cScripts/functions/logistics/fn_doStarterCrateSupplies.sqf +++ b/cScripts/functions/logistics/fn_doStarterCrateSupplies.sqf @@ -68,6 +68,6 @@ private _container = switch (_companySelector) do { default {[]}; }; -[_crate, _container] call FUNC(addCargo); +[_crate, _container] call FUNC(setCargo); true \ No newline at end of file diff --git a/cScripts/functions/logistics/fn_doSupplyCrate.sqf b/cScripts/functions/logistics/fn_doSupplyCrate.sqf index 04ae8aee1..a73fc6491 100644 --- a/cScripts/functions/logistics/fn_doSupplyCrate.sqf +++ b/cScripts/functions/logistics/fn_doSupplyCrate.sqf @@ -45,7 +45,7 @@ if (isServer) then { [{!isNil{EGVAR(DATABASE,DONE)} && EGVAR(DATABASE,DONE);}, { _this params ["_crate","_crateType"]; private _container = GET_CONTAINER(_crateType); - [_crate, _container] call FUNC(addCargo); + [_crate, _container] call FUNC(setCargo); }, [_crate, _crateType]] call CBA_fnc_waitUntilAndExecute; }; diff --git a/cScripts/functions/logistics/fn_setCargo.sqf b/cScripts/functions/logistics/fn_setCargo.sqf new file mode 100644 index 000000000..55b421792 --- /dev/null +++ b/cScripts/functions/logistics/fn_setCargo.sqf @@ -0,0 +1,45 @@ +#include "..\script_component.hpp"; +/* + * Author: Whitsel.M + * This function sets given supplies to a container. + * If nothing in the array is defined the container will be empty. + * + * Arguments: + * 0: Vehicle or Crate + * 1: Inventory + * + * Return Value: + * Nothing + * + * Example: + * [MyCrate, [["ACE_EarPlugs", 60]]] call cScripts_fnc_setCargo; + * [MyTruck, [["ACE_personalAidKit", 8], ["ACE_tourniquet", 10]]] call cScripts_fnc_setCargo; + * [MyTruck, [["ACE_personalAidKit", 8], ["ACE_tourniquet", 10]], "myCrate", false] call cScripts_fnc_setCargo; + * + * Public: Yes + */ + +params [ + ["_vehicle", objNull, [objNull]], + ["_inventory", [], [[]]], + ["_crateName", "", [""]] +]; + +clearWeaponCargoGlobal _vehicle; +clearMagazineCargoGlobal _vehicle; +clearItemCargoGlobal _vehicle; +clearBackpackCargoGlobal _vehicle; + +if ( count _inventory < 1 ) exitWith {}; + +{ + 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); + continue; + }; + + _x params [["_item", "", [""]], ["_amount", 0, [0]]]; + if (_item call FUNC(checkItemValidity)) then { + _vehicle addItemCargoGlobal [_item, _amount]; + }; +} forEach _inventory; \ No newline at end of file diff --git a/cScripts/functions/vehicle/fn_vehicle_addInventory.sqf b/cScripts/functions/vehicle/fn_vehicle_addInventory.sqf index 446858f7a..a713663ad 100644 --- a/cScripts/functions/vehicle/fn_vehicle_addInventory.sqf +++ b/cScripts/functions/vehicle/fn_vehicle_addInventory.sqf @@ -37,7 +37,7 @@ _vehicle setVariable ["ace_cargo_noRename", true, true]; _vehicle setVariable [QEGVAR(VehicleFunc,Inventory), true, true]; -if (_vehicleType == "EMPTY") exitWith { [_vehicle, []] call FUNC(addCargo); }; +if (_vehicleType == "EMPTY") exitWith { [_vehicle, []] call FUNC(setCargo); }; // Ground Vehicles @@ -57,7 +57,7 @@ if (_vehicle iskindOf "I_APC_Wheeled_03_cannon_F") then { // Vehicle Inventory [_vehicle, GET_CONTAINER("vehicle_strykerDragoon_V4") - ] call FUNC(addCargo); + ] call FUNC(setCargo); // Supply Crate ["Box_NATO_Equip_F", @@ -99,7 +99,7 @@ if (_vehicle iskindOf "I_APC_Wheeled_03_cannon_F") then { // Vehicle Inventory [_vehicle, GET_CONTAINER("vehicle_strykerDragoon") - ] call FUNC(addCargo); + ] call FUNC(setCargo); // Supply Crate ["Box_NATO_Equip_F", @@ -126,7 +126,7 @@ if (_vehicle iskindOf "I_APC_Wheeled_03_cannon_F") then { case "MED": { [_vehicle, GET_CONTAINER("vehicle_medicalAtlas") - ] call FUNC(addCargo); + ] call FUNC(setCargo); ["ace_medicalSupplyCrate", GET_CONTAINER("crate_medicalAtlas"), @@ -139,7 +139,7 @@ if (_vehicle iskindOf "I_APC_Wheeled_03_cannon_F") then { // Vehicle Inventory [_vehicle, GET_CONTAINER("vehicle_strykerDragoon") - ] call FUNC(addCargo); + ] call FUNC(setCargo); // Supply Crate ["Box_NATO_Equip_F", @@ -174,7 +174,7 @@ if (_vehicle iskindOf "MRAP_01_base_F") then { case "MED": { [_vehicle, GET_CONTAINER("vehicle_medicalAtlas") - ] call FUNC(addCargo); + ] call FUNC(setCargo); ["ace_medicalSupplyCrate", GET_CONTAINER("crate_medicalAtlas"), @@ -185,13 +185,13 @@ if (_vehicle iskindOf "MRAP_01_base_F") then { case "rhsusf_m1165a1_gmv_m2_m240_socom_w": { [_vehicle, GET_CONTAINER("vehicle_HMMWV") - ] call FUNC(addCargo); + ] call FUNC(setCargo); }; case "rhsusf_m1165a1_gmv_mk19_m240_socom_d"; case "rhsusf_m1165a1_gmv_mk19_m240_socom_w": { [_vehicle, GET_CONTAINER("vehicle_HMMWV_Weapons") - ] call FUNC(addCargo); + ] call FUNC(setCargo); }; case "rhsusf_M1239_socom_d"; case "rhsusf_M1239_M2_socom_d"; @@ -211,7 +211,7 @@ if (_vehicle iskindOf "MRAP_01_base_F") then { // Vehicle Inventory [_vehicle, GET_CONTAINER(vehicle_strykerDragoon) - ] call FUNC(addCargo); + ] call FUNC(setCargo); // Supply Crate ["Box_NATO_Equip_F", @@ -243,7 +243,7 @@ if (_vehicle iskindOf "MRAP_01_base_F") then { // Vehicle Inventory [_vehicle, GET_CONTAINER(vehicle_strykerDragoon) - ] call FUNC(addCargo); + ] call FUNC(setCargo); // Supply Crate ["Box_NATO_Equip_F", @@ -254,13 +254,13 @@ if (_vehicle iskindOf "MRAP_01_base_F") then { default { [_vehicle, GET_CONTAINER("vehicle_HMMWV") - ] call FUNC(addCargo); + ] call FUNC(setCargo); }; }; }; if (_vehicle iskindOf "rhsusf_fmtv_base") then { - [_vehicle, []] call FUNC(addCargo); + [_vehicle, []] call FUNC(setCargo); }; if (_vehicle iskindOf "Truck_01_base_F") then { @@ -270,7 +270,7 @@ if (_vehicle iskindOf "Truck_01_base_F") then { case "MED": { [_vehicle, GET_CONTAINER("vehicle_medicalAtlas") - ] call FUNC(addCargo); + ] call FUNC(setCargo); ["ace_medicalSupplyCrate", GET_CONTAINER("crate_medicalAtlas"), @@ -278,7 +278,7 @@ if (_vehicle iskindOf "Truck_01_base_F") then { ] call FUNC(createCargoCrate); }; default { - [_vehicle, []] call FUNC(addCargo); + [_vehicle, []] call FUNC(setCargo); }; }; ["ACE_Wheel", _vehicle, true] call ace_cargo_fnc_loadItem; @@ -296,7 +296,7 @@ if (_vehicle iskindOf "rhsusf_stryker_base") then { case "MED": { [_vehicle, GET_CONTAINER("vehicle_medicalAtlas") - ] call FUNC(addCargo); + ] call FUNC(setCargo); ["ace_medicalSupplyCrate", GET_CONTAINER("crate_medicalAtlas"), @@ -306,7 +306,7 @@ if (_vehicle iskindOf "rhsusf_stryker_base") then { default { [_vehicle, GET_CONTAINER("vehicle_strykerDragoon") - ] call FUNC(addCargo); + ] call FUNC(setCargo); }; }; ["FlexibleTank_01_forest_F", false, _vehicle, 1] call FUNC(createCargoCrate); @@ -317,7 +317,7 @@ if (_vehicle iskindOf "RHS_M2A2_Base") then { [_vehicle, GET_CONTAINER("vehicle_bradley") - ] call FUNC(addCargo); + ] call FUNC(setCargo); ["ACE_Track", _vehicle, true] call ace_cargo_fnc_loadItem; }; @@ -328,29 +328,29 @@ if (_vehicle iskindOf "rhsusf_m1a1tank_base") then { [_vehicle, GET_CONTAINER("vehicle_bradley") - ] call FUNC(addCargo); + ] call FUNC(setCargo); }; if (_vehicle iskindOf "RHS_MELB_base") then { - [_vehicle, []] call FUNC(addCargo); + [_vehicle, []] call FUNC(setCargo); }; // Deployable if (_vehicle iskindOf "rhs_m2staticmg_base") then { - [_vehicle, []] call FUNC(addCargo); + [_vehicle, []] call FUNC(setCargo); }; if (_vehicle iskindOf "RHS_MK19_TriPod_base") then { - [_vehicle, []] call FUNC(addCargo); + [_vehicle, []] call FUNC(setCargo); }; if (_vehicle iskindOf "RHS_TOW_TriPod_base") then { - [_vehicle, []] call FUNC(addCargo); + [_vehicle, []] call FUNC(setCargo); }; if (_vehicle iskindOf "NDS_M224_mortar_base") then { - [_vehicle, []] call FUNC(addCargo); + [_vehicle, []] call FUNC(setCargo); }; @@ -364,7 +364,7 @@ if (_vehicle iskindOf "Heli_Transport_01_base_F") then { case "MED": { [_vehicle, GET_CONTAINER("vehicle_medicalAtlas") - ] call FUNC(addCargo); + ] call FUNC(setCargo); ["ace_medicalSupplyCrate", GET_CONTAINER("crate_medicalAtlas"), @@ -374,7 +374,7 @@ if (_vehicle iskindOf "Heli_Transport_01_base_F") then { default { [_vehicle, GET_CONTAINER("vehicle_heliTransport") - ] call FUNC(addCargo); + ] call FUNC(setCargo); }; }; }; @@ -382,28 +382,28 @@ if (_vehicle iskindOf "Heli_Transport_01_base_F") then { if (_vehicle iskindOf "Heli_Transport_02_base_F") then { [_vehicle, GET_CONTAINER("vehicle_heliTransport") - ] call FUNC(addCargo); + ] call FUNC(setCargo); }; if (_vehicle iskindOf "TF373_SOAR_MH47G_Base") then { [_vehicle, GET_CONTAINER("vehicle_heliTransport") - ] call FUNC(addCargo); + ] call FUNC(setCargo); }; if (_vehicle iskindOf "vtx_MH60M") then { [_vehicle, GET_CONTAINER("vehicle_heliTransport") - ] call FUNC(addCargo); + ] call FUNC(setCargo); }; if (_vehicle iskindOf "RHS_AH64_base") then { - [_vehicle, []] call FUNC(addCargo); + [_vehicle, []] call FUNC(setCargo); }; // Fixed Wing if (_vehicle iskindOf "RHS_C130J_Base") then { [_vehicle, 45, -1, false, false] call FUNC(setCargoAttributes); - [_vehicle, []] call FUNC(addCargo); + [_vehicle, []] call FUNC(setCargo); }; From b9ceeece7b4ab38ef8fe9a614a9a65b8c4cdf199 Mon Sep 17 00:00:00 2001 From: AndreasBrostrom Date: Thu, 4 Apr 2024 19:06:40 +0200 Subject: [PATCH 2/2] Removed code duplication --- cScripts/functions/logistics/fn_addCargo.sqf | 4 +--- cScripts/functions/logistics/fn_setCargo.sqf | 18 ++---------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/cScripts/functions/logistics/fn_addCargo.sqf b/cScripts/functions/logistics/fn_addCargo.sqf index 249a94f0a..6bfac3c91 100644 --- a/cScripts/functions/logistics/fn_addCargo.sqf +++ b/cScripts/functions/logistics/fn_addCargo.sqf @@ -14,15 +14,13 @@ * Example: * [MyCrate, [["ACE_EarPlugs", 60]]] call cScripts_fnc_addCargo; * [MyTruck, [["ACE_personalAidKit", 8], ["ACE_tourniquet", 10]]] call cScripts_fnc_addCargo; - * [MyTruck, [["ACE_personalAidKit", 8], ["ACE_tourniquet", 10]], "myCrate", false] call cScripts_fnc_addCargo; * * Public: Yes */ params [ ["_vehicle", objNull, [objNull]], - ["_inventory", [], [[]]], - ["_crateName", "", [""]] + ["_inventory", [], [[]]] ]; if ( count _inventory < 1 ) exitWith {}; diff --git a/cScripts/functions/logistics/fn_setCargo.sqf b/cScripts/functions/logistics/fn_setCargo.sqf index 55b421792..0504528d6 100644 --- a/cScripts/functions/logistics/fn_setCargo.sqf +++ b/cScripts/functions/logistics/fn_setCargo.sqf @@ -14,15 +14,13 @@ * Example: * [MyCrate, [["ACE_EarPlugs", 60]]] call cScripts_fnc_setCargo; * [MyTruck, [["ACE_personalAidKit", 8], ["ACE_tourniquet", 10]]] call cScripts_fnc_setCargo; - * [MyTruck, [["ACE_personalAidKit", 8], ["ACE_tourniquet", 10]], "myCrate", false] call cScripts_fnc_setCargo; * * Public: Yes */ params [ ["_vehicle", objNull, [objNull]], - ["_inventory", [], [[]]], - ["_crateName", "", [""]] + ["_inventory", [], [[]]] ]; clearWeaponCargoGlobal _vehicle; @@ -30,16 +28,4 @@ clearMagazineCargoGlobal _vehicle; clearItemCargoGlobal _vehicle; clearBackpackCargoGlobal _vehicle; -if ( count _inventory < 1 ) exitWith {}; - -{ - 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); - continue; - }; - - _x params [["_item", "", [""]], ["_amount", 0, [0]]]; - if (_item call FUNC(checkItemValidity)) then { - _vehicle addItemCargoGlobal [_item, _amount]; - }; -} forEach _inventory; \ No newline at end of file +[_vehicle, _inventory] call FUNC(addCargo); \ No newline at end of file