2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2016-08-27 08:14:54 +00:00
|
|
|
/*
|
|
|
|
* Author: marc_book, commy2, CAA-Picard
|
|
|
|
* Unload and paradrop object from plane or helicopter.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Object <OBJECT>
|
|
|
|
* 1: Vehicle <OBJECT>
|
2019-01-31 00:30:42 +00:00
|
|
|
* 2: Show Hint <BOOL> (default: true)
|
2016-08-27 08:14:54 +00:00
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Return Value:
|
2016-08-27 08:14:54 +00:00
|
|
|
* Object unloaded <BOOL>
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [object, vehicle] call ace_cargo_fnc_paradropItem
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2019-01-31 00:30:42 +00:00
|
|
|
params ["_item", "_vehicle", ["_showHint", true]];
|
2016-08-27 08:14:54 +00:00
|
|
|
TRACE_2("params",_item,_vehicle);
|
|
|
|
|
|
|
|
private _loaded = _vehicle getVariable [QGVAR(loaded), []];
|
|
|
|
|
|
|
|
if !(_item in _loaded) exitWith {false};
|
|
|
|
|
|
|
|
// unload item from cargo
|
|
|
|
_loaded deleteAt (_loaded find _item);
|
|
|
|
_vehicle setVariable [QGVAR(loaded), _loaded, true];
|
|
|
|
|
|
|
|
private _cargoSpace = [_vehicle] call FUNC(getCargoSpaceLeft);
|
|
|
|
private _itemSize = [_item] call FUNC(getSizeItem);
|
|
|
|
_vehicle setVariable [QGVAR(space), (_cargoSpace + _itemSize), true];
|
|
|
|
|
2016-09-10 19:21:09 +00:00
|
|
|
(boundingBoxReal _vehicle) params ["_bb1", "_bb2"];
|
2017-05-31 22:54:57 +00:00
|
|
|
private _distBehind = ((_bb1 select 1) min (_bb2 select 1)) - 4; // 4 meters behind max bounding box
|
2016-08-27 08:14:54 +00:00
|
|
|
TRACE_1("",_distBehind);
|
2017-05-31 22:54:57 +00:00
|
|
|
private _posBehindVehicleAGL = _vehicle modelToWorld [0, _distBehind, -2];
|
2016-08-27 08:14:54 +00:00
|
|
|
|
|
|
|
|
2021-05-01 03:38:57 +00:00
|
|
|
private _object = _item;
|
|
|
|
if (_item isEqualType objNull) then {
|
|
|
|
detach _object;
|
2016-08-27 08:14:54 +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
|
2021-05-01 03:38:57 +00:00
|
|
|
[QGVAR(serverUnload), [_object, _posBehindVehicleAGL]] call CBA_fnc_serverEvent;
|
2016-08-27 08:14:54 +00:00
|
|
|
} else {
|
2021-05-01 03:38:57 +00:00
|
|
|
_object = createVehicle [_item, _posBehindVehicleAGL, [], 0, "NONE"];
|
|
|
|
_object setPosASL (AGLtoASL _posBehindVehicleAGL);
|
2016-08-27 08:14:54 +00:00
|
|
|
};
|
|
|
|
|
2021-05-01 03:38:57 +00:00
|
|
|
_object setVelocity ((velocity _vehicle) vectorAdd ((vectorNormalized (vectorDir _vehicle)) vectorMultiply -5));
|
2016-08-27 08:14:54 +00:00
|
|
|
|
|
|
|
// open parachute and ir light effect
|
|
|
|
[{
|
2021-05-01 03:38:57 +00:00
|
|
|
params ["_object"];
|
2016-08-27 08:14:54 +00:00
|
|
|
|
2021-05-01 03:38:57 +00:00
|
|
|
if (isNull _object || {getPos _object select 2 < 1}) exitWith {};
|
2016-08-27 08:14:54 +00:00
|
|
|
|
|
|
|
private _parachute = createVehicle ["B_Parachute_02_F", [0,0,0], [], 0, "CAN_COLLIDE"];
|
|
|
|
|
2016-09-25 07:45:55 +00:00
|
|
|
// cannot use setPos on parachutes without them closing down
|
2021-05-01 03:38:57 +00:00
|
|
|
_parachute attachTo [_object, [0,0,0]];
|
2016-09-25 07:45:55 +00:00
|
|
|
detach _parachute;
|
|
|
|
|
2021-05-01 03:38:57 +00:00
|
|
|
private _velocity = velocity _object;
|
2016-09-25 07:45:55 +00:00
|
|
|
|
2021-05-01 03:38:57 +00:00
|
|
|
_object attachTo [_parachute, [0,0,1]];
|
2016-09-25 07:45:55 +00:00
|
|
|
_parachute setVelocity _velocity;
|
2016-08-27 08:14:54 +00:00
|
|
|
|
2021-05-01 03:38:57 +00:00
|
|
|
if ((GVAR(disableParadropEffectsClasstypes) findIf {_object isKindOf _x}) == -1) then {
|
2019-07-03 14:58:46 +00:00
|
|
|
private _light = "Chemlight_yellow" createVehicle [0,0,0];
|
2021-05-01 03:38:57 +00:00
|
|
|
_light attachTo [_object, [0,0,0]];
|
2019-07-03 14:58:46 +00:00
|
|
|
};
|
2016-08-27 08:14:54 +00:00
|
|
|
|
2021-05-01 03:38:57 +00:00
|
|
|
}, [_object], 0.7] call CBA_fnc_waitAndExecute;
|
2016-08-27 08:14:54 +00:00
|
|
|
|
|
|
|
// smoke effect when crate landed
|
|
|
|
[{
|
2021-05-01 03:38:57 +00:00
|
|
|
(_this select 0) params ["_object"];
|
2016-08-27 08:14:54 +00:00
|
|
|
|
2021-05-01 03:38:57 +00:00
|
|
|
if (isNull _object) exitWith {
|
2016-08-27 08:14:54 +00:00
|
|
|
[_this select 1] call CBA_fnc_removePerFrameHandler;
|
|
|
|
};
|
|
|
|
|
2021-05-01 03:38:57 +00:00
|
|
|
if (getPos _object select 2 < 1) then {
|
|
|
|
if ((GVAR(disableParadropEffectsClasstypes) findIf {_object isKindOf _x}) == -1) then {
|
2019-07-03 14:58:46 +00:00
|
|
|
private _smoke = "SmokeshellYellow" createVehicle [0,0,0];
|
2021-05-01 03:38:57 +00:00
|
|
|
_smoke attachTo [_object, [0,0,0]];
|
2019-07-03 14:58:46 +00:00
|
|
|
};
|
2016-08-27 08:14:54 +00:00
|
|
|
|
|
|
|
[_this select 1] call CBA_fnc_removePerFrameHandler;
|
|
|
|
};
|
|
|
|
|
2021-05-01 03:38:57 +00:00
|
|
|
}, 1, [_object]] call CBA_fnc_addPerFrameHandler;
|
2016-08-27 08:14:54 +00:00
|
|
|
|
2019-01-31 00:30:42 +00:00
|
|
|
if (_showHint) then {
|
2017-05-05 19:02:59 +00:00
|
|
|
[
|
2019-01-31 00:30:42 +00:00
|
|
|
[
|
|
|
|
LSTRING(UnloadedItem),
|
2021-10-17 05:48:31 +00:00
|
|
|
[_object, true] call FUNC(getNameItem),
|
2021-02-18 18:58:08 +00:00
|
|
|
getText (configOf _vehicle >> "displayName")
|
2019-01-31 00:30:42 +00:00
|
|
|
],
|
|
|
|
3
|
|
|
|
] call EFUNC(common,displayTextStructured);
|
|
|
|
};
|
2017-05-05 19:02:59 +00:00
|
|
|
|
2016-08-27 08:14:54 +00:00
|
|
|
// Invoke listenable event
|
2021-05-01 03:38:57 +00:00
|
|
|
["ace_cargoUnloaded", [_object, _vehicle, "paradrop"]] call CBA_fnc_globalEvent;
|
2016-08-27 08:14:54 +00:00
|
|
|
|
|
|
|
true
|