-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
152 lines (142 loc) · 4.87 KB
/
client.lua
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
local cruisedSpeed = 0
local vehicleClasses = {
[0] = true,
[1] = true,
[2] = true,
[3] = true,
[4] = true,
[5] = true,
[6] = true,
[7] = true,
[8] = true,
[9] = true,
[10] = true,
[11] = true,
[12] = true,
[13] = false,
[14] = false,
[15] = false,
[16] = false,
[17] = true,
[18] = true,
[19] = true,
[20] = true,
[21] = false
}
local hands_on_steering_wheel_cooldown = false
local function hands_on_steering_wheel()
if hands_on_steering_wheel_cooldown then return end
SendNUIMessage({
transactionType = 'hands_on_steering_wheel'
})
hands_on_steering_wheel_cooldown = true
Citizen.SetTimeout(5000, function()
hands_on_steering_wheel_cooldown = false
end)
end
local autopilot_alert_cooldown = false
local function autopilot_alert()
if autopilot_alert_cooldown then return end
SendNUIMessage({
transactionType = 'autopilot_alert'
})
autopilot_alert_cooldown = true
Citizen.SetTimeout(5000, function()
autopilot_alert_cooldown = false
end)
end
local function TriggerCruiseControl()
local NOACoords = nil
local isCruiseControlEnabled = false
if cache.seat == -1 then
local blip = GetFirstBlipInfoId(8)
if not IsVehicleOnAllWheels(cache.vehicle) then
autopilot_alert()
return
end
if DoesBlipExist(blip) then
NOACoords = GetBlipInfoIdCoord(blip) -- 获取标记点的坐标
TaskVehicleDriveToCoordLongrange(cache.ped, cache.vehicle, NOACoords.x, NOACoords.y, NOACoords.z, 35.0, 1345083563, 50.0)
SendNUIMessage({
transactionType = 'noa_enabled'
})
else
cruisedSpeed = GetEntitySpeed(cache.vehicle)
if cruisedSpeed >= 10 and GetVehicleCurrentGear(cache.vehicle) > 0 then
TaskVehicleDriveWander(cache.ped, cache.vehicle, cruisedSpeed, 1345083563)
SendNUIMessage({
transactionType = 'autosteer_enabled'
})
else
autopilot_alert()
return
end
end
local initBodyHealth = GetVehicleBodyHealth(cache.vehicle)
isCruiseControlEnabled = true
Wait(1000)
CreateThread(function()
while cache.vehicle do
if not isCruiseControlEnabled then return end
Wait(50)
local speed = GetEntitySpeed(cache.vehicle)
local currnetBodyHealth = GetVehicleBodyHealth(cache.vehicle)
if initBodyHealth - currnetBodyHealth >= 5 then
ClearPedTasks(cache.ped)
SendNUIMessage({
transactionType = 'forward_collision_warning'
})
isCruiseControlEnabled = false
break
end
local turningOrBraking = IsControlPressed(2, 76) or IsControlPressed(2, 63) or IsControlPressed(2, 64) or IsControlPressed(2, 72)
if not IsVehicleOnAllWheels(cache.vehicle) then
hands_on_steering_wheel()
end
-- if IsControlPressed(2, 71) then
-- SetVehicleForwardSpeed(cache.vehicle, speed + 0.6)
-- end
if turningOrBraking then
ClearPedTasks(cache.ped)
SendNUIMessage({
transactionType = 'autosteer_disabled'
})
isCruiseControlEnabled = false
break
end
end
end)
CreateThread(function()
while cache.vehicle do
if not isCruiseControlEnabled then return end
Wait(500)
if NOACoords then
local distance = #(GetEntityCoords(cache.vehicle) - NOACoords)
if distance <= 50 then
ClearPedTasks(cache.ped)
SendNUIMessage({
transactionType = 'noa_disabled'
})
isCruiseControlEnabled = false
return
end
end
end
end)
end
end
local keybindCruiseControl = lib.addKeybind({name = 'toggle_cruise_control', description = 'auto pilot', defaultKey = 'Y',
onPressed = function(self)
if cache.seat == -1 then
local vehicleClass = GetVehicleClass(cache.vehicle)
if vehicleClasses[vehicleClass] then
TriggerCruiseControl()
else
lib.notify({type = 'error', description = 'This vehicle class is not supported'})
end
end
end
})
return {
keybindCruiseControl = keybindCruiseControl -- possibility of apler to deactivate/activate
}