summaryrefslogtreecommitdiff
path: root/scripts/zdoc_scripts/iracing_stuff.lua
blob: d0df9db34464e95284f6d9d4844b0567044072cb (plain)
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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
-- Custom SLIMax Manager Scripts for iRacing v3.2.1
-- Copyright ©2012-2013 by Zappadoc
-- _last change by Zappadoc - 2013-10

-- =====================================
-- iRacing Stuff script
-- define car setup function and all pit limiter and shiftlights methods for each car you drive
function iRacing_DebugCarInfo(deviceType)
	-- see debug console window
	-- get car name
	local dev = GetDeviceType(deviceType)
	local cNm = GetContextInfo("carname")
	local mxG = GetCarInfo("maxgear")
	local rdz = GetCarInfo("redzone")
	local ospf = GetContextInfo("ospfactor")
	print("\n----------\nDevice:"..dev.."\nSetup car:" .. cNm .. "(" .. rdz .. ")" .. "\nMaxGear:" .. mxG .. "\nOSP Factor:" .. ospf .. "\n");
end

function iRacing_InitGearEvent(gear)
	-- get current simulation name
	-- custom script to overwrite OSP value and OSP limit for each gear of each iRacing car
	local sim = GetContextInfo("simulation")
	if isAppIRacing(sim) then
	if gOldGear == nil then gOldGear = -2 end
	-- setup iRacing car OSP, RedZone, Max gear, ...
	iRacing_CarSetup(gear)
	if gear ~= gOldGear then
	gOldGear =  gear
	end
	end
end

function iRacing_CarSetup(cGear)
	-- get car name
	local cNm = ""
	cNm = GetContextInfo("carname")
	local mxG = 4
	local ospf = 140

	if cNm == "cadillacctsvr" then
	mxG = 6
	ospf = 148

	elseif cNm == "mclarenmp4" then
	mxG = 6
	ospf = 150

	elseif cNm == "kiaoptima" then
	mxG = 5
	ospf = 150

	elseif cNm == "formulamazda" then
	mxG = 6
	ospf = 60

	elseif cNm == "williamsfw31" then
	mxG = 7
	ospf = 90

	elseif cNm == "mx5 cup" or cNm == "mx5 roadster" then
	mxG = 6
	ospf = 140

	elseif cNm == "hpdarx01c" then
	mxG = 6
	if cGear <= 2 then
	ospf = 10
	gOSPLimit = 9900
	gRedZone = 9920
	elseif cGear ==3 then
	ospf = 100
	gOSPLimit = 9530
	gRedZone = 9545
	elseif cGear == 4 then
	ospf = 90
	gOSPLimit = 9500
	gRedZone = 9510
	else
	ospf = 150
	gOSPLimit = 9420
	gRedZone = 9425
	end


	elseif cNm == "fordgt" then
	mxG = 6
	ospf = 128

	elseif cNm == "fr500s" then
	mxG = 6
	ospf = 150

	elseif cNm == "fordv8sc" then
	mxG = 6
	ospf = 100

	 elseif cNm == "dallara" then
	mxG = 6
	ospf = 95

	elseif cNm == "latemodel" then
	mxG = 5

	elseif cNm == "legends ford34c" then
	mxG = 5
	ospf = 150

	elseif cNm == "skmodified" then
	mxG = 6

	elseif cNm == "silvercrown" then
	mxG = 6

	elseif cNm == "trucks silverado" then
	mxG = 4

	elseif cNm == "stockcars impala" then
	mxG = 4
	ospf = 140

	elseif cNm == "lotus79" then
	mxG = 5
	ospf = 100

	elseif cNm == "stockcars2 chevy" then
	mxG = 4
	ospf = 130

	elseif cNm == "stockcars2 chevy cot" then
	mxG = 4
	ospf = 150

	elseif cNm == "c6r" then
	mxG = 6
	ospf = 145

	elseif cNm == "solstice" then
	mxG = 5
	ospf = 150

	elseif cNm == "jettatdi" then
	mxG = 5

	elseif cNm == "radical sr8" then
	mxG = 6
	ospf = 115

	elseif cNm == "rt2000" then
	mxG = 5
	ospf = 140

	elseif cNm == "specracer" then
	mxG = 5
	ospf = 140

	elseif cNm == "rileydp" then
	mxG = 5
	ospf = 85

	elseif cNm == "streetstock" then
	mxG = 4
	ospf = 150

	elseif cNm == "sprint" then
	mxG = 6

	else
	-- default
	mxG = 4
	ospf = 150
	end
	-- set max gear and OSP factor for this car
	SetMaxGear(mxG)
	SetOSPFactor(ospf)
end

function FixRPMSpeedlimiter()
	local led = ""
	-- init table
	initLedTable(mRPMLedTable, 0)
	SetRPMLed("mRPMLedTable")
	for i = 0,14 do
	led = led.format("RPM%d",i)
	mRPMLedTable[led] = 1
	end
	SetRPMLed("mRPMLedTable")

end

function iRacing_spdLmtMethodEvent(idx, deviceType)
	local led = ""

	-- get car name
	local cNm = GetContextInfo("carname")

	-- speedlimiter stuff
	if cNm == "formulamazda" then
	mSpdLimitMethod = 2

	elseif cNm == "mclarenmp4" then
	mSpdLimitMethod = 2

	elseif cNm == "williamsfw31" then
	-- speedlimiter led fixed + digits blinking, method 6
	mSpdLimitMethod = 5

	elseif cNm == "fordv8sc" then
	mSpdLimitMethod = 2

	elseif cNm == "dallara" then
	mSpdLimitMethod = 2

	elseif cNm == "fordgt" then
	mSpdLimitMethod = 2

	elseif cNm == "hpdarx01c" then
	FixRPMSpeedlimiter()
	return 1

	elseif cNm == "rileydp" then
	mSpdLimitMethod = 2

	elseif cNm == "c6r" then
	FixRPMSpeedlimiter()
	return 1

	elseif cNm == "radical sr8" then
	mSpdLimitMethod = 0

	elseif cNm == "jettatdi" then
	mSpdLimitMethod = 2

	elseif cNm == "cadillacctsvr" then
	FixRPMSpeedlimiter()
	return 1

	-- cars with  without dashboardleds
	--	elseif cNm == "mx5 cup" or cNm == "mx5 roadster" then
	-- elseif cNm == "fr500s" then
	-- elseif cNm == "latemodel" then
	-- elseif cNm == "legends ford34c" then
	-- elseif cNm == "legends ford34c rookie" then
	-- elseif cNm == "skmodified" then
	-- elseif cNm == "silvercrown" then
	-- elseif cNm == "trucks silverado" then
	-- elseif cNm == "stockcars impala" then
	-- elseif cNm == "lotus79" then
	-- elseif cNm == "stockcars2 chevy" then
	-- elseif cNm == "solstice" then
	-- elseif cNm == "solstice rookie" then
	-- elseif cNm == "rt2000" then
	-- elseif cNm == "specracer" then
	-- elseif cNm == "streetstock" then
	-- elseif cNm == "sprint" then

	else
	-- default
	mSpdLimitMethod = 0

	end
	return 2
end

function iRacing_shiftLightsMethodEvent(idx, dev)
	-- rpm table name
	local tName = "mRPMLedTable"
	-- get rpm
	local rpm = 0
	rpm = GetCarInfo("rpm")
	if rpm == nil then rpm = 0 end

	-- check redzone value
	if gRedZone == nil or gRedZone == 0 then gRedZone = GetCarInfo("redzone") end

	-- get car name
	local cNm = GetContextInfo("carname")

	local isPit = GetCarInfo("inpits")
	local carspd =  GetCarInfo("rawspeed")

	-- init leds (see global.lua)
	initLedTable(mRPMLedTable, 0)

	-- Pits Stuff
	if isPit == 1 and carspd == 0 then
	--  pit stop

	elseif isPit >= 1 and carspd > 21 then
	-- car Approaching pits (or in pit lane) and exceed 45 mph
	-- set the red zone to the current engine rpm (This sets the shiftlights to the max and warns the driver)
	local spdLmt = GetCarInfo("speedlimiter")
	if spdLmt == 0 then
	-- if speedlimiter is OFF
	gRedZone = rpm
	end
	end

	-- get device type
	if dev == nil then dev = "none" end

	-- shiftlights stuff
	if cNm == "formulamazda" then
	-- start Mazda shiftlights
	if dev == "FANATEC" then
	SideToCenterFanatec(rpm, gRedZone, 96, 97 ,98 ,99 ,99.5)
	elseif dev == "SRDLX" then
	SideToCenterSRDlx(rpm, gRedZone, 95, 96, 97 ,98 ,99 ,99.5)
	elseif dev == "SRF1" then
	SideToCenterSRF1(rpm, gRedZone, 94, 94.5, 95, 96, 97 ,98 ,99 ,99.5)
	else
	SideToCenterSLI(rpm, gRedZone, 94.5, 95, 96, 97 ,98 ,99 ,99.5)
	end
	elseif cNm == "mclarenmp4" then
	local gear = GetCarInfo("gear")
	if gear == 6 then
	if dev == "FANATEC" then
	RpmFanatec(rpm, 6720 , 6870 , 7000 , 7200, 7305, 7340, 7340, 7340, 7340)
	elseif dev == "SRDLX" then
	RpmSRDlx(rpm, 6690, 6720 , 6870 , 7000 , 7200, 7305, 7340, 7340, 7340, 7340)
	elseif dev == "SRF1" then
	RpmSRF1(rpm, 6300, 6350, 6400, 6490, 6580, 6690, 6720 , 6870 , 7000 , 7200, 7305, 7340, 7340, 7340, 7340)
	else
	ProgressiveFixedSLI(rpm, 6300, 6490, 6580, 6690, 6720 , 6870 , 7000 , 7200, 7305, 7340, 7340, 7340, 7340)
	end
	else
	if dev == "FANATEC" then
	RpmFanatec(rpm, 6620 , 6670 , 6750 , 6800, 6895, 7040, 7040, 7040, 7040)
	elseif dev == "SRDLX" then
	RpmSRDlx(rpm, 6590, 6620 , 6670 , 6750 , 6800, 6895, 7040, 7040, 7040, 7040)
	elseif dev == "SRF1" then
	RpmSRF1(rpm, 6200, 6250, 6300, 6390, 6480, 6590, 6620 , 6670 , 6750 , 6800, 6895, 7040, 7040, 7040, 7040)
	else
	ProgressiveFixedSLI(rpm, 6200, 6390, 6480, 6590, 6620 , 6670 , 6750 , 6800, 6895, 7040, 7040, 7040, 7040)
	end
	end

	elseif cNm == "williamsfw31" then
	if dev == "FANATEC" then
	AlternateFanatec(rpm, gRedZone, 7.0, 8.0, 8.9)
	elseif dev == "SRDLX" then
	AlternateSRDlx(rpm, gRedZone, 8.0, 9.0, 9.9)
	elseif dev == "SRF1" then
	AlternateSRF1(rpm, gRedZone, 12.0, 13.0, 14.9)
	else
	AlternateSLI(rpm, gRedZone, 11.0, 12.0, 12.9)
	end

	elseif cNm == "kiaoptima" then
	if dev == "FANATEC" then
	SideToCenterFanatec(rpm, gRedZone, 95, 96 ,97 ,98 ,99)
	elseif dev == "SRDLX" then
	SideToCenterSRDlx(rpm, gRedZone, 90, 95, 96 ,97 ,98 ,99)
	elseif dev == "SRF1" then
	SideToCenterSRF1(rpm, gRedZone, 86, 90, 95, 96 ,97 ,98 ,99, 99.5)
	else
	SideToCenterSLI(rpm, gRedZone, 86, 90, 95, 96 ,97 ,98 ,99)
	end

	elseif cNm == "mx5 cup" or cNm == "mx5 roadster" then
	if dev == "FANATEC" then
	SideToCenterFanatec(rpm, gRedZone, 95, 96 ,97 ,98 ,99)
	elseif dev == "SRDLX" then
	SideToCenterSRDlx(rpm, gRedZone, 90, 95, 96 ,97 ,98 ,99)
	elseif dev == "SRF1" then
	SideToCenterSRF1(rpm, gRedZone, 86, 90, 95, 96 ,97 ,98 ,99, 99.5)
	else
	SideToCenterSLI(rpm, gRedZone, 86, 90, 95, 96 ,97 ,98 ,99)
	end

	elseif cNm == "fr500s" then
	if dev == "FANATEC" then
	SideToCenterFanatec(rpm, gRedZone, 86, 88 ,90 ,98 ,99)
	elseif dev == "SRDLX" then
	SideToCenterSRDlx(rpm, gRedZone, 84, 86, 88 ,90 ,98 ,99)
	elseif dev == "SRF1" then
	SideToCenterSRF1(rpm, gRedZone, 80, 84, 86, 88 ,90 ,98 ,99, 99.5)
	else
	SideToCenterSLI(rpm, gRedZone, 80, 84, 86, 88 ,90 ,98 ,99)
	end

	elseif cNm == "fordv8sc" then
	if dev == "FANATEC" then
	SideToCenterFanatec(rpm, gRedZone, 92, 94 ,97 ,98 ,99)
	elseif dev == "SRDLX" then
	SideToCenterSRDlx(rpm, gRedZone, 90, 92, 94 ,97 ,98 ,99)
	elseif dev == "SRF1" then
	SideToCenterSRF1(rpm, gRedZone, 87, 90, 92, 94 ,97 ,98 ,99, 99.5)
	else
	SideToCenterSLI(rpm, gRedZone, 87, 90, 92, 94 ,97 ,98 ,99)
	end

	 elseif cNm == "dallara" then
	if dev == "FANATEC" then
	SideToCenterFanatec(rpm, gRedZone, 90, 94 ,97 ,98 ,99)
	elseif dev == "SRDLX" then
	SideToCenterSRDlx(rpm, gRedZone, 82, 90, 94 ,97 ,98 ,99)
	elseif dev == "SRF1" then
	SideToCenterSRF1(rpm, gRedZone, 78, 82, 90, 94 ,97 ,98 ,99, 99.5)
	else
	SideToCenterSLI(rpm, gRedZone, 78, 82, 90, 94 ,97 ,98 ,99)
	end

	elseif cNm == "fordgt" then
	if dev == "FANATEC" then
	SideToCenterFanatec(rpm, gRedZone, 95, 96 ,97 ,98 ,99)
	elseif dev == "SRDLX" then
	SideToCenterSRDlx(rpm, gRedZone, 94, 95, 96 ,97 ,98 ,99)
	elseif dev == "SRF1" then
	SideToCenterSRF1(rpm, gRedZone, 93, 94, 95, 96 ,97 ,98 ,99, 99.5)
	else
	SideToCenterSLI(rpm, gRedZone, 93, 94, 95, 96 ,97 ,98 ,99)
	end

	elseif cNm == "hpdarx01c" then
	if dev == "FANATEC" then
	RpmFanatec(rpm, 8500 , 8700 , 8800 , 8900, 9100, 9300, 9500, 9700, 9940)
	elseif dev == "SRDLX" then
	RpmSRDlx(rpm, 8300, 8500 , 8700 , 8800 , 8900, 9100, 9300, 9500, 9700, 9940)
	elseif dev == "SRF1" then
	RpmSRF1(rpm, 7800, 7840, 7890, 7900, 8100, 8300, 8500 , 8700 , 8800 , 8900, 9100, 9300, 9500, 9700, 9940)
	else
	ProgressiveFixedSLI(rpm, 7800, 7900, 8100, 8300, 8500 , 8700 , 8800 , 8900, 9100, 9300, 9500, 9700, 9940)
	end

	elseif cNm == "rileydp" then
	if dev == "FANATEC" then
	RpmFanatec(rpm, 6900, 7000 , 10000 , 10000 , 10000, 10000, 10000, 10000, 10000)
	elseif dev == "SRDLX" then
	RpmSRDlx(rpm, 6800, 6900, 7000 , 10000 , 10000 , 10000, 10000, 10000, 10000, 10000)
	elseif dev == "SRF1" then
	RpmSRF1(rpm, 10000, 10000, 6700, 6800, 6900, 7000 , 10000 , 10000 , 10000, 10000, 10000, 10000, 10000, 10000, 10000)
	else
	ProgressiveFixedSLI(rpm, 10000, 6700, 6800, 6900, 7000 , 10000 , 10000 , 10000, 10000, 10000, 10000, 10000, 10000)
	end

	elseif cNm == "c6r" then
	if dev == "FANATEC" then
	RpmFanatec(rpm, 5200 , 5300 , 5400 , 5600, 5700, 5800, 5900, 6000, 6100)
	elseif dev == "SRDLX" then
	RpmSRDlx(rpm, 5000, 5200 , 5300 , 5400 , 5600, 5700, 5800, 5900, 6000, 6100)
	elseif dev == "SRF1" then
	RpmSRF1(rpm, 4700, 4800, 4900, 5000, 5040, 5190, 5200 , 5300 , 5400 , 5600, 5700, 5800, 5900, 6000, 6100)
	else
	ProgressiveFixedSLI(rpm, 4700, 4800, 4900, 5000, 5200 , 5300 , 5400 , 5600, 5700, 5800, 5900, 6000, 6100)
	end

	elseif cNm == "radical sr8" then
	if dev == "FANATEC" then
	RpmFanatec(rpm, 6400 , 6900 , 7700 , 8100, 8700, 9850, 10100, 10250, 10500)
	elseif dev == "SRDLX" then
	RpmSRDlx(rpm, 5700, 6400 , 6900 , 7700 , 8100, 8700, 9850, 10100, 10250, 10500)
	elseif dev == "SRF1" then
	RpmSRF1(rpm, 4350, 4800, 5100, 5300, 5500, 5700, 6400 , 6900 , 7700 , 8100, 8700, 9850, 10100, 10250, 10500)
	else
	ProgressiveFixedSLI(rpm, 4350, 4800, 5100, 5700, 6400 , 6900 , 7700 , 8100, 8700, 9850, 10100, 10250, 10500)
	end

	elseif cNm == "jettatdi" then
	if dev == "FANATEC" then
	SideToCenterFanatec(rpm, gRedZone, 86, 88 ,90 ,98 ,99)
	elseif dev == "SRDLX" then
	SideToCenterSRDlx(rpm, gRedZone, 84, 86, 88 ,90 ,98 ,99)
	elseif dev == "SRF1" then
	SideToCenterSRF1(rpm, gRedZone, 80, 84, 86, 88 ,90 ,98 ,99, 99.5)
	else
	SideToCenterSLI(rpm, gRedZone, 80, 84, 86, 88 ,90 ,98 ,99)
	end

	elseif cNm == "cadillacctsvr" then
	--ProgressiveFixedSLI(rpm, 6500, 6580, 6600, 6700, 6800 , 6900 , 7000 , 7100, 7200, 7300, 7400, 7500, 7600)
	if dev == "FANATEC" then
	ProgressiveFanatec(rpm, gRedZone, 7.9, 8.15, 8.2, 8.25, 8.3, 8.35, 8.5, 8.8, 8.98 )
	elseif dev == "SRDLX" then
	ProgressiveSRDlx(rpm, gRedZone, 8.5, 8.9, 9.15, 9.2, 9.25, 9.3, 9.35, 9.5, 9.8, 9.98 )
	elseif dev == "SRF1" then
	ProgressiveSRF1(rpm, gRedZone, 13.8, 13.85, 13.9, 13.95, 13.98, 14, 14.1, 14.15, 14.2, 14.25, 14.3, 14.35, 14.5, 14.8, 14.98 )
	else
	ProgressiveSLI(rpm, gRedZone, 11.9, 11.95, 11.98, 12, 12.1, 12.15, 12.2, 12.25, 12.3, 12.35, 12.5, 12.8, 12.98 )
	end

	-- progressive default method for all cars with dashboard without leds
	-- elseif cNm == "latemodel" then
	-- elseif cNm == "legends ford34c" then
	-- elseif cNm == "legends ford34c rookie" then
	-- elseif cNm == "skmodified" then
	-- elseif cNm == "silvercrown" then
	-- elseif cNm == "trucks silverado" then
	-- elseif cNm == "stockcars impala" then
	-- elseif cNm == "lotus79" then
	-- elseif cNm == "stockcars2 chevy" then
	-- elseif cNm == "solstice" then
	-- elseif cNm == "solstice rookie" then
	-- elseif cNm == "rt2000" then
	-- elseif cNm == "specracer" then
	-- elseif cNm == "streetstock" then
	-- elseif cNm == "sprint" then

	else
	-- default
	if dev == "FANATEC" then
	ProgressiveFanatec(rpm,  gRedZone, 4.5, 5, 6.5, 7, 7.5, 8, 8.5, 8.8, 8.98 )
	elseif dev == "SRDLX" then
	ProgressiveSRDlx(rpm,  gRedZone, 5.0, 5.5, 6, 7.5, 8, 8.5, 9, 9.5, 9.8, 9.98 )
	elseif dev == "SRF1" then
	ProgressiveSRF1(rpm,  gRedZone, 9.0, 9.5, 9.8, 10, 10.5, 11, 11.5, 12, 12.5, 13, 13.5, 14, 14.5, 14.8, 14.98  )
	else
	ProgressiveSLI(rpm, gRedZone, 7.5, 8, 8.5, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.5, 12.8, 12.98 )
	end
	end

	-- set leds
	SetRPMLed(tName)
end

function iRacing_ospMethodEvent(idx, deviceType)
	-- get car name
	local cNm = GetContextInfo("carname")
	-- OSP Method stuff
	if mOSPMethod ~= nil then
	if cNm == "mclarenmp4" or cNm == "williamsfw31" then
	 if deviceType == "FANATEC" then
	mOSPMethod = 1
	else
	mOSPMethod = 3
	end

	-- else
	-- -- default
	-- if deviceType == "FANATEC" then
	-- mOSPMethod = 1
	-- end
	end
	end
	return 2
end