2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-08-10 21:07:47 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal
|
2023-11-17 23:07:28 +00:00
|
|
|
* Starts loading item.
|
2015-08-10 21:07:47 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2023-11-17 23:07:28 +00:00
|
|
|
* 0: Unit doing the loading <OBJECT>
|
|
|
|
* 1: Item to be loaded <OBJECT>
|
|
|
|
* 2: Holder object (vehicle) <OBJECT> (default: objNull)
|
2015-08-10 21:07:47 +00:00
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Return Value:
|
2016-01-19 03:53:48 +00:00
|
|
|
* Load ProgressBar Started <BOOL>
|
2015-08-10 21:07:47 +00:00
|
|
|
*
|
2015-08-16 20:41:35 +00:00
|
|
|
* Example:
|
2023-11-17 23:07:28 +00:00
|
|
|
* [player, cursorObject] call ace_cargo_fnc_startLoadIn
|
2015-08-16 20:41:35 +00:00
|
|
|
*
|
2015-08-10 21:07:47 +00:00
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
params ["_loader", "_item", ["_vehicle", objNull]];
|
|
|
|
TRACE_3("params",_loader,_item,_vehicle);
|
2015-08-10 21:07:47 +00:00
|
|
|
|
2017-05-31 15:02:25 +00:00
|
|
|
if (isNull _vehicle) then {
|
2015-08-14 20:01:14 +00:00
|
|
|
{
|
2023-11-17 23:07:28 +00:00
|
|
|
if ([_item, _x] call FUNC(canLoadItemIn)) exitWith {
|
|
|
|
_vehicle = _x;
|
|
|
|
};
|
|
|
|
} forEach (nearestObjects [_loader, GVAR(cargoHolderTypes), MAX_LOAD_DISTANCE + 10]);
|
2015-08-14 20:01:14 +00:00
|
|
|
};
|
|
|
|
|
2016-01-19 03:53:48 +00:00
|
|
|
if (isNull _vehicle) exitWith {
|
2023-11-17 23:07:28 +00:00
|
|
|
TRACE_3("Could not find vehicle",_loader,_item,_vehicle);
|
|
|
|
|
|
|
|
false // return
|
2016-01-19 03:53:48 +00:00
|
|
|
};
|
2015-08-16 20:48:52 +00:00
|
|
|
|
2015-09-27 16:19:40 +00:00
|
|
|
// Start progress bar
|
2023-11-17 23:07:28 +00:00
|
|
|
if ([_item, _vehicle] call FUNC(canLoadItemIn)) then {
|
|
|
|
private _duration = GVAR(loadTimeCoefficient) * (_item call FUNC(getSizeItem));
|
|
|
|
|
|
|
|
// If load time is 0, don't show a progress bar
|
|
|
|
if (_duration <= 0) exitWith {
|
|
|
|
["ace_loadCargo", [_item, _vehicle]] call CBA_fnc_localEvent;
|
|
|
|
|
|
|
|
true // return
|
|
|
|
};
|
|
|
|
|
|
|
|
// Claim so nobody else can interact with it
|
|
|
|
[_loader, _item, true] call EFUNC(common,claim);
|
2015-09-27 16:19:40 +00:00
|
|
|
|
2016-02-23 23:24:51 +00:00
|
|
|
[
|
2023-11-17 23:07:28 +00:00
|
|
|
_duration,
|
|
|
|
[_item, _vehicle],
|
2017-11-29 20:07:30 +00:00
|
|
|
{
|
2021-10-12 22:42:38 +00:00
|
|
|
TRACE_1("load finish",_this);
|
2023-11-17 23:07:28 +00:00
|
|
|
|
2017-11-29 20:07:30 +00:00
|
|
|
[objNull, _this select 0 select 0, true] call EFUNC(common,claim);
|
2023-11-17 23:07:28 +00:00
|
|
|
|
2017-11-29 20:07:30 +00:00
|
|
|
["ace_loadCargo", _this select 0] call CBA_fnc_localEvent;
|
|
|
|
},
|
2019-02-23 00:54:55 +00:00
|
|
|
{
|
|
|
|
TRACE_1("load fail",_this);
|
2023-11-17 23:07:28 +00:00
|
|
|
(_this select 0) params ["_item", "_vehicle"];
|
|
|
|
|
|
|
|
[objNull, _item, true] call EFUNC(common,claim);
|
|
|
|
|
|
|
|
// Fix cancelling loading a carried item
|
|
|
|
if (!isNull attachedTo _item) then {
|
|
|
|
detach _item;
|
|
|
|
|
|
|
|
// Prevent coliisions between item and vehicle
|
|
|
|
[QEGVAR(common,fixCollision), _vehicle, _vehicle] call CBA_fnc_targetEvent;
|
|
|
|
[QEGVAR(common,fixCollision), _item, _item] call CBA_fnc_targetEvent;
|
|
|
|
|
|
|
|
[QEGVAR(common,fixPosition), _item, _item] call CBA_fnc_targetEvent;
|
|
|
|
[QEGVAR(common,fixFloating), _item, _item] call CBA_fnc_targetEvent;
|
|
|
|
};
|
2019-02-23 00:54:55 +00:00
|
|
|
},
|
2023-11-17 23:07:28 +00:00
|
|
|
LLSTRING(loadingItem),
|
2019-02-23 00:54:55 +00:00
|
|
|
{
|
2023-11-17 23:07:28 +00:00
|
|
|
(_this select 0) call FUNC(canLoadItemIn)
|
2019-02-23 00:54:55 +00:00
|
|
|
},
|
2017-10-01 18:38:11 +00:00
|
|
|
["isNotSwimming"]
|
2016-02-23 23:24:51 +00:00
|
|
|
] call EFUNC(common,progressBar);
|
2023-11-17 23:07:28 +00:00
|
|
|
|
|
|
|
true // return
|
2015-09-27 16:19:40 +00:00
|
|
|
} else {
|
2023-11-17 23:07:28 +00:00
|
|
|
[[LSTRING(loadingFailed), [_item, true] call FUNC(getNameItem)], 3] call EFUNC(common,displayTextStructured);
|
2016-01-19 03:53:48 +00:00
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// Fix cancelling loading a carried item
|
|
|
|
if (!isNull attachedTo _item) then {
|
|
|
|
detach _item;
|
|
|
|
|
|
|
|
// Prevent coliisions between item and vehicle
|
|
|
|
[QEGVAR(common,fixCollision), _vehicle, _vehicle] call CBA_fnc_targetEvent;
|
|
|
|
[QEGVAR(common,fixCollision), _item, _item] call CBA_fnc_targetEvent;
|
|
|
|
|
|
|
|
[QEGVAR(common,fixPosition), _item, _item] call CBA_fnc_targetEvent;
|
|
|
|
[QEGVAR(common,fixFloating), _item, _item] call CBA_fnc_targetEvent;
|
|
|
|
};
|
|
|
|
|
|
|
|
false // return
|
|
|
|
};
|