-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSCR auto.lua
More file actions
220 lines (191 loc) · 7.08 KB
/
SCR auto.lua
File metadata and controls
220 lines (191 loc) · 7.08 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
-- Made by PlaceReporter99
-- https://github.com/PlaceReporter99
-- You may want to change these constants depending on your train.
-- The maximum speed of your train.
local MAXSPEED = 75
-- Whether to obey the current speed limit.
local OBEYSPEEDLIMIT = true
-- The speed the train should slow down to when getting close to the station.
local SAFESTOPSPEED = 30
-- The speed the train should move at when approaching a single yellow signal.
local YELLOWSIGNALSPEED = 45
-- The distance in miles from the station your train should reach before slowing down.
local SAFESTOPDISTANCE = 0.2
-- The distance in studs from the buffer the train should stop.
local BUFFERSTOP = 100
print("AUTO DRIVE")
local cs = Instance.new("BindableEvent")
local buf = loadstring(game:HttpGet("https://raw.githubusercontent.com/PlaceReporter99/SCR-Autopilot/refs/heads/main/const/RouteBuffers.lua"))()
cs.Name = "ChangeSpeed"
signalv = {
["proceed"] = 0,
["precaution"] = 1,
["caution"] = 2,
["danger"] = 3,
["unknown"] = 4
}
cs.Event:Connect(function(a)
target(a)
end)
local fex = Instance.new("BindableEvent")
fex.Name = "ExecuteFunction"
fex.Event:Connect(function(f) f() end)
local vim = game:GetService('VirtualInputManager')
input = {
hold = function(key, time)
print("Holding key", key)
vim:SendKeyEvent(true, key, false, nil)
task.wait(time)
vim:SendKeyEvent(false, key, false, nil)
print("Finished holding key", key)
end,
press = function(key)
print("Pressing key", key)
vim:SendKeyEvent(true, key, false, nil)
task.wait(0.005)
vim:SendKeyEvent(false, key, false, nil)
end,
start = function(key)
print("starting key", key)
vim:SendKeyEvent(true, key, false, nil)
end,
stop = function(key)
print("stopping key", key)
vim:SendKeyEvent(false, key, false, nil)
end
}
local drive = game.Players.LocalPlayer.PlayerGui.DriveGui
local schd = drive.Additional.DetailsStack.AdvanceContainer.Main.ScheduleDetails
local left = schd.Counters
local cluster = drive.Cluster
local arm = cluster.Spedometer.TargetIndicator
local buttons = cluster.Actions
local d = left.Distance
local ti = left.DepartTime
local odm = cluster.Activity.ActivityMessage
local nl = drive.Summary.SummaryPage.Controls.NextLeg
local aws = cluster.AwsIndicatorMinimal
local signal = drive.Additional.DetailsStack.AdvanceContainer.Signal.Standard
local signald = drive.Additional.DetailsStack.AdvanceContainer.Signal.Distance
local speedl = game.Players.LocalPlayer.PlayerGui.DriveGui.Cluster.Stats.CurrentState.SpeedLimit.Limit
local msg = game.Players.LocalPlayer.PlayerGui.DriveGui.Additional.DetailsStack.MessageContainer
function getD(v)
return (workspace.CurrentCamera.Focus.Position - v).Magnitude
end
function getSpeedLimit()
if OBEYSPEEDLIMIT then
return tonumber(speedl.Text)
else
return 1000
end
end
function getSignal()
if signal.Danger.BackgroundTransparency == 0 then
print("signal get danger")
return signalv.danger
end
if signal.Precaution.BackgroundTransparency == 0 then
print("signal get precaution")
return signalv.precaution
end
if signal.Caution.BackgroundTransparency == 0 then
print("signal get caution")
return signalv.caution
end
if signal.Proceed.BackgroundTransparency == 0 then
print("signal get proceed")
return signalv.proceed
end
print("signal get unknown")
return signalv.unknown
end
function getSignalDistance()
return tonumber(signald.Text:sub(1, -4))
end
local mode = nil
speed_angle = function(speed) return speed*1.2 - 31 end
function target(speed)
local tt = false
local stopr = cs.Event:Connect(function()
tt = true
end)
input.stop(Enum.KeyCode.W)
input.stop(Enum.KeyCode.S)
print("targeting speed", speed)
print("rotation data this", speed_angle(speed), "that", arm.Rotation)
if -1.8 <= speed_angle(speed) - arm.Rotation and speed_angle(speed) - arm.Rotation <= 1.8 then
-- it's fine, do nothing
print("speed did not change", speed)
elseif speed_angle(speed) < arm.Rotation then
print("speed decrease to", speed)
input.start(Enum.KeyCode.S)
while speed_angle(speed) < arm.Rotation or tt do
task.wait(0.005)
end
input.stop(Enum.KeyCode.S)
elseif speed_angle(speed) > arm.Rotation then
print("speed increase to", speed)
input.start(Enum.KeyCode.W)
while speed_angle(speed) > arm.Rotation or tt do
task.wait(0.005)
end
input.stop(Enum.KeyCode.W)
end
end
drive.Clock.TextLabel:GetPropertyChangedSignal("Text"):Connect(function()
input.press(Enum.KeyCode.T)
input.press(Enum.KeyCode.Q)
if arm.Rotation <= speed_angle(10) and tonumber(d.Text:sub(1, -4)) ~= 0 and (getSignal() ~= signalv.danger or getSignalDistance() > tonumber(d.Text:sub(1, -4))) then
task.wait(10)
if arm.Rotation <= speed_angle(10) and tonumber(d.Text:sub(1, -4)) ~= 0 and (getSignal() ~= signalv.danger or getSignalDistance() > tonumber(d.Text:sub(1, -4))) then
cs:Fire(SAFESTOPSPEED)
end
end
--clickButton(nl)
end)
local c;
print(d.Text)
cs:Fire(math.min(MAXSPEED, getSpeedLimit()))
function b()
local num = tonumber(d.Text:sub(1, -4))
print(num)
if num == 0 or (getSignal() == signalv.danger and num >= getSignalDistance()) then
if num == 0 then
local plat = string.gsub(schd.Platform.Text, "Platform ", "")
local st = schd.NextStop.Text
if buf[st] and buf[st][plat] then
while getD(buf[st][plat]) >= BUFFERSTOP do
print(getD(buf[st][plat]))
cs:Fire(15)
task.wait(0.1)
end
end
end
cs:Fire(0)
elseif num <= SAFESTOPDISTANCE then
cs:Fire(math.min(SAFESTOPSPEED, getSpeedLimit()))
elseif getSignal() == signalv.caution then
cs:Fire(math.min(YELLOWSIGNALSPEED, getSpeedLimit()))
elseif (num > SAFESTOPDISTANCE and (getSignal() == signalv.precaution or getSignal() == signalv.proceed)) then
cs:Fire(math.min(MAXSPEED, getSpeedLimit()))
end
end
if (tonumber(d.Text:sub(1, -4)) <= SAFESTOPDISTANCE) then
cs:Fire(math.min(SAFESTOPSPEED, getSpeedLimit()))
elseif getSignal() == signalv.caution then
cs:Fire(math.min(YELLOWSIGNALSPEED, getSpeedLimit()))
else
cs:Fire(math.min(MAXSPEED, getSpeedLimit()))
end
d:GetPropertyChangedSignal("Text"):Connect(b)
signald:GetPropertyChangedSignal("Text"):Connect(b)
speedl:GetPropertyChangedSignal("Text"):Connect(b)
function under(child)
if child.Name == "DriveMessage" and (string.match(child.TextLabel.Text, "longside") or string.match(child.TextLabel.Text, "uffer")) then
cs:fire(5)
task.wait(3)
cs:fire(0)
end
end
msg.ChildAdded:Connect(under)
print(getSignal())