-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathinitPlayerLocal.sqf
More file actions
419 lines (343 loc) · 16.5 KB
/
Copy pathinitPlayerLocal.sqf
File metadata and controls
419 lines (343 loc) · 16.5 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
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
/*
* FLO Player Local Initialization Script
* Author: Frontline Operations Development Group
* Description: Client-side initialization
*/
params ["_player", "_didJIP"];
// Only execute on clients with interface
if (!hasInterface) exitWith {};
// ============================================================================
// INITIAL SETUP AND LOADING SCREEN
// ============================================================================
// Initialize loading screen with fade effect
titleText ["Frontline Operations Group Presents...", "BLACK IN", 9999];
// 5 fadeSound 0; I spy with my little eye... what do we have here, sound fix?
sleep 1;
// Initialize mission state
StartingLocationDone = false;
FLO_GTN_ShowSupplyMarkers = true;
FLO_GTN_CommanderSupplyToggleActionId = -1;
FLO_GTN_CommanderSupplyToggleActionOwner = objNull;
FLO_GTN_LastCommanderIntelSyncArgs = [];
FLO_GTN_CommanderSupplyRespawnHandlerAdded = false;
FLO_GTN_PlayerSupportActionIds = [];
FLO_GTN_PlayerSupportActionOwner = objNull;
FLO_GTN_PlayerSupportMapClickEhId = -1;
FLO_GTN_PlayerSupportPendingType = "";
FLO_GTN_PlayerSupportCancelWatcherRunning = false;
FLO_ClientFinalizeDone = false;
[] call FLO_fnc_initMissionConfigEvents;
[] call FLO_fnc_initMoneyStateEvents;
[] spawn {
waitUntil {
sleep 1;
!isNull player
&& {player == player}
&& {!isNil "FLO_MissionReady"}
&& {FLO_MissionReady}
};
if (!FLO_ClientFinalizeDone) then {
["INIT_CLIENT", 3, "Mission-ready watchdog firing local client finalize"] call FLO_fnc_log;
["FLO_INIT_COMPLETE", []] call FLO_fnc_initClientFinalize;
};
};
// ============================================================================
// MISSION LOADING SEQUENCE
// ============================================================================
// Wait for mission to be fully loaded with timeout protection
private _loadTimeout = time + 300; // 5 minute timeout
waitUntil {
sleep 0.1;
!isNil "MissionLoadedLitterally" && {MissionLoadedLitterally} || {time > _loadTimeout}
};
if (time > _loadTimeout) then {
["INIT_CLIENT", 1, "Mission loading timeout reached"] call FLO_fnc_log;
};
// ============================================================================
// SAVE GAME DETECTION - Wait for server's Phase 0 detection
// ============================================================================
// Wait for server to complete Phase 0 (save detection) with timeout
private _fnc_waitForSaveDetection = {
private _startTime = diag_tickTime;
private _timeout = 30; // 30 second timeout for save detection
["INIT_CLIENT", 3, "Waiting for server save detection..."] call FLO_fnc_log;
// Wait for the server to broadcast FLO_IsLoadedSave (happens in Phase 0)
// We MUST wait for Phase 1 or later - that's when we know Phase 0 is COMPLETE
// and all publicVariables from Phase 0 have been sent
waitUntil {
sleep 0.3;
private _serverPastPhase0 = !isNil "FLO_InitPhase" && {FLO_InitPhase >= 1};
private _timedOut = (diag_tickTime - _startTime) > _timeout;
_serverPastPhase0 || _timedOut
};
// Wait for network sync - publicVariable can take a moment to arrive
// This is critical on dedicated servers where network latency matters
sleep 1.0;
// Additional wait to ensure FLO_IsLoadedSave has synced
private _syncStart = diag_tickTime;
waitUntil {
sleep 0.1;
!isNil "FLO_IsLoadedSave" || (diag_tickTime - _syncStart) > 5
};
// Check if this is a saved game from server's detection
private _isSavedGame = !isNil "FLO_IsLoadedSave" && {FLO_IsLoadedSave};
["INIT_CLIENT", 3, format ["Save detection result: FLO_IsLoadedSave=%1, isSavedGame=%2", FLO_IsLoadedSave, _isSavedGame]] call FLO_fnc_log;
if (_isSavedGame) then {
["INIT_CLIENT", 3, "Server detected saved game - skipping faction dialog"] call FLO_fnc_log;
StartingLocationDone = true;
} else {
["INIT_CLIENT", 3, "Server detected fresh start"] call FLO_fnc_log;
};
_isSavedGame
};
private _isSavedGame = call _fnc_waitForSaveDetection;
// ============================================================================
// FRESH START INITIALIZATION
// ============================================================================
if (!_isSavedGame && !StartingLocationDone) then {
// Commander validation
private _fnc_validateCommander = {
if (isNil "TheCommander") then {
private _message = "Commander must be assigned to a player at fresh start.\nHave someone return to Lobby and pick Commander.";
titleText [_message, "BLACK IN", 9999];
// Wait for commander assignment with periodic updates
private _startTime = time;
waitUntil {
sleep 1;
if (time - _startTime > 30) then {
_startTime = time;
["INIT_CLIENT", 2, "Still waiting for commander assignment..."] call FLO_fnc_log;
};
!isNil "TheCommander"
};
["INIT_CLIENT", 3, format ["Commander assigned: %1", name TheCommander]] call FLO_fnc_log;
};
};
call _fnc_validateCommander;
// Check if this is a loaded save - if so, skip the faction dialog
// Wait briefly for server to set FLO_IsLoadedSave
private _saveCheckStart = diag_tickTime;
waitUntil { sleep 0.2; !isNil "FLO_IsLoadedSave" || (diag_tickTime - _saveCheckStart > 5) };
private _isLoadedSave = !isNil "FLO_IsLoadedSave" && {FLO_IsLoadedSave};
if (_isLoadedSave) then {
["INIT_CLIENT", 3, "Loading from saved game - skipping faction selection dialog"] call FLO_fnc_log;
StartingLocationDone = true;
} else {
private _shouldOpenFactionDialog = [] call FLO_fnc_shouldOpenFactionDialog;
if (!_shouldOpenFactionDialog) then {
["INIT_CLIENT", 3, "Mission setup already in progress or complete - skipping faction selection dialog"] call FLO_fnc_log;
StartingLocationDone = true;
};
// Launch faction selection for commander (fresh start only)
if (_shouldOpenFactionDialog) then {
if (_player isEqualTo TheCommander) then {
["INIT_CLIENT", 3, "Launching faction selection dialog for commander"] call FLO_fnc_log;
execVM "Scripts\MissionSetupMenu\Dialog_Faction.sqf";
} else {
["INIT_CLIENT", 3, format ["Player %1 waiting for commander faction selection", name _player]] call FLO_fnc_log;
};
};
};
};
// ============================================================================
// WAIT FOR SERVER PHASE MANAGER
// ============================================================================
// Disable saving during initialization
enableSaving [false, false];
// Wait for server Phase Manager to complete all initialization
// This replaces the old fragmented approach (init_groups, init_Markers, etc.)
private _fnc_waitForPhaseManager = {
private _startTime = diag_tickTime;
private _timeout = 600; // 10 minute timeout
waitUntil {
sleep 1;
// Show progress to player based on current phase
if (!isNil "FLO_InitPhase") then {
private _phaseName = switch (FLO_InitPhase) do {
case 0: { "Waiting for configuration..." };
case 1: { "Loading factions..." };
case 2: { "Configuring factions..." };
case 3: { "Indexing objectives..." };
case 4: { "Setting up OPFOR forces..." };
case 5: { "Starting mission systems..." };
case 99: { "Ready!" };
case -1: { "ERROR" };
default { "Initializing..." };
};
hintSilent format ["Mission Setup: %1", _phaseName];
} else {
hintSilent "Waiting for server...";
};
// Check for completion or error
private _ready = !isNil "FLO_MissionReady" && {FLO_MissionReady};
private _error = !isNil "FLO_InitPhase" && {FLO_InitPhase == -1};
private _timedOut = (diag_tickTime - _startTime) > _timeout;
_ready || _error || _timedOut
};
// Handle result
if (!isNil "FLO_MissionReady" && {FLO_MissionReady}) then {
["INIT_CLIENT", 3, "Phase Manager completed - mission ready"] call FLO_fnc_log;
true
} else {
if (!isNil "FLO_InitPhase" && {FLO_InitPhase == -1}) then {
private _error = if (!isNil "FLO_InitError") then { FLO_InitError } else { "Unknown error" };
["INIT_CLIENT", 1, format ["Phase Manager failed: %1", _error]] call FLO_fnc_log;
} else {
["INIT_CLIENT", 1, "Phase Manager timeout"] call FLO_fnc_log;
};
false
}
};
private _phaseSuccess = call _fnc_waitForPhaseManager;
// ============================================================================
// USER INTERFACE SETUP
// ============================================================================
// Mrker interaction system
private _fnc_initMarkerInteraction = {
// Wait for main display to be available using spawn
[] spawn {
waitUntil {sleep 0.1; !isNull findDisplay 46};
private _mouseHandler = (findDisplay 46) displayAddEventHandler ["MouseButtonDown", {
params ["_displayOrControl", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];
// Check for Ctrl+Right-click on map markers
if (_ctrl && {_button isEqualTo 1}) then {
try {
private _mapDisplay = findDisplay 12;
if (!isNull _mapDisplay) then {
private _mapCtrl = _mapDisplay displayCtrl 51;
private _mouseOver = ctrlMapMouseOver _mapCtrl;
if ((_mouseOver select 0) isEqualTo "marker") then {
private _markerName = _mouseOver select 1;
[_markerName] execVM "Scripts\MarkerIntro.sqf";
};
};
} catch {
["UI", 1, format ["Error in marker interaction: %1", _exception]] call FLO_fnc_log;
};
};
false
}];
["UI", 3, "Marker interaction system initialized"] call FLO_fnc_log;
};
};
call _fnc_initMarkerInteraction;
// ============================================================================
// OPTIONAL EQUIPMENT SETUP
// ============================================================================
// cTab integration (if available)
private _fnc_initCTab = {
if (isClass (configFile >> "CfgVehicles" >> "Box_cTab_items")) then {
try {
player addItem "ItemAndroid";
player addItem "ItemcTab";
["EQUIPMENT", 3, "cTab equipment added to player"] call FLO_fnc_log;
} catch {
["EQUIPMENT", 1, format ["Failed to add cTab equipment: %1", _exception]] call FLO_fnc_log;
};
} else {
["EQUIPMENT", 5, "cTab not available - skipping equipment"] call FLO_fnc_log;
};
};
call _fnc_initCTab;
// ============================================================================
// MISSION READINESS CHECK
// ============================================================================
// Note: We already waited for Phase Manager above, but do a final sanity check
if (!_phaseSuccess) then {
["INIT_CLIENT", 1, "Mission initialization failed - some features may not work correctly"] call FLO_fnc_log;
hint "Warning: Mission initialization encountered errors.\nSome features may not work correctly.";
} else {
["INIT_CLIENT", 3, "Mission readiness confirmed"] call FLO_fnc_log;
};
// ============================================================================
// CLIENT FEATURE INITIALIZATION
// ============================================================================
// Initialize client features based on mission parameters
private _fnc_initClientFeatures = {
private _features = [
["RestrictedArsenal", "FLO_fnc_restrictedArsenal", "Restricted Arsenal"],
["RagequitBlocker", "FLO_fnc_ragequitBlocker", "Ragequit Blocker"],
["DisableSystemChat", "FLO_fnc_disableSystemChat", "System Chat Disabler"]
];
{
_x params ["_paramName", "_functionName", "_displayName"];
try {
private _paramValue = _paramName call BIS_fnc_getParamValue;
if (_paramValue isEqualTo 0) then {
[] call (missionNamespace getVariable [_functionName, {}]);
["CLIENT_FEATURES", 3, format ["%1 initialized", _displayName]] call FLO_fnc_log;
} else {
["CLIENT_FEATURES", 5, format ["%1 disabled by mission parameter", _displayName]] call FLO_fnc_log;
};
} catch {
["CLIENT_FEATURES", 1, format ["Failed to initialize %1: %2", _displayName, _exception]] call FLO_fnc_log;
};
sleep 0.1; // Small delay between feature initializations
} forEach _features;
};
call _fnc_initClientFeatures;
// ============================================================================
// VEHICLE SCRAPYARD ACTION
// ============================================================================
FLO_fnc_addHoldAction_Client = {
params ["_veh"];
[
_veh, // Target
"Scrap Vehicle", // Title
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_unloadDevice_ca.paa", // Idle Icon
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_unloadDevice_ca.paa", // Progress Icon
"alive _target && _this distance _target < 15 && count (crew _target) == 0 && {(nearestObjects [_target, ['Land_Cargo_HQ_V1_F', 'Land_Cargo_HQ_V2_F', 'Land_Cargo_HQ_V3_F'], 100]) isNotEqualTo []}", // Condition Show: Near FOB (100m)
"true", // Condition Progress
{}, // Code Start
{}, // Code Progress
{
params ["_target", "_caller", "_actionId", "_arguments"];
[_target, "open_menu"] call FLO_fnc_vehicleMarket;
}, // Code Completed
{}, // Code Interrupted
[], // Arguments
1, // Duration
10, // Priority
false, // Remove Completed
false // Show Unconscious
] call BIS_fnc_holdActionAdd;
_veh setVariable ["FLO_ScrapActionAdded_Hold", true];
// systemChat format ["DEBUG: Hold Action Init: %1", typeOf _veh];
};
// Register for classes using the Global Function
["LandVehicle", "init", { params ["_veh"]; [_veh] call FLO_fnc_addHoldAction_Client }, true, [], true] call CBA_fnc_addClassEventHandler;
["Air", "init", { params ["_veh"]; [_veh] call FLO_fnc_addHoldAction_Client }, true, [], true] call CBA_fnc_addClassEventHandler;
["Ship", "init", { params ["_veh"]; [_veh] call FLO_fnc_addHoldAction_Client }, true, [], true] call CBA_fnc_addClassEventHandler;
// ============================================================================
// FINAL CLIENT INITIALIZATION
// ============================================================================
// Execute final client initialization scripts
private _fnc_finalizeInit = {
try {
["INIT_CLIENT", 3, "Starting final client initialization"] call FLO_fnc_log;
// Execute triggers initialization
Triggers0 = execVM "Scripts\Init\init_Triggers.sqf";
waitUntil {sleep 0.5; scriptDone Triggers0};
["INIT_CLIENT", 3, "Client initialization completed successfully"] call FLO_fnc_log;
// Final loading message
hintSilent "LOADED!";
// Brief delay before clearing hint using spawn
[] spawn {
sleep 3;
hintSilent "";
};
// Initialize Notifications Module
[] call IDS_Notifications_fnc_initNotificationClass;
[] spawn {
waitUntil { !isNil "IDS_NotificationClass" };
IDS_NotificationClass call ["init", []];
};
// Initialize Capture Balance UI (updates pushed from server)
["init"] call FLO_fnc_captureUI;
["INIT_CLIENT", 3, "Capture UI initialized"] call FLO_fnc_log;
} catch {
["INIT_CLIENT", 1, format ["Error in final initialization: %1", _exception]] call FLO_fnc_log;
hintSilent "LOADED WITH ERRORS!";
};
};
call _fnc_finalizeInit;