-
Notifications
You must be signed in to change notification settings - Fork 6
/
vehicleCruise.lua
61 lines (57 loc) · 1.51 KB
/
vehicleCruise.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
local cruise = false
local timer = false
local speed = 0
function togCruise()
if (cruise) then
local veh = getPedOccupiedVehicle(localPlayer)
if (not veh or not isElement(veh)) then return false end
local v1,v2,v3 = getElementVelocity(veh)
local currspeed = (v1^2 + v2^2 + v3^2)^(0.5)
if (currspeed < speed) then
setPedControlState("accelerate", true)
else
setPedControlState("accelerate", false)
end
end
end
function cruiseNow()
local veh = getPedOccupiedVehicle(localPlayer)
if (not veh or not isElement(veh)) then return false end
if (getVehicleOccupant(veh, 0) ~= localPlayer or not getVehicleOccupant(veh, 0)) then
return false
end
if (not cruise) then
cruise = true
local speedx,speedy,speedz = getElementVelocity(veh)
speed = (speedx^2 + speedy^2 + speedz^2)^(0.5)
timer = setTimer(togCruise, 50, 0)
exports.UCDdx:add("cruise", "Cruising", 255, 255, 255)
else
cruise = false
killTimer(timer)
speed = 0
setPedControlState("accelerate", false)
exports.UCDdx:del("cruise")
end
end
bindKey("c", "up", cruiseNow)
function exitVeh(player)
if (cruise and player == localPlayer) then
cruise = false
killTimer(timer)
speed = 0
setPedControlState("accelerate", false)
exports.UCDdx:del("cruise")
end
end
addEventHandler("onClientVehicleExit", root, exitVeh)
function diedVeh()
if (cruise) then
cruise = false
killTimer(timer)
speed = 0
setPedControlState("accelerate", false)
exports.UCDdx:del("cruise")
end
end
addEventHandler("onClientPlayerWasted", localPlayer, diedVeh)