ACE3/addons/cargo/functions/fnc_startLoadIn.sqf

109 lines
3.3 KiB
Plaintext
Raw Normal View History

#include "..\script_component.hpp"
2015-08-10 21:07:47 +00:00
/*
* Author: Glowbal
* Starts loading item.
2015-08-10 21:07:47 +00:00
*
* Arguments:
* 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:
* [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
*/
params ["_loader", "_item", ["_vehicle", objNull]];
TRACE_3("params",_loader,_item,_vehicle);
2015-08-10 21:07:47 +00:00
if (isNull _vehicle) then {
2015-08-14 20:01:14 +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 {
TRACE_3("Could not find vehicle",_loader,_item,_vehicle);
false // return
2016-01-19 03:53:48 +00:00
};
// Start progress bar
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);
[
_duration,
[_item, _vehicle],
{
TRACE_1("load finish",_this);
[objNull, _this select 0 select 0, true] call EFUNC(common,claim);
["ace_loadCargo", _this select 0] call CBA_fnc_localEvent;
},
{
TRACE_1("load fail",_this);
(_this select 0) params ["_item", "_vehicle"];
[objNull, _item, true] call EFUNC(common,claim);
[[LSTRING(loadingFailed), [_item, true] call FUNC(getNameItem)], 3] call EFUNC(common,displayTextStructured);
// 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;
};
},
format [LLSTRING(loadingItem), [_item, true] call FUNC(getNameItem), getText (configOf _vehicle >> "displayName")],
{
(_this select 0) call FUNC(canLoadItemIn)
},
["isNotSwimming"]
] call EFUNC(common,progressBar);
true // return
} else {
// Unlock the object
[objNull, _item, true] call EFUNC(common,claim);
[[LSTRING(loadingFailed), [_item, true] call FUNC(getNameItem)], 3] call EFUNC(common,displayTextStructured);
2016-01-19 03:53:48 +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
};