From d8118ac3aa9d770a5b82accaaa17aeba4fa50c06 Mon Sep 17 00:00:00 2001 From: Vdauphin Date: Sat, 7 Nov 2020 10:44:07 +0100 Subject: [PATCH] Add: getVehicleCargo and differentiate normal "CargoNet_01_box_F" and ACE "CargoNet_01_box_F" --- addons/cargo/XEH_PREP.hpp | 1 + .../fnc_canShowUnloadAllVehicles.sqf | 2 +- .../cargo/functions/fnc_getVehicleCargo.sqf | 22 +++++++++++++++++++ addons/cargo/functions/fnc_loadItem.sqf | 5 +++-- .../cargo/functions/fnc_unloadAllVehicles.sqf | 4 ++-- 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 addons/cargo/functions/fnc_getVehicleCargo.sqf diff --git a/addons/cargo/XEH_PREP.hpp b/addons/cargo/XEH_PREP.hpp index 1fbea404a7..79351a1230 100644 --- a/addons/cargo/XEH_PREP.hpp +++ b/addons/cargo/XEH_PREP.hpp @@ -5,6 +5,7 @@ PREP(canShowUnloadAllVehicles); PREP(canUnloadItem); PREP(getCargoSpaceLeft); PREP(getSizeItem); +PREP(getVehicleCargo); PREP(handleDeleted); PREP(handleDestroyed); PREP(initObject); diff --git a/addons/cargo/functions/fnc_canShowUnloadAllVehicles.sqf b/addons/cargo/functions/fnc_canShowUnloadAllVehicles.sqf index b6e5c60650..4e4b6fdf74 100644 --- a/addons/cargo/functions/fnc_canShowUnloadAllVehicles.sqf +++ b/addons/cargo/functions/fnc_canShowUnloadAllVehicles.sqf @@ -23,4 +23,4 @@ params [ driver _vehicle isEqualTo _unit && {isClass (configOf _vehicle >> "VehicleTransport" >> "Carrier")} && -{!(getVehicleCargo _vehicle - (_vehicle getVariable [QGVAR(loaded), []]) isEqualTo [])} +{!([_vehicle] call ace_cargo_fnc_getVehicleCargo isEqualTo [])} diff --git a/addons/cargo/functions/fnc_getVehicleCargo.sqf b/addons/cargo/functions/fnc_getVehicleCargo.sqf new file mode 100644 index 0000000000..17a3713fb6 --- /dev/null +++ b/addons/cargo/functions/fnc_getVehicleCargo.sqf @@ -0,0 +1,22 @@ +#include "script_component.hpp" +/* + * Author: Vdauphin + * Get vehicle in cargo. + * + * Arguments: + * 0: Vehicle + * + * Return Value: + * Loaded vehicles not part of ACE Cargo + * + * Example: + * [vehicle player] call ace_cargo_fnc_getVehicleCargo + * + * Public: No + */ + +params ["_vehicle"]; + +(getVehicleCargo _vehicle - (_vehicle getVariable [QGVAR(loaded), []])) select { + !(_x getVariable [QGVAR(isCargoNet), false]) +} diff --git a/addons/cargo/functions/fnc_loadItem.sqf b/addons/cargo/functions/fnc_loadItem.sqf index 50ce64ae7b..1077765e86 100644 --- a/addons/cargo/functions/fnc_loadItem.sqf +++ b/addons/cargo/functions/fnc_loadItem.sqf @@ -41,14 +41,14 @@ if (_item isEqualType objNull) then { (_vehicle canVehicleCargo _item) isEqualTo [false, true] && // Could be loaded if _vehicle was empty {_vehicleCargo findIf { !(_x in _loaded) && // Don't use ViV if ViV was used outside of ACE Cargo - !(typeOf _x isEqualTo "CargoNet_01_box_F") + !(_x getVariable [QGVAR(isCargoNet), false]) } isEqualTo -1} ) then { private _cargoNet = createVehicle ["CargoNet_01_box_F", [0, 0, 0], [], 0, "CAN_COLLIDE"]; if ((_vehicle canVehicleCargo _cargoNet) select 1) then { while {!(_vehicle setVehicleCargo _cargoNet)} do { // Move ViV cargo to ACE Cargo private _itemViV = _vehicleCargo deleteAt 0; - if (typeOf _itemViV isEqualTo "CargoNet_01_box_F") exitWith { // The vehicle is already full of "CargoNet_01_box_F") + if (_itemViV getVariable [QGVAR(isCargoNet), false]) exitWith { // The vehicle is already full of cargo net deleteVehicle _cargoNet; _item setVariable [QGVAR(cargoNet), _itemViV, true]; }; @@ -62,6 +62,7 @@ if (_item isEqualType objNull) then { [_itemViV, "blockDamage", "ACE_cargo", true] call EFUNC(common,statusEffect_set); }; if !(isNull _cargoNet) then { + _cargoNet setVariable [QGVAR(isCargoNet), true, true]; _item setVariable [QGVAR(cargoNet), _cargoNet, true]; }; } else { diff --git a/addons/cargo/functions/fnc_unloadAllVehicles.sqf b/addons/cargo/functions/fnc_unloadAllVehicles.sqf index d3507af047..deaaf5dfeb 100644 --- a/addons/cargo/functions/fnc_unloadAllVehicles.sqf +++ b/addons/cargo/functions/fnc_unloadAllVehicles.sqf @@ -7,7 +7,7 @@ * 0: Vehicle * * Return Value: - * Loaded vehiclesnot part of ACE Cargo + * Loaded vehicles not part of ACE Cargo * * Example: * [vehicle player] call ace_cargo_fnc_unloadAllVehicles @@ -17,7 +17,7 @@ params ["_vehicle"]; -private _loadedVehicles = getVehicleCargo _vehicle - (_vehicle getVariable [QGVAR(loaded), []]); +private _loadedVehicles = [_vehicle] call ace_cargo_fnc_getVehicleCargo; private _unloadingInterval = getNumber (configOf _vehicle >> "VehicleTransport" >> "Carrier" >> "unloadingInterval"); { [{objnull setVehicleCargo _this}, _x, _forEachIndex * _unloadingInterval] call CBA_fnc_waitAndExecute;