-
Notifications
You must be signed in to change notification settings - Fork 0
/
LFS Drift Script.py
303 lines (247 loc) · 11.5 KB
/
LFS Drift Script.py
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
# ==============================================================================================
#
# Github link:
# https://github.com/Bluewave2/Drift-Script
#
#
# Mouse = X axis steering
# W = Throttle
# S = Brake
# C = Clutch
# Q = Upshift (sequential)
# E = Downshift (sequential)
# R = Reset car (if the game supports it)
# Z = View left
# X = View right
# Space = Handbrake
# Mouse 3 = Lock mouse to bottom of screen (toggle)
#
# ==============================================================================================
if starting:
system.setThreadTiming(TimingTypes.HighresSystemTimer)
system.threadExecutionInterval = 5
def set_button(button, key):
if keyboard.getKeyDown(key):
v.setButton(button, True)
else:
v.setButton(button, False)
def calculate_rate(max, time):
if time > 0:
return max / (time / system.threadExecutionInterval)
else:
return max
int32_max = (2 ** 14) - 1
int32_min = (( 2** 14) * -1) + 1
v = vJoy[0]
v.x, v.y, v.z, v.rx, v.ry, v.rz, v.slider, v.dial = (int32_min,) * 8
from ctypes import *
user32 = windll.user32
# =============================================================================================
# Axis inversion settings (multiplier): normal = 1; inverted = -1
# =============================================================================================
global throttle_inversion, braking_inversion, clutch_inversion, hbrake_inversion
throttle_inversion = 1
braking_inversion = 1
clutch_inversion = 1
hbrake_inversion = 1
# =============================================================================================
# Mouse settings
# =============================================================================================
global mouse_sensitivity, sensitivity_center_reduction
mouse_sensitivity = 5
sensitivity_center_reduction = 1.0
# =============================================================================================
# Ignition cut settings
# =============================================================================================
global ignition_cut_time, ignition_cut_elapsed_time
ignition_cut_enabled = True
ignition_cut_time = 100
ignition_cut_elapsed_time = 0
global ignition_cut, ignition_cut_released
# Init values, do not change
ignition_cut = False
ignition_cut_released = True
# =============================================================================================
# Steering settings
# =============================================================================================
global steering, steering_max, steering_min, steering_center_reduction
# Init values, do not change
steering = 0.0
steering_max = float(int32_max)
steering_min = float(int32_min)
steering_center_reduction = 1
# =============================================================================================
# Throttle settings
# =============================================================================================
global throttle_blip_enabled
throttle_blip_enabled = False
# In milliseconds
throttle_increase_time = 100
throttle_increase_time_after_ignition_cut = 0
throttle_increase_time_blip = 50
throttle_decrease_time = 150
global throttle, throttle_max, throttle_min, throttle_max2
# Init values, do not change
throttle_max = int32_max * throttle_inversion
throttle_min = int32_min * throttle_inversion
throttle_max2 = int32_max * throttle_inversion
throttle = throttle_min
global throttle_increase_rate, throttle_decrease_rate
# Set throttle behaviour with the increase and decrease time,
# the actual increase and decrease rates are calculated automatically
throttle_increase_rate = calculate_rate(throttle_max, throttle_increase_time)
throttle_increase_rate_after_ignition_cut = calculate_rate(throttle_max, throttle_increase_time_after_ignition_cut)
throttle_increase_rate_blip = calculate_rate(throttle_max, throttle_increase_time_blip)
throttle_decrease_rate = calculate_rate(throttle_max, throttle_decrease_time) * -1
# =============================================================================================
# Braking settings
# =============================================================================================
# In milliseconds
braking_increase_time = 120
braking_decrease_time = 120
global braking, braking_max, braking_min, braking_max2, brakeflippy
# Init values, do not change
braking_max = int32_max * braking_inversion
braking_min = int32_min * braking_inversion
braking_max2 = braking_max
brakeflippy = 0
braking = braking_min
global braking_increase_rate, braking_decrease_rate
# Set braking behaviour with the increase and decrease time,
# the actual increase and decrease rates are calculated automatically
braking_increase_rate = calculate_rate(braking_max, braking_increase_time)
braking_decrease_rate = calculate_rate(braking_max, braking_decrease_time) * -1
# =============================================================================================
# HBraking settings
# =============================================================================================
# In milliseconds
hbrake_increase_time = 100
hbrake_decrease_time = 100
global hbrake, hbrake_max, hbrake_min
# Init values, do not change
hbrake_max = int32_max * hbrake_inversion
hbrake_min = int32_min * hbrake_inversion
hbrake = hbrake_min
global hbrake_increase_rate, hbrake_decrease_rate
# Set hbrake behaviour with the increase and decrease time,
# the actual increase and decrease rates are calculated automatically
hbrake_increase_rate = calculate_rate(hbrake_max, hbrake_increase_time)
hbrake_decrease_rate = calculate_rate(hbrake_max, hbrake_decrease_time) * -1
# =============================================================================================
# Clutch settings
# =============================================================================================
# In milliseconds
clutch_increase_time = 0
clutch_decrease_time = 50
global clutch, clutch_max, clutch_min
# Init values, do not change
clutch_max = int32_max * clutch_inversion
clutch_min = int32_min * clutch_inversion
clutch = clutch_min
global clutch_increase_rate, clutch_decrease_rate
# Set clutch behaviour with the increase and decrease time,
# the actual increase and decrease rates are calculated automatically
clutch_increase_rate = calculate_rate(clutch_max, clutch_increase_time)
clutch_decrease_rate = calculate_rate(clutch_max, clutch_decrease_time) * -1
global mouselock
mouselock = False
# assign button
vJoy[0].setButton(0,int(keyboard.getKeyDown(Key.Q)))
vJoy[0].setButton(1,int(keyboard.getKeyDown(Key.E)))
vJoy[0].setButton(2,int(keyboard.getKeyDown(Key.Z)))
vJoy[0].setButton(3,int(keyboard.getKeyDown(Key.X)))
vJoy[0].setButton(4,int(keyboard.getKeyDown(Key.R)))
vJoy[0].setButton(5,int(keyboard.getKeyDown(Key.V)))
#vJoy[0].setButton(6,int(keyboard.getKeyDown(Key.T)))
#vJoy[0].setButton(7,int(keyboard.getKeyDown(Key.Y)))
toggle_mouselock = mouse.getPressed(3)
if toggle_mouselock:
mouselock = not mouselock
if (mouselock):
user32.SetCursorPos(960, 5000)
# =================================================================================================
# LOOP START
# =================================================================================================
# =================================================================================================
# Steering logic
# =================================================================================================
if steering > 0:
steering_center_reduction = sensitivity_center_reduction ** (1 - (steering / steering_max))
elif steering < 0:
steering_center_reduction = sensitivity_center_reduction ** (1 - (steering / steering_min))
steering = steering + ((float(mouse.deltaX) * mouse_sensitivity) / steering_center_reduction)
if steering > steering_max:
steering = steering_max
elif steering < steering_min:
steering = steering_min
v.x = int(round(steering))
# =================================================================================================
# Clutch logic
# =================================================================================================
if keyboard.getKeyDown(Key.C):
clutch = clutch + clutch_increase_rate
else:
clutch = clutch + clutch_decrease_rate
if clutch > clutch_max * clutch_inversion:
clutch = clutch_max * clutch_inversion
elif clutch < clutch_min * clutch_inversion:
clutch = clutch_min * clutch_inversion
v.z = clutch
# =================================================================================================
# Throttle logic
# =================================================================================================
#if keyboard.getKeyDown(Key.K):
# throttle_max = (int32_max * throttle_inversion) /3
# brakeflippy = 1
#elif keyboard.getKeyDown(Key.J) and brakeflippy == 1:
# throttle_max = throttle_max2
# brakeflippy = 0
if keyboard.getKeyDown(Key.W):
throttle = throttle + throttle_increase_rate
else:
throttle = throttle + throttle_decrease_rate
if throttle > throttle_max * throttle_inversion:
throttle = throttle_max * throttle_inversion
elif throttle < throttle_min * throttle_inversion:
throttle = throttle_min * throttle_inversion
v.y = throttle
# =================================================================================================
# Braking logic
# =================================================================================================
#if keyboard.getPressed(Key.B):
# if brakeflippy == 1:
# brakeflippy = 0
# else:
# brakeflippy = 1
#if brakeflippy == 1:
# braking_max = braking_max / 2
#else:
# braking_max = braking_max2
#if keyboard.getKeyDown(Key.B):
# braking_max = braking_max / 2
#else:
# braking_max = braking_max2
if keyboard.getKeyDown(Key.S):
braking = braking + braking_increase_rate
else:
braking = braking + braking_decrease_rate
if braking > braking_max * braking_inversion:
braking = braking_max * braking_inversion
elif braking < braking_min * braking_inversion:
braking = braking_min * braking_inversion
v.rz = braking
# =================================================================================================
# HandBraking logic
# =================================================================================================
if keyboard.getKeyDown(Key.Space):
hbrake = hbrake + hbrake_increase_rate
else:
hbrake = hbrake + hbrake_decrease_rate
if hbrake > hbrake_max * hbrake_inversion:
hbrake = hbrake_max * hbrake_inversion
elif hbrake < hbrake_min * hbrake_inversion:
hbrake = hbrake_min * hbrake_inversion
v.ry = hbrake
# =================================================================================================
# Buttons post-throttle logic
# ====================================================================