2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2017-09-16 16:21:23 +00:00
|
|
|
/*
|
|
|
|
* Author: 654wak654
|
|
|
|
* Removes a cargo item from the vehicle.
|
|
|
|
*
|
|
|
|
* Arguments:
|
2023-11-17 23:07:28 +00:00
|
|
|
* 0: Item to be removed <STRING> or <OBJECT> (default: "")
|
|
|
|
* 1: Holder object (vehicle) <OBJECT> (default: objNull)
|
2017-09-16 16:21:23 +00:00
|
|
|
* 2: Amount <NUMBER> (default: 1)
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Number of items removed <NUMBER>
|
|
|
|
*
|
|
|
|
* Example:
|
2023-11-17 23:07:28 +00:00
|
|
|
* ["ACE_Wheel", cursorObject, 2] call ace_cargo_fnc_removeCargoItem
|
2017-09-16 16:21:23 +00:00
|
|
|
* [crate_7, truck] call ace_cargo_fnc_removeCargoItem
|
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
params [["_item", "", [objNull, ""]], ["_vehicle", objNull, [objNull]], ["_amount", 1, [0]]];
|
2017-09-16 16:21:23 +00:00
|
|
|
TRACE_3("params",_item,_vehicle,_amount);
|
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// Get config sensitive case name
|
|
|
|
if (_item isEqualType "") then {
|
|
|
|
_item = _item call EFUNC(common,getConfigName);
|
|
|
|
};
|
|
|
|
|
2017-09-16 16:21:23 +00:00
|
|
|
private _loaded = _vehicle getVariable [QGVAR(loaded), []];
|
|
|
|
|
|
|
|
private _addedSpace = 0;
|
|
|
|
private _itemClass = _item;
|
|
|
|
private _itemsRemoved = 0;
|
|
|
|
|
|
|
|
private _continue = if (_item isEqualType objNull) then {
|
|
|
|
if !(_item in _loaded) exitWith {false};
|
2023-11-17 23:07:28 +00:00
|
|
|
|
|
|
|
_addedSpace = (_item call FUNC(getSizeItem)) max 0; // don't let negative size items increase space
|
2017-09-16 16:21:23 +00:00
|
|
|
_loaded deleteAt (_loaded find _item);
|
2023-11-17 23:07:28 +00:00
|
|
|
|
2017-09-16 16:21:23 +00:00
|
|
|
_itemClass = typeOf _item;
|
2023-11-17 23:07:28 +00:00
|
|
|
|
|
|
|
// Delete item
|
2017-09-16 16:21:23 +00:00
|
|
|
deleteVehicle _item;
|
2023-11-17 23:07:28 +00:00
|
|
|
|
2017-09-16 16:21:23 +00:00
|
|
|
_itemsRemoved = 1;
|
2023-11-17 23:07:28 +00:00
|
|
|
|
2017-09-16 16:21:23 +00:00
|
|
|
true
|
|
|
|
} else {
|
|
|
|
{
|
|
|
|
if (_itemsRemoved == _amount) exitWith {};
|
|
|
|
|
|
|
|
if (
|
2023-11-17 23:07:28 +00:00
|
|
|
(_x isEqualType "" && {_x == _item}) ||
|
|
|
|
{_x isEqualType objNull && {typeOf _x == _item}}
|
2017-09-16 16:21:23 +00:00
|
|
|
) then {
|
|
|
|
INC(_itemsRemoved);
|
2023-11-17 23:07:28 +00:00
|
|
|
_addedSpace = _addedSpace + ((_x call FUNC(getSizeItem)) max 0); // don't let negative size items increase space
|
2017-09-16 16:21:23 +00:00
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// Delete item
|
2017-09-16 16:21:23 +00:00
|
|
|
if (_x isEqualType objNull) then {
|
|
|
|
deleteVehicle _x;
|
|
|
|
};
|
2023-11-17 23:07:28 +00:00
|
|
|
|
2017-09-16 16:21:23 +00:00
|
|
|
_loaded set [_forEachIndex, nil];
|
|
|
|
};
|
|
|
|
} forEach _loaded;
|
|
|
|
|
2020-02-11 22:41:18 +00:00
|
|
|
FILTER(_loaded,!isNil "_x");
|
2023-11-17 23:07:28 +00:00
|
|
|
|
2017-09-16 16:21:23 +00:00
|
|
|
true
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!_continue) exitWith {0};
|
|
|
|
|
|
|
|
_vehicle setVariable [QGVAR(loaded), _loaded, true];
|
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// Update remaining cargo space
|
|
|
|
private _cargoSpace = _vehicle call FUNC(getCargoSpaceLeft);
|
|
|
|
_vehicle setVariable [QGVAR(space), _cargoSpace + _addedSpace, true];
|
2017-09-16 16:21:23 +00:00
|
|
|
|
|
|
|
// Invoke listenable event
|
|
|
|
["ace_cargoRemoved", [_itemClass, _vehicle, _amount, _itemsRemoved]] call CBA_fnc_globalEvent;
|
|
|
|
|
|
|
|
_itemsRemoved
|