-
Notifications
You must be signed in to change notification settings - Fork 749
Expand file tree
/
Copy pathfnc_startUnload.sqf
More file actions
122 lines (98 loc) · 3.93 KB
/
fnc_startUnload.sqf
File metadata and controls
122 lines (98 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "..\script_component.hpp"
/*
* Author: Glowbal
* Starts unloading item selected in the cargo menu.
*
* Arguments:
* 0: Unit doing the unloading <OBJECT>
*
* Return Value:
* None
*
* Example:
* player call ace_cargo_fnc_startUnload
*
* Public: No
*/
disableSerialization;
private _display = uiNamespace getVariable QGVAR(menuDisplay);
if (isNil "_display") exitWith {};
private _loaded = GVAR(interactionVehicle) getVariable [QGVAR(loaded), []];
if (_loaded isEqualTo []) exitWith {};
// This can be an object or a classname string
private _item = _loaded param [lbCurSel (_display displayCtrl 100), nil];
if (isNil "_item") exitWith {};
params ["_unit"];
if (GVAR(interactionParadrop)) exitWith {
// Close the cargo menu
closeDialog 0;
private _duration = GVAR(paradropTimeCoefficent) * (_item call FUNC(getSizeItem));
// If drop time is 0, don't show a progress bar
if (_duration <= 0) exitWith {
[QGVAR(paradropItem), [_item, GVAR(interactionVehicle)]] call CBA_fnc_localEvent;
};
// Start progress bar - paradrop
// Delay execution by a frame, to avoid progress bar stopping prematurely because of the cargo menu still being open
[EFUNC(common,progressBar), [
_duration,
[_item, GVAR(interactionVehicle)],
{
[QGVAR(paradropItem), _this select 0] call CBA_fnc_localEvent;
},
{
params ["", "", "", "_errorCode"];
if (_errorCode == 3) then { // show warning if we failed because of flight conditions
[LSTRING(unlevelFlightWarning)] call EFUNC(common,displayTextStructured);
};
},
format [LLSTRING(unloadingItem), [_item, true] call FUNC(getNameItem), getText (configOf GVAR(interactionVehicle) >> "displayName")],
{
(_this select 0) params ["", "_target"];
if ((acos ((vectorUp _target) select 2)) > 30) exitWith {false}; // check flight level
if (((getPos _target) select 2) < 25) exitWith {false}; // check height
if ((speed _target) < -5) exitWith {false}; // check reverse
true
},
["isNotSwimming", "isNotInside"],
false
]] call CBA_fnc_execNextFrame;
};
// If in zeus
if (!isNull findDisplay 312) exitWith {
// Do not check distance to unit, but do check for valid position
if !([_item, GVAR(interactionVehicle), objNull, true] call FUNC(canUnloadItem)) exitWith {
[[LSTRING(unloadingFailed), [_item, true] call FUNC(getNameItem)], 3] call EFUNC(common,displayTextStructured);
};
// Close the cargo menu
closeDialog 1;
["ace_unloadCargo", [_item, GVAR(interactionVehicle)]] call CBA_fnc_localEvent;
};
// Start progress bar - normal ground unload
if ([_item, GVAR(interactionVehicle), _unit] call FUNC(canUnloadItem)) then {
// Close the cargo menu
closeDialog 0;
private _duration = GVAR(loadTimeCoefficient) * (_item call FUNC(getSizeItem));
// If unload time is 0, don't show a progress bar
if (_duration <= 0) exitWith {
["ace_unloadCargo", [_item, GVAR(interactionVehicle), _unit]] call CBA_fnc_localEvent;
};
[
_duration,
[_item, GVAR(interactionVehicle), _unit],
{
TRACE_1("unload finish",_this);
["ace_unloadCargo", _this select 0] call CBA_fnc_localEvent;
},
{
TRACE_1("unload fail",_this);
},
format [LLSTRING(unloadingItem), [_item, true] call FUNC(getNameItem), getText (configOf GVAR(interactionVehicle) >> "displayName")],
{
(_this select 0) params ["_item", "_vehicle", "_unit"];
[_item, _vehicle, _unit, false, true] call FUNC(canUnloadItem) // don't check for a suitable unloading position every frame
},
["isNotSwimming"]
] call EFUNC(common,progressBar);
} else {
[[LSTRING(unloadingFailed), [_item, true] call FUNC(getNameItem)], 3] call EFUNC(common,displayTextStructured);
};