-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
65 lines (57 loc) · 1.84 KB
/
main.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
GHOST_KEY = 'x'
function updateZ()
local velocity = localVehicle.velocity
velocity.z = z
localVehicle.velocity = velocity
end
function toggleGhost(bool)
enabled = bool
if enabled then
z = localVehicle.velocity.z
addEventHandler('onClientRender', root, updateZ)
else
removeEventHandler('onClientRender', root, updateZ)
end
triggerServerEvent('onClientToggleGhost', localVehicle)
setCameraClip(not enabled, not enabled)
end
function handleGhostKey(key, keyState)
if localVehicle then
if not enabled and keyState == 'down' then
toggleGhost(true)
elseif enabled and keyState == 'up' then
toggleGhost(false)
end
end
end
function newVehicle(vehicle, seat)
if seat == 0 then
localVehicle = vehicle
addEventHandler('onClientVehicleExplode', localVehicle, noVehicle)
addEventHandler('onClientElementDestroy', localVehicle, noVehicle)
addEventHandler('onClientVehicleStartExit', localVehicle, noVehicle)
end
end
addEventHandler('onClientPlayerVehicleEnter', localPlayer, newVehicle)
function noVehicle()
removeEventHandler('onClientVehicleExplode', localVehicle, noVehicle)
removeEventHandler('onClientElementDestroy', localVehicle, noVehicle)
removeEventHandler('onClientVehicleStartExit', localVehicle, noVehicle)
if enabled then
toggleGhost(false)
end
localVehicle = nil
end
function resourceStart()
if localPlayer.vehicle then
newVehicle(localPlayer.vehicle, localPlayer.vehicleSeat)
end
bindKey(GHOST_KEY, 'both', handleGhostKey)
end
addEventHandler('onClientResourceStart', resourceRoot, resourceStart)
function resourceStop()
if localVehicle and enabled then
toggleGhost(false)
end
end
addEventHandler('onClientResourceStop', resourceRoot, resourceStop)