-
Notifications
You must be signed in to change notification settings - Fork 9
/
client.lua
215 lines (193 loc) · 8.21 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
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
local ESX = exports['es_extended']:getSharedObject()
local active = false
local photoactive = false
local cameraprop = nil
local frontCam = false
local photoprop = nil
local streetName
local fov_max = 70.0
local fov_min = 5.0 -- max zoom level (smaller fov is more zoom)
local zoomspeed = 10.0 -- camera zoom speed
local speed_lr = 8.0 -- speed by which the camera pans left-right
local speed_ud = 8.0 -- speed by which the camera pans up-down
local fov = (fov_max+fov_min)*0.5
local presstake = false
local function SharedRequestAnimDict(animDict, cb)
if not HasAnimDictLoaded(animDict) then
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
Citizen.Wait(1)
end
end
if cb ~= nil then
cb()
end
end
local function LoadPropDict(model)
while not HasModelLoaded(GetHashKey(model)) do
RequestModel(GetHashKey(model))
Wait(10)
end
end
local function FullClose()
active = false
presstake = false
if cameraprop then DeleteEntity(cameraprop) end
ClearPedTasks(PlayerPedId())
end
--FUNCTIONS--
function HideHUDThisFrame()
HideHelpTextThisFrame()
HideHudAndRadarThisFrame()
HideHudComponentThisFrame(1) -- Wanted Stars
HideHudComponentThisFrame(2) -- Weapon icon
HideHudComponentThisFrame(3) -- Cash
HideHudComponentThisFrame(4) -- MP CASH
HideHudComponentThisFrame(6)
HideHudComponentThisFrame(7)
HideHudComponentThisFrame(8)
HideHudComponentThisFrame(9)
HideHudComponentThisFrame(13) -- Cash Change
HideHudComponentThisFrame(11) -- Floating Help Text
HideHudComponentThisFrame(12) -- more floating help text
HideHudComponentThisFrame(15) -- Subtitle Text
HideHudComponentThisFrame(18) -- Game Stream
HideHudComponentThisFrame(19) -- weapon wheel
end
function CheckInputRotation(cam, zoomvalue)
local rightAxisX = GetDisabledControlNormal(0, 220)
local rightAxisY = GetDisabledControlNormal(0, 221)
local rotation = GetCamRot(cam, 2)
if rightAxisX ~= 0.0 or rightAxisY ~= 0.0 then
new_z = rotation.z + rightAxisX*-1.0*(speed_ud)*(zoomvalue+0.1)
new_x = math.max(math.min(20.0, rotation.x + rightAxisY*-1.0*(speed_lr)*(zoomvalue+0.1)), -89.5)
SetCamRot(cam, new_x, 0.0, new_z, 2)
SetEntityHeading(PlayerPedId(),new_z)
end
end
function HandleZoom(cam)
local lPed = PlayerPedId()
if not ( IsPedSittingInAnyVehicle( lPed ) ) then
if IsControlJustPressed(0,241) then
fov = math.max(fov - zoomspeed, fov_min)
end
if IsControlJustPressed(0,242) then
fov = math.min(fov + zoomspeed, fov_max)
end
local current_fov = GetCamFov(cam)
if math.abs(fov-current_fov) < 0.1 then
fov = current_fov
end
SetCamFov(cam, current_fov + (fov - current_fov)*0.05)
else
if IsControlJustPressed(0,17) then
fov = math.max(fov - zoomspeed, fov_min)
end
if IsControlJustPressed(0,16) then
fov = math.min(fov + zoomspeed, fov_max)
end
local current_fov = GetCamFov(cam)
if math.abs(fov-current_fov) < 0.1 then
fov = current_fov
end
SetCamFov(cam, current_fov + (fov - current_fov)*0.05)
end
end
RegisterNetEvent("wert-camera:client:use-camera", function()
if IsPedInAnyVehicle(PlayerPedId(), false) then
ESX.ShowNotification('You can`t use camera in car!')
else
if not active then
active = true
local ped = PlayerPedId()
SharedRequestAnimDict("amb@world_human_paparazzi@male@base", function()
TaskPlayAnim(ped, "amb@world_human_paparazzi@male@base", "base", 2.0, 2.0, -1, 1, 0, false, false, false)
end)
local x,y,z = table.unpack(GetEntityCoords(ped))
if not HasModelLoaded("prop_pap_camera_01") then
LoadPropDict("prop_pap_camera_01")
end
cameraprop = CreateObject(GetHashKey("prop_pap_camera_01"), x, y, z+0.2, true, true, true)
AttachEntityToEntity(cameraprop, ped, GetPedBoneIndex(ped, 28422), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, true, true, false, true, 1, true)
SetModelAsNoLongerNeeded("prop_pap_camera_01")
CreateThread(function()
while active do
Wait(200)
local lPed = PlayerPedId()
local vehicle = GetVehiclePedIsIn(lPed)
local pCoords = GetEntityCoords(lPed)
streetName, street2 = GetStreetNameAtCoord(pCoords.x, pCoords.y, pCoords.z)
streetName = GetStreetNameFromHashKey(streetName) .. ' | ' .. GetStreetNameFromHashKey(street2)
if active then
active = true
Wait(500)
SetTimecycleModifier("default")
SetTimecycleModifierStrength(0.3)
local cam = CreateCam("DEFAULT_SCRIPTED_FLY_CAMERA", true)
AttachCamToEntity(cam, lPed, 0.0, 1.0, 1.0, true)
SetCamRot(cam, 0.0,0.0,GetEntityHeading(lPed))
SetCamFov(cam, fov)
RenderScriptCams(true, false, 0, 1, 0)
while active and not IsEntityDead(lPed) and (GetVehiclePedIsIn(lPed) == vehicle) and true do
if IsControlJustPressed(0, 177) then
PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
FullClose()
elseif IsControlJustPressed(1, 176) then
if not presstake then
presstake = true
ESX.TriggerServerCallback("wert-camera:server:webhook", function(hook)
if hook then
exports['screenshot-basic']:requestScreenshotUpload(tostring(hook), "files[]", function(data)
local image = json.decode(data)
FullClose()
TriggerServerEvent("wert-camera:server:add-photo-item", json.encode(image.attachments[1].proxy_url), streetName)
end)
end
end)
end
end
local zoomvalue = (1.0/(fov_max-fov_min))*(fov-fov_min)
CheckInputRotation(cam, zoomvalue)
HandleZoom(cam)
HideHUDThisFrame()
Wait(1)
end
FullClose()
ClearTimecycleModifier()
fov = (fov_max+fov_min)*0.5
RenderScriptCams(false, false, 0, 1, 0)
DestroyCam(cam, false)
SetNightvision(false)
SetSeethrough(false)
end
end
end)
else
FullClose()
end
end
end)
RegisterNetEvent("wert-camera:client:use-photo", function(url1)
if not photoactive then
photoactive = true
SetNuiFocus(true, true)
SendNUIMessage({action = "Show", photo = url1})
local ped = PlayerPedId()
SharedRequestAnimDict("amb@world_human_tourist_map@male@base", function()
TaskPlayAnim(ped, "amb@world_human_tourist_map@male@base", "base", 2.0, 2.0, -1, 1, 0, false, false, false)
end)
local x,y,z = table.unpack(GetEntityCoords(ped))
if not HasModelLoaded("prop_tourist_map_01") then
LoadPropDict("prop_tourist_map_01")
end
photoprop = CreateObject(GetHashKey("prop_tourist_map_01"), x, y, z+0.2, true, true, true)
AttachEntityToEntity(photoprop, ped, GetPedBoneIndex(ped, 28422), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, true, true, false, true, 1, true)
SetModelAsNoLongerNeeded("prop_tourist_map_01")
end
end)
RegisterNUICallback("Close", function()
SetNuiFocus(false, false)
photoactive = false
if photoprop then DeleteEntity(photoprop) end
ClearPedTasks(PlayerPedId())
end)