Skip to content

Commit

Permalink
Added alternative function setCargo that replace cargo and addCargo t…
Browse files Browse the repository at this point in the history
…hat append to the cargo container (#1165)

Co-authored-by: Jonah Pool <[email protected]>
  • Loading branch information
AndreasBrostrom and pool011 authored Apr 7, 2024
1 parent 38dd73d commit 7b95a68
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 43 deletions.
1 change: 1 addition & 0 deletions cScripts/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class cScripts {
class logistics {
file = "cScripts\functions\logistics";
class addCargo {};
class setCargo {};
class setCargoAttributes {};
class checkItemValidity {};
class createCargoCrate {};
Expand Down
11 changes: 2 additions & 9 deletions cScripts/functions/logistics/fn_addCargo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 <OBJECT>
Expand All @@ -14,22 +14,15 @@
* 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", [], [[]]]
];

clearWeaponCargoGlobal _vehicle;
clearMagazineCargoGlobal _vehicle;
clearItemCargoGlobal _vehicle;
clearBackpackCargoGlobal _vehicle;

if ( count _inventory < 1 ) exitWith {};

{
Expand Down
2 changes: 1 addition & 1 deletion cScripts/functions/logistics/fn_createCargoCrate.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cScripts/functions/logistics/fn_doFieldHospital.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cScripts/functions/logistics/fn_doStarterCrateSupplies.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ private _container = switch (_companySelector) do {
default {[]};
};

[_crate, _container] call FUNC(addCargo);
[_crate, _container] call FUNC(setCargo);

true
2 changes: 1 addition & 1 deletion cScripts/functions/logistics/fn_doSupplyCrate.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
31 changes: 31 additions & 0 deletions cScripts/functions/logistics/fn_setCargo.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#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 <OBJECT>
* 1: Inventory <ARRAY>
*
* Return Value:
* Nothing
*
* Example:
* [MyCrate, [["ACE_EarPlugs", 60]]] call cScripts_fnc_setCargo;
* [MyTruck, [["ACE_personalAidKit", 8], ["ACE_tourniquet", 10]]] call cScripts_fnc_setCargo;
*
* Public: Yes
*/

params [
["_vehicle", objNull, [objNull]],
["_inventory", [], [[]]]
];

clearWeaponCargoGlobal _vehicle;
clearMagazineCargoGlobal _vehicle;
clearItemCargoGlobal _vehicle;
clearBackpackCargoGlobal _vehicle;

[_vehicle, _inventory] call FUNC(addCargo);
60 changes: 30 additions & 30 deletions cScripts/functions/vehicle/fn_vehicle_addInventory.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,7 +57,7 @@ if (_vehicle iskindOf "cav_dragoon_base_F") then {
// Vehicle Inventory
[_vehicle,
GET_CONTAINER("vehicle_strykerDragoon_V4")
] call FUNC(addCargo);
] call FUNC(setCargo);

// Supply Crate
["Box_NATO_Equip_F",
Expand Down Expand Up @@ -99,7 +99,7 @@ if (_vehicle iskindOf "cav_dragoon_base_F") then {
// Vehicle Inventory
[_vehicle,
GET_CONTAINER("vehicle_strykerDragoon")
] call FUNC(addCargo);
] call FUNC(setCargo);

// Supply Crate
["Box_NATO_Equip_F",
Expand All @@ -126,7 +126,7 @@ if (_vehicle iskindOf "cav_dragoon_base_F") then {
case "MED": {
[_vehicle,
GET_CONTAINER("vehicle_medicalAtlas")
] call FUNC(addCargo);
] call FUNC(setCargo);

["ace_medicalSupplyCrate",
GET_CONTAINER("crate_medicalAtlas"),
Expand All @@ -139,7 +139,7 @@ if (_vehicle iskindOf "cav_dragoon_base_F") then {
// Vehicle Inventory
[_vehicle,
GET_CONTAINER("vehicle_strykerDragoon")
] call FUNC(addCargo);
] call FUNC(setCargo);

// Supply Crate
["Box_NATO_Equip_F",
Expand Down Expand Up @@ -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"),
Expand All @@ -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";
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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 {
Expand All @@ -270,15 +270,15 @@ 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"),
_vehicle
] call FUNC(createCargoCrate);
};
default {
[_vehicle, []] call FUNC(addCargo);
[_vehicle, []] call FUNC(setCargo);
};
};
["ACE_Wheel", _vehicle, true] call ace_cargo_fnc_loadItem;
Expand All @@ -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"),
Expand All @@ -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);
Expand All @@ -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;
};
Expand All @@ -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);
};


Expand All @@ -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"),
Expand All @@ -374,36 +374,36 @@ if (_vehicle iskindOf "Heli_Transport_01_base_F") then {
default {
[_vehicle,
GET_CONTAINER("vehicle_heliTransport")
] call FUNC(addCargo);
] call FUNC(setCargo);
};
};
};

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);
};

0 comments on commit 7b95a68

Please sign in to comment.