2015-08-10 21:07:47 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal, ViperMaul
|
2015-08-16 20:41:35 +00:00
|
|
|
* Unload object from vehicle.
|
2015-08-10 21:07:47 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2015-09-27 16:19:40 +00:00
|
|
|
* 0: Item <OBJECT or STRING>
|
2015-08-10 21:07:47 +00:00
|
|
|
* 1: Vehicle <OBJECT>
|
|
|
|
*
|
|
|
|
* Return value:
|
2015-08-16 20:48:52 +00:00
|
|
|
* Object unloaded <BOOL>
|
2015-08-10 21:07:47 +00:00
|
|
|
*
|
2015-08-16 20:41:35 +00:00
|
|
|
* Example:
|
|
|
|
* [object, vehicle] call ace_cargo_fnc_unloadItem
|
|
|
|
*
|
2015-08-10 21:07:47 +00:00
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2016-01-27 00:01:01 +00:00
|
|
|
params ["_item", "_vehicle", ["_unloader", objNull]];
|
|
|
|
TRACE_3("params",_item,_vehicle,_unloader);
|
2015-08-10 21:07:47 +00:00
|
|
|
|
2016-01-27 00:01:01 +00:00
|
|
|
private _itemClass = if (_item isEqualType "") then {_item} else {typeOf _item};
|
2015-08-10 21:07:47 +00:00
|
|
|
|
2016-01-27 00:01:01 +00:00
|
|
|
//This covers testing vehicle stability and finding a safe position
|
|
|
|
private _emptyPosAGL = [_vehicle, _itemClass, _unloader] call EFUNC(common,findUnloadPosition);
|
|
|
|
TRACE_1("findUnloadPosition",_emptyPosAGL);
|
2015-09-27 16:19:40 +00:00
|
|
|
|
2016-01-27 00:01:01 +00:00
|
|
|
if ((count _emptyPosAGL) != 3) exitWith {
|
|
|
|
TRACE_4("Could not find unload pos",_vehicle,getPosASL _vehicle,isTouchingGround _vehicle,speed _vehicle);
|
|
|
|
if ((!isNull _unloader) && {_unloader == ACE_player}) then {
|
|
|
|
//display text saying there are no safe places to exit the vehicle
|
2016-05-22 15:29:05 +00:00
|
|
|
["displayTextStructured", [localize ELSTRING(common,NoRoomToUnload)]] call CBA_fnc_localEvent;
|
2015-08-10 21:07:47 +00:00
|
|
|
};
|
2016-01-27 00:01:01 +00:00
|
|
|
false
|
2015-08-10 21:07:47 +00:00
|
|
|
};
|
|
|
|
|
2016-01-19 03:53:48 +00:00
|
|
|
private _loaded = _vehicle getVariable [QGVAR(loaded), []];
|
2016-01-27 00:01:01 +00:00
|
|
|
|
|
|
|
if !(_item in _loaded) exitWith {
|
|
|
|
ACE_LOGERROR_3("Tried to unload item [%1] not in vehicle[%2] cargo[%3]", _item, _vehicle, _loaded);
|
|
|
|
false
|
|
|
|
};
|
|
|
|
|
2015-09-27 16:19:40 +00:00
|
|
|
_loaded deleteAt (_loaded find _item);
|
2015-08-16 20:41:35 +00:00
|
|
|
_vehicle setVariable [QGVAR(loaded), _loaded, true];
|
2015-08-10 21:07:47 +00:00
|
|
|
|
2016-01-19 03:53:48 +00:00
|
|
|
private _space = [_vehicle] call FUNC(getCargoSpaceLeft);
|
|
|
|
private _itemSize = [_item] call FUNC(getSizeItem);
|
2015-08-16 20:41:35 +00:00
|
|
|
_vehicle setVariable [QGVAR(space), (_space + _itemSize), true];
|
2015-08-10 21:07:47 +00:00
|
|
|
|
2015-11-20 17:40:31 +00:00
|
|
|
if (_item isEqualType objNull) then {
|
2015-09-27 16:19:40 +00:00
|
|
|
detach _item;
|
2016-02-23 21:05:15 +00:00
|
|
|
// 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
|
2016-05-22 15:29:05 +00:00
|
|
|
["ServerUnloadCargo", [_item, _emptyPosAGL]] call CBA_fnc_serverEvent;
|
2015-09-27 16:19:40 +00:00
|
|
|
} else {
|
2016-01-27 00:01:01 +00:00
|
|
|
private _newItem = createVehicle [_item, _emptyPosAGL, [], 0, ""];
|
|
|
|
_newItem setPosASL (AGLtoASL _emptyPosAGL);
|
2015-09-27 16:19:40 +00:00
|
|
|
};
|
2015-08-18 16:48:21 +00:00
|
|
|
|
2015-08-16 20:48:52 +00:00
|
|
|
true
|