summaryrefslogtreecommitdiff
path: root/scripts/gugus/gear.lua
blob: 079f428a383adb4a1a24db7c781796bb20ac8c37 (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

mIgnitionTicks = nil
oldIgnition = nil
oldGear = nil

function Ignition(gear, isFanatec)
	-- print ( " Gear : " .. gear )
	local ignition = GetCarInfo("ignition")

	--print ( string.format("gear %d/ignition %d" , g, ignition))

	if isFanatec == false then
		SetLeftDigits("       ")
		SetRightDigits("       ")
	else
		SetfanatecDigits("   ")
	end

	toggleAllLed(0)

	if ignition == 2 then
		-- Ignition ON, Starting engine
		initLedTable(mRPMLedTable, 1)
		SetRPMLed("mRPMLedTable")
	else
		-- Ignition ON, Engine OFF
		initLedTable(mRPMLedTable, 0)
		SetRPMLed("mRPMLedTable")

		-- blink damage led
		if mIgnitionTicks == nil or GetTicks() > mIgnitionTicks then
			mIgnitionTicks  = GetTicks() + 1000
			SetWarnLed(GetLedIndex("damage"), 1)
		end
	end

	if ignition == 0 and GetContextInfo("simulation") == "rFactor2.exe" then
		-- Don¿t display gear when Ignition OFF
		SetGearDigit(" ")
	else
		-- Ignition ON (or can¿t tell on other sims)
		SetGearDigit(GetCurrentGear())
	end

	SLISendReport(1)

	-- bypasses gearEvent
	return 1
end

function custom_gearEvent(gear)

	-- get neutral
	local n = GetContextInfo("neutral")
	-- get reverse char and convert to string
	local r = string.char(GetContextInfo("reverse"))
	-- get state of custom Optimal Shift Point (OSP) records
	local ospcustom_on = GetContextInfo("ospcustom")

	if gear == 69 then
		-- specific case when gear == 'E'

		local g = GetCarInfo("gear")
		oldGear = g

		Ignition(g, false)

		return 1

	elseif oldGear == nil or oldGear ~= gear then
		-- backup gear state
		oldGear = gear
		-- set neutral, reverse or current gear
		if gear == 0 then
			-- if neutral and using custom OSP record then add a dot to gear digit
			if ospcustom_on then n = n + 128 end
			SetGearDigit(string.char(n))
		elseif gear < 0 then
			SetGearDigit(r)
		else
			SetGearDigit(string.char(gear))
		end
	end

	return 1
end

print ( "gugus> + gear (ignition)" )