ACE3/addons/cargo/functions/fnc_unload.sqf

66 lines
2.1 KiB
Plaintext
Raw Normal View History

#include "script_component.hpp"
/*
* Author: Glowbal, ViperMaul
* Unload object from vehicle.
*
* Arguments:
* 0: Item <OBJECT or STRING>
* 1: Empty position <ARRAY>
* 2: Items loaded in cargo <ARRAY>
* 3: Vehicle with the item loaded <OBJECT>
2021-08-04 16:56:48 +00:00
* 4: Avoid creation of a parachute by A3 <BOOL>
*
* Return Value:
* Object unloaded <OBJECT>
*
* Example:
* [item, posAGL, loaded, vehicle] call ace_cargo_fnc_unload
*
* Public: No
*/
2021-08-04 16:56:48 +00:00
params ["_item", "_posAGL", "_loaded", "_vehicle", "_isParadrop"];
_loaded deleteAt (_loaded find _item);
_vehicle setVariable [QGVAR(loaded), _loaded, true];
private _space = [_vehicle] call FUNC(getCargoSpaceLeft);
private _itemSize = [_item] call FUNC(getSizeItem);
_vehicle setVariable [QGVAR(space), _space + _itemSize, true];
private _object = _item;
if (_object isEqualType objNull) then {
if (isNull isVehicleCargo _object) then {
detach _object;
// hideObjectGlobal must be executed before setPos to ensure light objects are rendered correctly
// do both on server to ensure they are executed in the correct order
[QGVAR(serverUnload), [_object, _posAGL]] call CBA_fnc_serverEvent;
private _cargoNet = _object getVariable [QGVAR(cargoNet), objNull];
if !(isNull _cargoNet) then {
private _itemsRemaining = _loaded select {
_x getVariable [QGVAR(cargoNet), objNull] isEqualTo _cargoNet
};
if (_itemsRemaining isEqualTo []) then {
objNull setVehicleCargo _cargoNet;
deleteVehicle _cargoNet;
};
};
} else {
2021-08-04 16:56:48 +00:00
if (_isParadrop) then {
detach _object; // Don't create a parachute by A3 engine
} else {
objNull setVehicleCargo _object;
};
_object setPosASL (AGLtoASL _posAGL);
};
} else {
_object = createVehicle [_item, _posAGL, [], 0, "NONE"];
_object setPosASL (AGLtoASL _posAGL);
2021-08-03 20:43:42 +00:00
[QEGVAR(common,fixCollision), _object] call CBA_fnc_localEvent;
[QEGVAR(common,fixPosition), _object] call CBA_fnc_localEvent;
};
_object