Repository navigation
Expand file tree
/
Copy pathclient.lua
More file actions
239 lines (220 loc) · 11.3 KB
/
Copy pathclient.lua
File metadata and controls
239 lines (220 loc) · 11.3 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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
local pendingData = nil
RegisterNetEvent('nova-pausemenu:client:data', function(data)
local cb = pendingData
pendingData = nil
if cb then cb(data) end
end)
local function requestMenuData(cb)
local finished = false
local function finish(data)
if finished then return end
finished = true
if pendingData == finish then pendingData = nil end
cb(data)
end
pendingData = finish
TriggerServerEvent('nova-pausemenu:server:requestData')
SetTimeout(5000, function()
finish(nil)
end)
end
local menuOpen = false
local isOpening = false
local cam = nil
local mapState = 'none' -- 'none' | 'pending' | 'shown'
local scenarioStarted = false
-- ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
-- HUD Hide/Show
-- ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
local function HudVisible(show)
-- Nova HUD
if GetResourceState('nova-hud') == 'started' then
if show then
pcall(function() exports['nova-hud']:pmShow() end)
pcall(function() exports['nova-hud']:showHud() end)
else
pcall(function() exports['nova-hud']:pmHide() end)
pcall(function() exports['nova-hud']:hideHud() end)
end
-- Standart QBCore HUD
elseif GetResourceState('qb-hud') == 'started' then
pcall(function() exports['qb-hud']:HideHud(not show) end)
-- Project Sloth HUD
elseif GetResourceState('ps-hud') == 'started' then
pcall(function() exports['ps-hud']:ToggleHud(show) end)
end
-- Pusula / Compass
if GetResourceState('compass') == 'started' then
pcall(function() exports['compass']:setVisible(show) end)
end
end
-- ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
-- Character Cinema (Camera)
-- ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
-- Is it safe to play a standing scenario on this ped right now?
-- IsPedOnFoot is false while in / entering / exiting a vehicle, falling, ragdolling or
-- swimming. Playing the scenario during a vehicle transition (e.g. a quick ESC mid-entry)
-- glitches the ped through the map, so we gate strictly on a settled on-foot state.
local function PedCanScenario(ped)
return IsPedOnFoot(ped)
and not IsPedInAnyVehicle(ped, true) -- true = also counts get-in/out stage
and GetVehiclePedIsEntering(ped) == 0
and not IsPedRagdoll(ped)
and not IsPedFalling(ped)
end
local function StartCam()
if not Config.ShowCharacter then return end
local ped = PlayerPedId()
local dist = Config.CamDistance or 2.2
cam = CreateCam('DEFAULT_SCRIPTED_CAMERA', true)
local veh = GetVehiclePedIsIn(ped, false)
if veh ~= 0 then
AttachCamToEntity(cam, veh, -dist, 0.0, Config.CamHeight or 0.55, true)
PointCamAtEntity(cam, ped, 0.0, 0.0, Config.CamLookZ or 0.45, true)
else
local pc = GetEntityCoords(ped)
local fwd = GetEntityForwardVector(ped)
local camX = pc.x + fwd.x * dist
local camY = pc.y + fwd.y * dist
local camZ = pc.z + (Config.CamHeight or 0.55)
SetCamCoord(cam, camX, camY, camZ)
PointCamAtCoord(cam, pc.x, pc.y, pc.z + (Config.CamLookZ or 0.45))
end
SetCamFov(cam, Config.CamFov or 38.0)
SetCamActive(cam, true)
RenderScriptCams(true, true, 400, true, true)
scenarioStarted = false
if Config.CharacterScenario and Config.CharacterScenario ~= ''
and PedCanScenario(ped) then
TaskStartScenarioInPlace(ped, Config.CharacterScenario, 0, true)
scenarioStarted = true
end
end
local function StopCam()
if cam then
RenderScriptCams(false, true, 300, true, true)
DestroyCam(cam, false)
cam = nil
end
-- Only clear if we started a scenario and are still on foot.
-- (Condition IsPedOnFoot as ClearPedTasksImmediately can throw the pad in the vehicle.)
if scenarioStarted and IsPedOnFoot(PlayerPedId()) then
ClearPedTasksImmediately(PlayerPedId())
end
scenarioStarted = false
end
-- ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
-- Menu Transactions
-- ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
local function CloseMenu()
if not menuOpen then return end
menuOpen = false
isOpening = false
SetNuiFocus(false, false)
SendNUIMessage({ action = 'close' })
StopCam()
HudVisible(true)
end
local function OpenMenu()
if menuOpen or isOpening then return end
isOpening = true
requestMenuData(function(data)
isOpening = false
if not data then return end
menuOpen = true
HudVisible(false)
StartCam()
SetNuiFocus(true, true)
SendNUIMessage({ action = 'open', data = data })
end)
end
-- Hide HUD in every frame when the menu is open (to avoid leaking speedometer etc.)
CreateThread(function()
while true do
if menuOpen then
HideHudAndRadarThisFrame()
Wait(0)
else
Wait(300)
end
end
end)
-- ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
-- Key Controls and Triggers
-- ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
-- GTA Pause Menu Suppression + Map Status Machine
CreateThread(function()
while true do
Wait(0)
if IsPauseMenuActive() then
if mapState ~= 'none' then
mapState = 'shown' -- Native map shown, don't touch
elseif not menuOpen then
SetFrontendActive(false)
OpenMenu()
else
SetFrontendActive(false)
end
else
if mapState == 'shown' then mapState = 'none' end -- Map closed
Wait(150)
end
end
end)
-- Closing the Menu with ESC or Cellphone Cancel (Backup)
CreateThread(function()
while true do
if menuOpen then
Wait(0)
if IsControlJustPressed(0, 200) or IsControlJustPressed(0, 322) then
CloseMenu()
end
else
Wait(250)
end
end
end)
-- ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
-- NUI Callback Definitions
-- ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
RegisterNUICallback('close', function(_, cb)
CloseMenu()
cb('ok')
end)
RegisterNUICallback('disconnect', function(_, cb)
CloseMenu()
TriggerServerEvent('nova-pausemenu:server:disconnect')
cb('ok')
end)
-- Native GTA menu. Map uses the multiplayer pause page. Settings uses the landing menu.
RegisterNUICallback('openNative', function(data, cb)
local which = data and data.which or 'map'
CloseMenu()
mapState = 'pending'
cb('ok')
CreateThread(function()
if which == 'settings' then
ActivateFrontendMenu(GetHashKey('FE_MENU_VERSION_LANDING_MENU'), false, -1)
else
ActivateFrontendMenu(GetHashKey('FE_MENU_VERSION_MP_PAUSE'), false, -1)
end
local deadline = GetGameTimer() + 1000
while not IsPauseMenuActive() and GetGameTimer() < deadline do
Wait(0)
end
if which == 'map' and IsPauseMenuActive() then
PauseMenuceptionGoDeeper(0)
end
end)
end)
AddEventHandler('onResourceStop', function(res)
if res == GetCurrentResourceName() and menuOpen then
SetNuiFocus(false, false)
StopCam()
HudVisible(true)
end
end)
-- Exports (For other scripts)
exports('OpenMenu', OpenMenu)
exports('CloseMenu', CloseMenu)
exports('IsOpen', function() return menuOpen end)