2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2016-08-27 08:14:54 +00:00
|
|
|
/*
|
|
|
|
* Author: marc_book, commy2, CAA-Picard
|
2023-11-17 23:07:28 +00:00
|
|
|
* Unloads and paradrops an object from a plane or helicopter.
|
2016-08-27 08:14:54 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2023-11-17 23:07:28 +00:00
|
|
|
* 0: Item <STRING> or <OBJECT>
|
|
|
|
* 1: Holder object (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:
|
2023-11-17 23:07:28 +00:00
|
|
|
* ["ACE_Wheel", vehicle player] call ace_cargo_fnc_paradropItem
|
2016-08-27 08:14:54 +00:00
|
|
|
*
|
|
|
|
* 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);
|
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// Get config sensitive case name
|
|
|
|
if (_item isEqualType "") then {
|
|
|
|
_item = _item call EFUNC(common,getConfigName);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Check if item is actually part of cargo
|
2016-08-27 08:14:54 +00:00
|
|
|
private _loaded = _vehicle getVariable [QGVAR(loaded), []];
|
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
if !(_item in _loaded) exitWith {
|
|
|
|
false // return
|
|
|
|
};
|
|
|
|
|
|
|
|
// Check if item can be unloaded
|
|
|
|
private _itemSize = _item call FUNC(getSizeItem);
|
2016-08-27 08:14:54 +00:00
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
if (_itemSize < 0) exitWith {
|
|
|
|
false // return
|
|
|
|
};
|
|
|
|
|
|
|
|
// Unload item from cargo
|
2016-08-27 08:14:54 +00:00
|
|
|
_loaded deleteAt (_loaded find _item);
|
|
|
|
_vehicle setVariable [QGVAR(loaded), _loaded, true];
|
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// Update cargo space remaining
|
|
|
|
private _cargoSpace = _vehicle call FUNC(getCargoSpaceLeft);
|
|
|
|
_vehicle setVariable [QGVAR(space), _cargoSpace + _itemSize, true];
|
2016-08-27 08:14:54 +00:00
|
|
|
|
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
|
|
|
|
private _posBehindVehicleAGL = _vehicle modelToWorld [0, _distBehind, -2];
|
2016-08-27 08:14:54 +00:00
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
TRACE_1("",_distBehind);
|
2016-08-27 08:14:54 +00:00
|
|
|
|
2021-05-01 03:38:57 +00:00
|
|
|
private _object = _item;
|
2023-11-17 23:07:28 +00:00
|
|
|
|
2021-05-01 03:38:57 +00:00
|
|
|
if (_item isEqualType objNull) then {
|
|
|
|
detach _object;
|
2023-11-17 23:07:28 +00:00
|
|
|
|
2016-08-27 08:14:54 +00:00
|
|
|
// hideObjectGlobal must be executed before setPos to ensure light objects are rendered correctly
|
2023-11-17 23:07:28 +00:00
|
|
|
// 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
|
|
|
};
|
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
[QEGVAR(common,setVelocity), [_object, (velocity _vehicle) vectorAdd ((vectorNormalized (vectorDir _vehicle)) vectorMultiply -5)], _object] call CBA_fnc_targetEvent;
|
2016-08-27 08:14:54 +00:00
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// Open parachute and IR light effect
|
2016-08-27 08:14:54 +00:00
|
|
|
[{
|
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
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
private _parachute = createVehicle ["B_Parachute_02_F", [0, 0, 0], [], 0, "CAN_COLLIDE"];
|
2016-08-27 08:14:54 +00:00
|
|
|
|
2023-09-14 21:54:06 +00:00
|
|
|
// Prevent collision damage
|
|
|
|
[QEGVAR(common,fixCollision), _parachute] call CBA_fnc_localEvent;
|
|
|
|
[QEGVAR(common,fixCollision), _object, _object] call CBA_fnc_targetEvent;
|
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// Cannot use setPos on parachutes without them closing down
|
|
|
|
_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
|
|
|
|
2023-09-14 21:54:06 +00:00
|
|
|
// Attach to the middle of the object
|
|
|
|
(2 boundingBoxReal _object) params ["_bb1", "_bb2"];
|
|
|
|
|
|
|
|
_object attachTo [_parachute, [0, 0, ((_bb2 select 2) - (_bb1 select 2)) / 2]];
|
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 {
|
2023-11-17 23:07:28 +00:00
|
|
|
private _light = "Chemlight_yellow" createVehicle [0, 0, 0];
|
|
|
|
_light attachTo [_object, [0, 0, 0]];
|
2019-07-03 14:58:46 +00:00
|
|
|
};
|
2023-11-17 23:07:28 +00:00
|
|
|
}, _object, 0.7] call CBA_fnc_waitAndExecute;
|
2016-08-27 08:14:54 +00:00
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// Create smoke effect when crate landed
|
2016-08-27 08:14:54 +00:00
|
|
|
[{
|
2024-07-22 17:15:43 +00:00
|
|
|
params ["_object", "_pfhID"];
|
2016-08-27 08:14:54 +00:00
|
|
|
|
2021-05-01 03:38:57 +00:00
|
|
|
if (isNull _object) exitWith {
|
2024-07-22 17:15:43 +00:00
|
|
|
_pfhID call CBA_fnc_removePerFrameHandler;
|
2016-08-27 08:14:54 +00:00
|
|
|
};
|
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
if (getPos _object select 2 < 1) exitWith {
|
2024-07-22 17:15:43 +00:00
|
|
|
_pfhID call CBA_fnc_removePerFrameHandler;
|
|
|
|
|
|
|
|
// Reenable UAV crew
|
|
|
|
private _UAVCrew = _object getVariable [QGVAR(isUAV), []];
|
|
|
|
|
|
|
|
if (_UAVCrew isNotEqualTo []) then {
|
|
|
|
// Reenable AI
|
|
|
|
{
|
|
|
|
[_x, false] call EFUNC(common,disableAiUAV);
|
|
|
|
} forEach _UAVCrew;
|
|
|
|
|
|
|
|
_object setVariable [QGVAR(isUAV), nil, true];
|
|
|
|
};
|
2023-11-17 23:07:28 +00:00
|
|
|
|
2021-05-01 03:38:57 +00:00
|
|
|
if ((GVAR(disableParadropEffectsClasstypes) findIf {_object isKindOf _x}) == -1) then {
|
2023-11-17 23:07:28 +00:00
|
|
|
private _smoke = "SmokeshellYellow" createVehicle [0, 0, 0];
|
|
|
|
_smoke attachTo [_object, [0, 0, 0]];
|
2019-07-03 14:58:46 +00:00
|
|
|
};
|
2016-08-27 08:14:54 +00:00
|
|
|
};
|
2023-11-17 23:07:28 +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
|
|
|
[
|
2023-11-17 23:07:28 +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
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
true // return
|