-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.lua
More file actions
122 lines (105 loc) · 3.31 KB
/
client.lua
File metadata and controls
122 lines (105 loc) · 3.31 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
local zoomFov = 20.0
local defaultFOV = GetGameplayCamFov()
local zoomCam = nil
local transitionTime = 150 -- The longer the transition time the more the camera will 'lag behind' when perpendicular to the player
local zoomActive = false
local zoomInProgress = false -- Not necessary to wait for zoom in / out to finish but may result in unfavourable results if spammed too quickly
local blockZoom = false
local function CreateZoomCamera()
local gpcCoords = GetGameplayCamCoord()
local gpcRot = GetGameplayCamRot(2)
zoomCam = CreateCamWithParams(
"DEFAULT_SCRIPTED_CAMERA",
gpcCoords.x, gpcCoords.y, gpcCoords.z,
gpcRot.x, gpcRot.y, gpcRot.z,
zoomFov,
true,
2
)
RenderScriptCams(true, true, transitionTime, true, true)
end
local function EnableZoom()
zoomActive = true
if zoomCam then
SetCamFov(zoomCam, zoomFov)
SetCamActive(zoomCam, true)
RenderScriptCams(true, true, transitionTime, true, true)
zoomInProgress = true
Wait(transitionTime)
zoomInProgress = false
else
CreateZoomCamera()
end
end
local function DisableZoom()
zoomActive = false
if zoomCam then
SetCamActive(zoomCam, false)
RenderScriptCams(false, true, transitionTime, true, true)
zoomInProgress = true
Wait(transitionTime)
zoomInProgress = false
end
end
local zoomInKeybind = lib.addKeybind({
name = 'zoom_in',
description = 'Zoom In',
defaultKey = 'IOM_WHEEL_UP',
defaultMapper = 'MOUSE_WHEEL',
onPressed = function(self)
if not IsPlayerFreeAiming(cache.playerId) and not blockZoom and not zoomInProgress then
EnableZoom()
end
end,
})
local zoomOutKeybind = lib.addKeybind({
name = 'zoom_out',
description = 'Zoom Out',
defaultKey = 'IOM_WHEEL_DOWN',
defaultMapper = 'MOUSE_WHEEL',
onPressed = function(self)
if not IsPlayerFreeAiming(cache.playerId) and not blockZoom and not zoomInProgress then
DisableZoom()
end
end,
})
CreateThread(function()
local wait = 100
while true do
if zoomCam then
local gpcCoords = GetGameplayCamCoord()
local gpcRot = GetGameplayCamRot(2)
SetCamCoord(zoomCam, gpcCoords.x, gpcCoords.y, gpcCoords.z)
SetCamRot(zoomCam, gpcRot.x, gpcRot.y, gpcRot.z, 2)
end
if IsPlayerFreeAiming(cache.playerId) and zoomActive then
DisableZoom()
end
if zoomActive then
wait = 0
else
wait = 100
end
Wait(wait)
end
end)
--
-- You will need to disable the zoom functionality in certain cases. i.e. no clip
-- An export would be better but meh good enough for now
--
RegisterNetEvent('zoom:updateBlock', function(blockUpdate)
blockZoom = blockUpdate
if blockUpdate and zoomCam then
DisableZoom()
end
end)
--[[
Note there is only 1 level of zoom, if you want to have
incremental zoom you may wish to apply this to the camera
for each increment of zoom level:
InterpolateCamWithParams(activeCam,
camPos.x, camPos.y, camPos.z,
camRot.x, camRot.y, camRot.z,
newFov, timeToZoom,
1, 1, 2, 1)
]]