-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
436 lines (322 loc) · 11.6 KB
/
client.js
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/** Imports of natives and of the incredible functions of ALTV */
import * as alt from 'alt';
import * as native from 'natives';
/**
* List of variables :
*
* vehicle : ScriptID of the vehicle that is actually being customised in menu
* menuouvert : Is menuopen used for on.keydown to avoid opening it while open
* portesouvertes : Are vehicle's doors open ? used for doors bonus button
* enginestate : Is vehicle's engine on ? used for engine bonus button
* interval : No Mouse & Debugging Interval ( Only active when in menu )
* wtype : For Debugging ( #2 )
* wtype : For Debugging ( #2 )
* roof : For Debugging ( #4 )
* actualextra : For Debugging ( #5 )
*
*/
let vehicle = false;
let menuouvert = false;
let portesouvertes = false;
let enginestate = true;
let interval;
let wtype;
let wnum;
let roof;
let actualextra = [];
/**
* Listing zone from where menu can be open
*
* x, y and z are coordinates
* dist is the size of the zone in which you can open the menu
* name is the name of the blip
*/
let MechanicPosList = [
{ x : -146.6, y : -596.6, z : 166.0, dist : 6.0, name : 'Mechanic' }, // Arcadius
{ x : -337.38, y : -136.92, z : 38.57, dist : 6.0, name : 'Mechanic' }, // burton
{ x : -1155.53, y : -2007.18, z : 12.74, dist : 6.0, name : 'Mechanic' }, // airport
{ x : 731.81, y : -1088.82, z : 21.73, dist : 6.0, name : 'Mechanic' }, // la mesa
{ x : 1175.04, y : 2640.21, z : 37.32, dist : 6.0, name : 'Mechanic' }, // harmony desert
{ x : 110.99, y : 6626.39, z : 30.89, dist : 6.0, name : 'Mechanic' }, // paleto bay
]
/**
* Blip Generator
*
* Srite is the logo on map
* ShortRange is how it is seen on map / radar
* 1 mean it will be seen on map and on radar if nearby enough but not pined
*/
MechanicPosList.forEach(b => {
const blip = new alt.PointBlip(b.x, b.y, b.z);
blip.sprite = 72;
blip.color = 28;
blip.scale = 1.0;
blip.shortRange = 1;
blip.name = b.name;
});
/**
* Creation of the WebView Item
*/
let hud = new alt.WebView('http://resource/menu/index.html');
/**
* On WebView : Choice of Colors :
* Choice of Primary Color
* Choice of Secondary Color
* Choice of Interior / Third Color
* Choice of Pearlescent Color
* Choice of Wheel Color
*/
hud.on('ColorHandler', (type, couleur) => {
alt.emitServer('seln:mecha:color', type, couleur);
});
/**
* On WebView : Stickers
* On WebView : Liveries ( Emergency Vehicles Stickers )
* On WebView : Roof Liveries
*/
hud.on('StickerHandler', (sticker) => { alt.emitServer('seln:mecha:setmod', 48, sticker); });
hud.on('LiveryHandler', (livery) => { native.setVehicleLivery(vehicle, livery); });
hud.on('RoofHandler', (livery) => {
roof = livery;
native.setVehicleRoofLivery(vehicle, livery);
});
/**
* On WebView : Choice of which sides are ON or OFF
* On WebView : Choice of Neons Color
*/
hud.on('NeonHandler', (hex) => { alt.emitServer('seln:mecha:neon', hex); });
hud.on('NeonONOFFHandler', (neon) => { alt.emitServer('seln:mecha:neononoff', neon); });
/**
* On WebView : Choice of Headlights Xenon Color
*/
hud.on('Xenon', (couleur) => {
alt.emitServer('seln:mecha:setxenon', couleur);
});
/**
* On WebView : Setting chosen mod at chosen number
* On WebView : Switching chosen mod between TRUE/FALSE ( may not be used )
*/
hud.on('SwitchMod', (mod) => { alt.emitServer('seln:mecha:switchmod', mod); });
hud.on('SetMod', (mod, num) => { alt.emitServer('seln:mecha:setmod', mod, num); });
/**
* On WebView : Choice of Plate Format
*/
hud.on('PlateChanger', (plate) => { alt.emitServer('seln:mecha:platechanger', plate); });
/**
* On WebView : Choice of Wheels Category :
* Set the wheels on the first wheels of the category so the category change it is effective
* ( Set the frontwheels and backwheels cause bikes and some vehicles have backwheels )
* Saving the wheels category in 'wtype' for the debugging interval
* Sending the maximum of wheels for this category to the WebView
*/
hud.on('SetWheelsCat', (cat) => {
alt.log(cat);
native.setVehicleWheelType(vehicle, cat);
native.setVehicleMod(vehicle, 23, 0);
native.setVehicleMod(vehicle, 24, 0);
wtype = native.getVehicleWheelType(vehicle);
hud.emit('senddata', 'slidermax', native.getNumVehicleMods(vehicle, 23))
});
/**
* On WebView : Choice of Wheels :
* Set the wheels on asked number
* ( Set the frontwheels and backwheels cause bikes and some vehicles have backwheels )
* Saving the wheels category in 'wtype' for the debugging interval
* Saving the wheels number in 'wnum' for the debugging interval
*/
hud.on('SetWheels', (num) => {
native.setVehicleMod(vehicle, 23, num);
native.setVehicleMod(vehicle, 24, num);
wtype = native.getVehicleWheelType(vehicle);
wnum = native.getVehicleMod(vehicle, 23);
});
/**
* On WebView : Switching Extras
* Get the actual status of the extra and switch it
* Saving the chosen extra status in 'actualextra' for the debugging interval
*/
hud.on('Extras', (extra) => {
let actual = native.isVehicleExtraTurnedOn(alt.Player.local.vehicle.scriptID, extra);
if (actual) { native.setVehicleExtra(alt.Player.local.vehicle.scriptID, extra, 1); }
else { native.setVehicleExtra(alt.Player.local.vehicle.scriptID, extra, 0); }
actualextra[extra].ison = !actual
});
/**
* On WebView : Bonus opening / closing doors
*/
hud.on('BonusPortes', () => {
if (portesouvertes) { native.setVehicleDoorsShut(vehicle, false); }
else {
for (let i = 0; i < 10; i++) {
try { native.setVehicleDoorOpen(vehicle, i, false, false); } catch(error) {}
}
}
portesouvertes = !portesouvertes
});
/**
* On WebView : Bonus repair vehicle
*/
hud.on('BonusRepair', () => { native.setVehicleFixed(vehicle); });
/**
* On WebView : Bonus clean vehicle
*/
hud.on('BonusClean', () => { native.setVehicleDirtLevel(vehicle, 0); });
/**
* On WebView : Bonus engine OFF / ON
*/
hud.on('BonusMoteur', () => {
enginestate = !enginestate
native.setVehicleEngineOn(vehicle, enginestate, false, true);
});
/**
* On WebView : Vision Changes
*/
hud.on('POVHandler', (pov, pov2) => {
try {
native.setGameplayCamRelativeHeading(pov);
native.setGameplayCamRelativePitch(pov2, 1.00);
} catch (error) {}
});
/**
* On WebView : Ask for list of stickers with names
* If the vehicle have stickers list them with their names
* Send the list of names to the WebView
*/
hud.on('AskStickers', (count) => {
if(count > 0 ) {
let tempstickers = {}
for (let i = 0; i < count; i++) {
let temp = native.getLabelText(native.getModTextLabel( alt.Player.local.vehicle.scriptID, 48, i));
tempstickers[i+1] = { i: i+1, name: temp}
}
hud.emit('senddata', 'stickers', tempstickers)
}
});
/**
* On WebView : Ask list of vehicles extras
* Look up if extra 0 to 20 exist for this vehicle
* Saving every extras statut in 'actualextra' for the debugging interval
* Send to the WebView the existing extras
* Send to the WebView if their is at least one extras or not
*/
hud.on('AskExtras', () => {
let noextra = true;
let temp = []
for (let i = 0; i < 20; i++) {
if ( native.doesExtraExist(alt.Player.local.vehicle.scriptID, i) )
{
temp[i] = { id: i , state : true }
noextra = false
}
else { temp[i] = { id: i , state : false } }
}
temp.forEach(extra => {
if (extra.state) {
let ison = native.isVehicleExtraTurnedOn(alt.Player.local.vehicle.scriptID, extra.id)
actualextra[extra.id] = { id: extra.id, ison: ison };
}
});
alt.log(noextra);
hud.emit('senddata', 'extras', temp)
hud.emit('senddata', 'noextra', noextra)
});
/**
* On WebView & Client : Close Menu
* Close the WebView
* Stopping the no mouse and bug deleter interval
* Ask the WebView to set variables to their default values
*/
hud.on('Close', () => { Close() });
function Close() {
menuouvert = false;
native.freezeEntityPosition(vehicle, false);
hud.unfocus();
alt.showCursor(false);
native.displayRadar(true);
alt.clearInterval(interval);
vehicle = false;
hud.emit('close')
}
/**
* On Server : Receive data and open menu
*/
alt.onServer('seln:mecha:getmodscountanswer', (type, nblivery, nbroofs, modscount, currentmods) => {
hud.emit('ouvrir', type, modscount, currentmods, nblivery, nbroofs)
});
/**
* On : KeyDown
*
* [SPACE] key : If player in a vehicle and the menu is closed :
* Get position and check if the player is in one of the mechanic zones
* If in a mechanic zone, open the menu
*
* [F] key : If the menu is open then close it :
* This one is to avoid problems if the player leave the vehicle while in menu
*/
alt.on('keydown', (key) => {
// [SPACE]
if ( key == 32 && alt.Player.local.vehicle && menuouvert == false ) {
let pos = native.getEntityCoords(alt.Player.local.scriptID, true);
MechanicPosList.forEach(mech => {
if( native.getDistanceBetweenCoords(mech.x, mech.y, mech.z, pos.x, pos.y, pos.z, true) < mech.dist )
{ openMenu('menu') }
});
}
// [F]
if ( key == 70 && menuouvert == true ) { Close() }
});
/**
* Menu Opener :
* Preparing the needed data to open the menu
* Starting the no mouse and bug deleter interval
* Asking server for other needed data
*
* Needed data from client :
* Saving the wheel category
* Saving the wheel number
* Get Number of liveries
* Get Number of roof liveries
*/
function openMenu(type) {
vehicle = alt.Player.local.vehicle.scriptID
wtype = native.getVehicleWheelType(vehicle);
wnum = native.getVehicleMod(vehicle, 23);
hud.focus();
alt.showCursor(true);
native.displayRadar(false);
native.freezeEntityPosition(vehicle, true);
interval = alt.setInterval(() => { NoMouseAndBugDeleter() }, 1);
let nblivery = native.getVehicleLiveryCount(vehicle);
let nbroofs = native.getVehicleRoofLiveryCount(vehicle);
alt.emitServer('seln:mecha:getmodscount', type, nblivery, nbroofs);
menuouvert = true
}
/**
* In Menu Interval :
* Remove the mouse activities to avoid messing the screen when using the menu
* Unbug bugs #2, #4 and #5
* Bug #2 : The wheels go to normal when changing something else
* Bug #4 : The roof livery go back to classic when changing something else
* Bug #5 : The extras changes get undone when changing something else
*
*/
function NoMouseAndBugDeleter() {
// Unbug vehicle wheels
native.setVehicleWheelType(vehicle, wtype);
native.setVehicleMod(vehicle, 23, wnum);
native.setVehicleMod(vehicle, 24, wnum);
// Unbug vehicle roof livery
native.setVehicleRoofLivery(vehicle, roof);
// Unbug vehicle extras
actualextra.forEach(extra => {
if (extra != null) {
let actual = extra.ison
if (actual) { native.setVehicleExtra(alt.Player.local.vehicle.scriptID, extra.id, 0); }
else { native.setVehicleExtra(alt.Player.local.vehicle.scriptID, extra.id, 1); }
}
});
// No Mouse
native.disableControlAction(0, 1, true);
native.disableControlAction(0, 2, true);
native.disableControlAction(0, 106, true);
}