-
Notifications
You must be signed in to change notification settings - Fork 185
/
pp_saving_functions.sqf
313 lines (235 loc) · 10.5 KB
/
pp_saving_functions.sqf
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
if (!isNil "parking_saving_functions_defined") exitWith {};
diag_log format["Loading parking saving functions ..."];
#include "macro.h"
if (isServer) then {
pp_notify = {
//diag_log format["%1 call pp_notify", _this];
ARGVX3(0,_player,objNull);
ARGVX3(1,_msg,"");
ARGV3(2,_dialog,"");
pp_notify_request = [_msg,OR(_dialog,nil)];
(owner _player) publicVariableClient "pp_notify_request";
};
pp_mark_vehicle = {
//diag_log format["%1 call pp_create_mark_vehicle", _this];
ARGVX3(0,_player,objNull);
ARGVX3(1,_vehicle,objNull);
pp_mark_vehicle_request = [_vehicle];
(owner _player) publicVariableClient "pp_mark_vehicle_request";
};
pp_is_safe_position = {
ARGVX3(0,_player,objNull);
ARGVX3(1,_class,"");
ARGVX3(2,_position,[]);
def(_classes);
_classes = ["Helicopter", "Plane", "Ship_F", "Car", "Motorcycle", "Tank"];
def(_size);
_size = sizeof _class;
((_position distance _player) < 50 && {
(count(nearestObjects [_position, _classes , _size]) == 0)})
};
if (call A3W_savingMethod == "extDB") then
{
v_addSaveVehicle =
{
params ["_parked_vehicles", "_vehicle"];
private _vehID = [_vehicle, 0, true] call fn_saveVehicle;
private _vehProps = _vehicle getVariable "A3W_parkedProperties";
if (isNil "_vehProps") exitWith {nil};
_vehicle setVariable ["A3W_parkedProperties", nil];
if (isNil "_vehID") exitWith {nil};
[_parked_vehicles, _vehID, _vehProps] call fn_setToPairs;
true
};
v_restoreVehicle =
{
params ["_data_pair", ["_ignore_expiration",false,[false]], ["_create_array",[],[[]]]];
_data_pair params ["_vehicleID", "_vehData"];
private _pos = _create_array select 1;
private _safeDistance = _create_array select 3;
[_vehData, "Position", _pos] call fn_setToPairs;
[_vehData, "Direction"] call fn_removeFromPairs;
[_vehData, "Velocity"] call fn_removeFromPairs;
private _varNames = call fn_getVehicleVars;
private _varVals = [_vehData, _varNames] call fn_preprocessSavedData;
private ["_veh", "_hoursAlive", "_hoursUnused"];
//private (_varVals apply {_x select 0});
//{ (_x select 1) call compile format ["%1 = _this", _x select 0] } forEach _varVals;
[] params _varVals; // automagic assignation
private _lockState = [1,2] select (["A3W_vehicleLocking"] call isConfigOn && round getNumber (configFile >> "CfgVehicles" >> _class >> "isUav") < 1);
// delete wrecks near spawn
{
if (!alive _x) then
{
deleteVehicle _x;
};
} forEach nearestObjects [_markerPos, ["LandVehicle","Air","Ship"], 25 max sizeOf _class];
call fn_restoreSavedVehicle;
_veh call fn_manualVehicleSave;
_veh
};
};
pp_park_vehicle_request_handler = {
ARGVX3(1,_this,[]);
ARGVX3(0,_player,objNull);
ARGVX3(1,_vehicle,objNull);
if (not(alive _vehicle)) exitWith {};
def(_uid);
_uid = getPlayerUID _player;
private _vehOwner = _vehicle getVariable ["ownerUID",""];
if !(_vehOwner in ["",_uid]) exitWith {
[_player, format ["Someone else has the ownership of the %1, you cannot park it.", ([typeOf _vehicle] call generic_display_name)], "Parking Error"] call pp_notify;
};
diag_log format["Parking vehicle %1(%2) for player %3(%4)", typeOf _vehicle, netId _vehicle, (name _player), _uid];
def(_parked_vehicles);
_parked_vehicles = _player getVariable "parked_vehicles";
_parked_vehicles = OR(_parked_vehicles,[]);
if (_vehOwner isEqualTo "") then {
_vehicle setVariable ["ownerUID", _uid];
};
private _saveFlag = (_vehicle getVariable ["A3W_purchasedVehicle", false] || _vehicle getVariable ["A3W_missionVehicle", false]);
if !(_saveFlag) then {
_vehicle setVariable ["A3W_purchasedVehicle", true];
};
[_this, _player, _vehicle, _uid, _vehOwner, _parked_vehicles, _saveFlag] spawn
{
params ["_this", "_player", "_vehicle", "_uid", "_vehOwner", "_parked_vehicles", "_saveFlag"];
def(_added);
_added = [_parked_vehicles, _vehicle, false] call v_addSaveVehicle;
if (isNil "_added") exitWith {
if (_vehOwner isEqualTo "") then {
_vehicle setVariable ["ownerUID", nil];
};
if !(_saveFlag) then {
_vehicle setVariable ["A3W_purchasedVehicle", nil];
};
diag_log format["ERROR: Could not park vehicle %1(%2) for player %3(%4)", typeOf _vehicle, netId _vehicle, (name _player), _uid];
[_player, format["An unknown error happened while trying to park the %1", ([typeOf _vehicle] call generic_display_name)], "Parking Error"] call pp_notify;
};
def(_display_name);
_display_name = [typeOf _vehicle] call generic_display_name;
private _attachedObjs = attachedObjects _vehicle;
if (!isNil "fn_untrackSavedVehicle") then { _vehicle call fn_untrackSavedVehicle };
deleteVehicle _vehicle;
{ ["detach", _x] call A3W_fnc_towingHelper } forEach _attachedObjs;
_player setVariable ["parked_vehicles", _parked_vehicles]; //, true];
["parked_vehicles", _parked_vehicles] remoteExecCall ["A3W_fnc_setVarPlayer", _player];
//[_player] call fn_saveAccount;
[_player, format["%1, your %2 has been parked.", (name _player), _display_name]] call pp_notify;
};
};
pp_retrieve_vehicle_request_handler = {
ARGVX3(1,_this,[]);
ARGVX3(0,_player,objNull);
ARGVX3(1,_vehicle_id, "");
def(_uid);
_uid = getPlayerUID _player;
diag_log format["Retrieving parked vehicle %1 for player %2(%3)", _vehicle_id, (name _player), _uid];
def(_parked_vehicles);
_parked_vehicles = _player getVariable "parked_vehicles";
_parked_vehicles = OR(_parked_vehicles,[]);
def(_vehicle_data);
_vehicle_data = [_parked_vehicles, _vehicle_id] call fn_getFromPairs;
if (!isARRAY(_vehicle_data)) exitWith {
diag_log format["ERROR: Could not retrieve vehicle %1 for player %2(%3)", _vehicle_id, (name _player), _uid];
[_player, format["An error occurred, your vehicle (%2) could not be retrieved. Please report this error to A3Armory.com.", _vehicle_id], "Retrieval Error"] call pp_notify;
};
//def(_position);
//_position = [_vehicle_data, "Position"] call fn_getFromPairs;
//def(_class);
_class = [_vehicle_data, "Class"] call fn_getFromPairs;
private ["_marker", "_markerPos", "_dirAngle", "_pos", "_posAGL"];
private _nearbySpawns = allMapMarkers select {_x select [0,7] == "Parking" && {_x select [count _x - 6, 6] == "_spawn" && _player distance markerPos _x < 100}};
if !(_nearbySpawns isEqualTo []) then
{
_marker = _nearbySpawns select 0;
_markerPos = markerPos _marker;
_dirAngle = markerDir _marker;
if (surfaceIsWater _markerPos) then
{
_markerPos set [2, (getPosASL _player) select 2];
_posAGL = ASLtoAGL _markerPos;
_pos = if (round getNumber (configFile >> "CfgVehicles" >> _class >> "canFloat") > 0) then { _posAGL } else { ASLtoATL _markerPos };
}
else
{
_pos = _markerPos;
_posAGL = _pos;
};
_pos set [2, (_pos select 2) + 0.1];
};
def(_create_array);
//if (not([_player,_class,_position] call pp_is_safe_position)) then {
//we don't have an exact safe position, let the game figure one out
_create_array = [_class, if (isNil "_pos") then { getPos _player } else { _pos }, [], [0,50] select (isNil "_pos"), ""];
//};
def(_vehicle);
_vehicle = [[_vehicle_id, _vehicle_data], true,OR(_create_array,nil)] call v_restoreVehicle;
if (isNil "_vehicle") exitWith {
diag_log format["ERROR: Could not restore vehicle %1 for player %2(%3)", _vehicle_id, (name _player), _uid];
[_player, format["An error occurred, your vehicle (%1) could not be restored. Please report this error to A3Armory.com.", _vehicle_id], "Restoring Error"] call pp_notify;
};
[_parked_vehicles, _vehicle_id] call fn_removeFromPairs;
_player setVariable ["parked_vehicles", _parked_vehicles]; //, true];
["parked_vehicles", _parked_vehicles] remoteExecCall ["A3W_fnc_setVarPlayer", _player];
//[_player] call fn_saveAccount;
def(_display_name);
_display_name = [typeOf _vehicle] call generic_display_name;
[_player, _vehicle] call pp_mark_vehicle;
[_player, format["%1, your %2 has been retrieved (marked on map)", (name _player), _display_name]] call pp_notify;
};
"pp_park_vehicle_request" addPublicVariableEventHandler pp_park_vehicle_request_handler;
"pp_retrieve_vehicle_request" addPublicVariableEventHandler pp_retrieve_vehicle_request_handler;
};
if (isClient) then {
pp_notify_request_handler = {_this spawn {
//diag_log format["%1 call pp_notify_request_handler", _this];
ARGVX3(1,_this,[]);
ARGVX3(0,_msg,"");
ARGV3(1,_dialog,"");
if (isSTRING(_dialog)) exitWith {
[_msg, _dialog, "OK", false] call BIS_fnc_guiMessage;
};
player groupChat _msg;
};};
"pp_notify_request" addPublicVariableEventHandler {_this call pp_notify_request_handler};
pp_mark_vehicle_request_handler = {_this spawn {
//diag_log format["%1 call pp_mark_vehicle_request_handler", _this];
ARGVX3(1,_this,[]);
ARGVX3(0,_vehicle,objNull);
sleep 1; //give enough time for the vehicle to be move to the correct location (before marking)
def(_class);
_class = typeOf _vehicle;
def(_name);
_name = [_class] call generic_display_name;
def(_pos);
_pos = getPos _vehicle;
def(_marker);
_marker = format["pp_vehicle_marker_%1", ceil(random 1000)];
_marker = createMarkerLocal [_marker, _pos];
_marker setMarkerTypeLocal "waypoint";
_marker setMarkerPosLocal _pos;
_marker setMarkerColorLocal "ColorBlue";
//_marker setMarkerTextLocal _name;
_vehicle setVariable ["was_parked", true];
if (!alive getConnectedUAV player) then {
player connectTerminalToUAV _vehicle; // attempt uav connect
};
[_marker] spawn {
ARGVX3(0,_marker,"");
sleep 60;
deleteMarkerLocal _marker;
};
};};
"pp_mark_vehicle_request" addPublicVariableEventHandler {_this call pp_mark_vehicle_request_handler};
pp_park_vehicle = {
pp_park_vehicle_request = _this;
publicVariableServer "pp_park_vehicle_request";
};
pp_retrieve_vehicle = {
pp_retrieve_vehicle_request = _this;
publicVariableServer "pp_retrieve_vehicle_request";
};
};
diag_log format["Loading parking saving functions complete"];
parking_saving_functions_defined = true;