forked from qbcore-framework/qb-policejob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractions.lua
464 lines (425 loc) · 17.9 KB
/
interactions.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
-- Variables
local isEscorting = false
-- Functions
exports('IsHandcuffed', function()
return isHandcuffed
end)
local function loadAnimDict(dict) -- interactions, job,
while (not HasAnimDictLoaded(dict)) do
RequestAnimDict(dict)
Wait(10)
end
end
local function IsTargetDead(playerId)
local retval = false
local hasReturned = false
QBCore.Functions.TriggerCallback('police:server:isPlayerDead', function(result)
retval = result
hasReturned = true
end, playerId)
while not hasReturned do
Wait(10)
end
return retval
end
local function HandCuffAnimation()
local ped = PlayerPedId()
if isHandcuffed == true then
TriggerServerEvent('InteractSound_SV:PlayOnSource', 'Cuff', 0.2)
else
TriggerServerEvent('InteractSound_SV:PlayOnSource', 'Uncuff', 0.2)
end
loadAnimDict('mp_arrest_paired')
Wait(100)
TaskPlayAnim(ped, 'mp_arrest_paired', 'cop_p2_back_right', 3.0, 3.0, -1, 48, 0, 0, 0, 0)
TriggerServerEvent('InteractSound_SV:PlayOnSource', 'Cuff', 0.2)
Wait(3500)
TaskPlayAnim(ped, 'mp_arrest_paired', 'exit', 3.0, 3.0, -1, 48, 0, 0, 0, 0)
end
local function GetCuffedAnimation(playerId)
local ped = PlayerPedId()
local cuffer = GetPlayerPed(GetPlayerFromServerId(playerId))
local heading = GetEntityHeading(cuffer)
TriggerServerEvent('InteractSound_SV:PlayOnSource', 'Cuff', 0.2)
loadAnimDict('mp_arrest_paired')
SetEntityCoords(ped, GetOffsetFromEntityInWorldCoords(cuffer, 0.0, 0.45, 0.0))
Wait(100)
SetEntityHeading(ped, heading)
TaskPlayAnim(ped, 'mp_arrest_paired', 'crook_p2_back_right', 3.0, 3.0, -1, 32, 0, 0, 0, 0, true, true, true)
Wait(2500)
end
-- Events
RegisterNetEvent('police:client:SetOutVehicle', function()
local ped = PlayerPedId()
if IsPedInAnyVehicle(ped, false) then
local vehicle = GetVehiclePedIsIn(ped, false)
TaskLeaveVehicle(ped, vehicle, 16)
end
end)
RegisterNetEvent('police:client:PutInVehicle', function()
local ped = PlayerPedId()
if isHandcuffed or isEscorted then
local vehicle = QBCore.Functions.GetClosestVehicle()
if DoesEntityExist(vehicle) then
for i = GetVehicleMaxNumberOfPassengers(vehicle), 0, -1 do
if IsVehicleSeatFree(vehicle, i) then
isEscorted = false
TriggerEvent('hospital:client:isEscorted', isEscorted)
ClearPedTasks(ped)
DetachEntity(ped, true, false)
Wait(100)
SetPedIntoVehicle(ped, vehicle, i)
return
end
end
end
end
end)
RegisterNetEvent('police:client:SearchPlayer', function()
local player, distance = QBCore.Functions.GetClosestPlayer()
if player ~= -1 and distance < 2.5 then
local playerId = GetPlayerServerId(player)
TriggerServerEvent('inventory:server:OpenInventory', 'otherplayer', playerId)
TriggerServerEvent('police:server:SearchPlayer', playerId)
else
QBCore.Functions.Notify(Lang:t('error.none_nearby'), 'error')
end
end)
RegisterNetEvent('police:client:SeizeCash', function()
local player, distance = QBCore.Functions.GetClosestPlayer()
if player ~= -1 and distance < 2.5 then
local playerId = GetPlayerServerId(player)
TriggerServerEvent('police:server:SeizeCash', playerId)
else
QBCore.Functions.Notify(Lang:t('error.none_nearby'), 'error')
end
end)
RegisterNetEvent('police:client:SeizeDriverLicense', function()
local player, distance = QBCore.Functions.GetClosestPlayer()
if player ~= -1 and distance < 2.5 then
local playerId = GetPlayerServerId(player)
TriggerServerEvent('police:server:SeizeDriverLicense', playerId)
else
QBCore.Functions.Notify(Lang:t('error.none_nearby'), 'error')
end
end)
RegisterNetEvent('police:client:RobPlayer', function()
local player, distance = QBCore.Functions.GetClosestPlayer()
local ped = PlayerPedId()
if player ~= -1 and distance < 2.5 then
local playerPed = GetPlayerPed(player)
local playerId = GetPlayerServerId(player)
if IsEntityPlayingAnim(playerPed, 'missminuteman_1ig_2', 'handsup_base', 3) or IsEntityPlayingAnim(playerPed, 'mp_arresting', 'idle', 3) or IsTargetDead(playerId) then
QBCore.Functions.Progressbar('robbing_player', Lang:t('progressbar.robbing'), math.random(5000, 7000), false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
animDict = 'random@shop_robbery',
anim = 'robbery_action_b',
flags = 16,
}, {}, {}, function() -- Done
local plyCoords = GetEntityCoords(playerPed)
local pos = GetEntityCoords(ped)
if #(pos - plyCoords) < 2.5 then
StopAnimTask(ped, 'random@shop_robbery', 'robbery_action_b', 1.0)
TriggerServerEvent('inventory:server:OpenInventory', 'otherplayer', playerId)
TriggerEvent('inventory:server:RobPlayer', playerId)
else
QBCore.Functions.Notify(Lang:t('error.none_nearby'), 'error')
end
end, function() -- Cancel
StopAnimTask(ped, 'random@shop_robbery', 'robbery_action_b', 1.0)
QBCore.Functions.Notify(Lang:t('error.canceled'), 'error')
end)
end
else
QBCore.Functions.Notify(Lang:t('error.none_nearby'), 'error')
end
end)
RegisterNetEvent('police:client:JailPlayer', function()
local player, distance = QBCore.Functions.GetClosestPlayer()
if player ~= -1 and distance < 2.5 then
local playerId = GetPlayerServerId(player)
local dialog = exports['qb-input']:ShowInput({
header = Lang:t('info.jail_time_input'),
submitText = Lang:t('info.submit'),
inputs = {
{
text = Lang:t('info.time_months'),
name = 'jailtime',
type = 'number',
isRequired = true
}
}
})
if tonumber(dialog['jailtime']) > 0 then
TriggerServerEvent('police:server:JailPlayer', playerId, tonumber(dialog['jailtime']))
else
QBCore.Functions.Notify(Lang:t('error.time_higher'), 'error')
end
else
QBCore.Functions.Notify(Lang:t('error.none_nearby'), 'error')
end
end)
RegisterNetEvent('police:client:BillPlayer', function()
local player, distance = QBCore.Functions.GetClosestPlayer()
if player ~= -1 and distance < 2.5 then
local playerId = GetPlayerServerId(player)
local dialog = exports['qb-input']:ShowInput({
header = Lang:t('info.bill'),
submitText = Lang:t('info.submit'),
inputs = {
{
text = Lang:t('info.amount'),
name = 'bill',
type = 'number',
isRequired = true
}
}
})
if tonumber(dialog['bill']) > 0 then
TriggerServerEvent('police:server:BillPlayer', playerId, tonumber(dialog['bill']))
else
QBCore.Functions.Notify(Lang:t('error.amount_higher'), 'error')
end
else
QBCore.Functions.Notify(Lang:t('error.none_nearby'), 'error')
end
end)
RegisterNetEvent('police:client:PutPlayerInVehicle', function()
local player, distance = QBCore.Functions.GetClosestPlayer()
if player ~= -1 and distance < 2.5 then
local playerId = GetPlayerServerId(player)
if not isHandcuffed and not isEscorted then
TriggerServerEvent('police:server:PutPlayerInVehicle', playerId)
end
else
QBCore.Functions.Notify(Lang:t('error.none_nearby'), 'error')
end
end)
RegisterNetEvent('police:client:SetPlayerOutVehicle', function()
local player, distance = QBCore.Functions.GetClosestPlayer()
if player ~= -1 and distance < 2.5 then
local playerId = GetPlayerServerId(player)
if not isHandcuffed and not isEscorted then
TriggerServerEvent('police:server:SetPlayerOutVehicle', playerId)
end
else
QBCore.Functions.Notify(Lang:t('error.none_nearby'), 'error')
end
end)
RegisterNetEvent('police:client:EscortPlayer', function()
local player, distance = QBCore.Functions.GetClosestPlayer()
if player ~= -1 and distance < 2.5 then
local playerId = GetPlayerServerId(player)
if not isHandcuffed and not isEscorted then
TriggerServerEvent('police:server:EscortPlayer', playerId)
end
else
QBCore.Functions.Notify(Lang:t('error.none_nearby'), 'error')
end
end)
RegisterNetEvent('police:client:KidnapPlayer', function()
local player, distance = QBCore.Functions.GetClosestPlayer()
if player ~= -1 and distance < 2.5 then
local playerId = GetPlayerServerId(player)
if not IsPedInAnyVehicle(GetPlayerPed(player)) then
if not isHandcuffed and not isEscorted then
TriggerServerEvent('police:server:KidnapPlayer', playerId)
end
end
else
QBCore.Functions.Notify(Lang:t('error.none_nearby'), 'error')
end
end)
RegisterNetEvent('police:client:CuffPlayerSoft', function()
if not IsPedRagdoll(PlayerPedId()) then
local player, distance = QBCore.Functions.GetClosestPlayer()
if player ~= -1 and distance < 1.5 then
local playerId = GetPlayerServerId(player)
if not IsPedInAnyVehicle(GetPlayerPed(player)) and not IsPedInAnyVehicle(PlayerPedId()) then
TriggerServerEvent('police:server:CuffPlayer', playerId, true)
HandCuffAnimation()
else
QBCore.Functions.Notify(Lang:t('error.vehicle_cuff'), 'error')
end
else
QBCore.Functions.Notify(Lang:t('error.none_nearby'), 'error')
end
else
Wait(2000)
end
end)
RegisterNetEvent('police:client:CuffPlayer', function()
if not IsPedRagdoll(PlayerPedId()) then
local player, distance = QBCore.Functions.GetClosestPlayer()
if player ~= -1 and distance < 1.5 then
local result = QBCore.Functions.HasItem(Config.HandCuffItem)
if result then
local playerId = GetPlayerServerId(player)
if not IsPedInAnyVehicle(GetPlayerPed(player)) and not IsPedInAnyVehicle(PlayerPedId()) then
TriggerServerEvent('police:server:CuffPlayer', playerId, false)
HandCuffAnimation()
else
QBCore.Functions.Notify(Lang:t('error.vehicle_cuff'), 'error')
end
else
QBCore.Functions.Notify(Lang:t('error.no_cuff'), 'error')
end
else
QBCore.Functions.Notify(Lang:t('error.none_nearby'), 'error')
end
else
Wait(2000)
end
end)
RegisterNetEvent('police:client:GetEscorted', function(playerId)
local ped = PlayerPedId()
QBCore.Functions.GetPlayerData(function(PlayerData)
if PlayerData.metadata['isdead'] or isHandcuffed or PlayerData.metadata['inlaststand'] then
if not isEscorted then
isEscorted = true
local dragger = GetPlayerPed(GetPlayerFromServerId(playerId))
SetEntityCoords(ped, GetOffsetFromEntityInWorldCoords(dragger, 0.0, 0.45, 0.0))
AttachEntityToEntity(ped, dragger, 11816, 0.45, 0.45, 0.0, 0.0, 0.0, 0.0, false, false, false, false, 2, true)
else
isEscorted = false
DetachEntity(ped, true, false)
end
TriggerEvent('hospital:client:isEscorted', isEscorted)
end
end)
end)
RegisterNetEvent('police:client:DeEscort', function()
isEscorted = false
TriggerEvent('hospital:client:isEscorted', isEscorted)
DetachEntity(PlayerPedId(), true, false)
end)
RegisterNetEvent('police:client:GetKidnappedTarget', function(playerId)
local ped = PlayerPedId()
QBCore.Functions.GetPlayerData(function(PlayerData)
if PlayerData.metadata['isdead'] or PlayerData.metadata['inlaststand'] or isHandcuffed then
if not isEscorted then
isEscorted = true
local dragger = GetPlayerPed(GetPlayerFromServerId(playerId))
RequestAnimDict('nm')
while not HasAnimDictLoaded('nm') do
Wait(10)
end
AttachEntityToEntity(ped, dragger, 0, 0.27, 0.15, 0.63, 0.5, 0.5, 0.0, false, false, false, false, 2, false)
TaskPlayAnim(ped, 'nm', 'firemans_carry', 8.0, -8.0, 100000, 33, 0, false, false, false)
else
isEscorted = false
DetachEntity(ped, true, false)
ClearPedTasksImmediately(ped)
end
TriggerEvent('hospital:client:isEscorted', isEscorted)
end
end)
end)
RegisterNetEvent('police:client:GetKidnappedDragger', function()
QBCore.Functions.GetPlayerData(function(_)
if not isEscorting then
local dragger = PlayerPedId()
RequestAnimDict('missfinale_c2mcs_1')
while not HasAnimDictLoaded('missfinale_c2mcs_1') do
Wait(10)
end
TaskPlayAnim(dragger, 'missfinale_c2mcs_1', 'fin_c2_mcs_1_camman', 8.0, -8.0, 100000, 49, 0, false, false, false)
isEscorting = true
else
local dragger = PlayerPedId()
ClearPedSecondaryTask(dragger)
ClearPedTasksImmediately(dragger)
isEscorting = false
end
TriggerEvent('hospital:client:SetEscortingState', isEscorting)
TriggerEvent('qb-kidnapping:client:SetKidnapping', isEscorting)
end)
end)
RegisterNetEvent('police:client:GetCuffed', function(playerId, isSoftcuff)
local ped = PlayerPedId()
if not isHandcuffed then
isHandcuffed = true
TriggerServerEvent('police:server:SetHandcuffStatus', true)
ClearPedTasksImmediately(ped)
if GetSelectedPedWeapon(ped) ~= `WEAPON_UNARMED` then
SetCurrentPedWeapon(ped, `WEAPON_UNARMED`, true)
end
if not isSoftcuff then
cuffType = 16
GetCuffedAnimation(playerId)
QBCore.Functions.Notify(Lang:t('info.cuff'), 'primary')
else
cuffType = 49
GetCuffedAnimation(playerId)
QBCore.Functions.Notify(Lang:t('info.cuffed_walk'), 'primary')
end
else
isHandcuffed = false
isEscorted = false
TriggerEvent('hospital:client:isEscorted', isEscorted)
DetachEntity(ped, true, false)
TriggerServerEvent('police:server:SetHandcuffStatus', false)
ClearPedTasksImmediately(ped)
TriggerServerEvent('InteractSound_SV:PlayOnSource', 'Uncuff', 0.2)
QBCore.Functions.Notify(Lang:t('success.uncuffed'), 'success')
end
end)
-- Threads
CreateThread(function()
while true do
Wait(1)
if isEscorted then
DisableAllControlActions(0)
EnableControlAction(0, 1, true)
EnableControlAction(0, 2, true)
EnableControlAction(0, 245, true)
EnableControlAction(0, 38, true)
EnableControlAction(0, 322, true)
EnableControlAction(0, 249, true)
EnableControlAction(0, 46, true)
end
if isHandcuffed then
DisableControlAction(0, 24, true) -- Attack
DisableControlAction(0, 257, true) -- Attack 2
DisableControlAction(0, 25, true) -- Aim
DisableControlAction(0, 263, true) -- Melee Attack 1
DisableControlAction(0, 45, true) -- Reload
DisableControlAction(0, 22, true) -- Jump
DisableControlAction(0, 44, true) -- Cover
DisableControlAction(0, 37, true) -- Select Weapon
DisableControlAction(0, 23, true) -- Also 'enter'?
DisableControlAction(0, 288, true) -- Disable phone
DisableControlAction(0, 289, true) -- Inventory
DisableControlAction(0, 170, true) -- Animations
DisableControlAction(0, 167, true) -- Job
DisableControlAction(0, 26, true) -- Disable looking behind
DisableControlAction(0, 73, true) -- Disable clearing animation
DisableControlAction(2, 199, true) -- Disable pause screen
DisableControlAction(0, 59, true) -- Disable steering in vehicle
DisableControlAction(0, 71, true) -- Disable driving forward in vehicle
DisableControlAction(0, 72, true) -- Disable reversing in vehicle
DisableControlAction(2, 36, true) -- Disable going stealth
DisableControlAction(0, 264, true) -- Disable melee
DisableControlAction(0, 257, true) -- Disable melee
DisableControlAction(0, 140, true) -- Disable melee
DisableControlAction(0, 141, true) -- Disable melee
DisableControlAction(0, 142, true) -- Disable melee
DisableControlAction(0, 143, true) -- Disable melee
DisableControlAction(0, 75, true) -- Disable exit vehicle
DisableControlAction(27, 75, true) -- Disable exit vehicle
EnableControlAction(0, 249, true) -- Added for talking while cuffed
EnableControlAction(0, 46, true) -- Added for talking while cuffed
if (not IsEntityPlayingAnim(PlayerPedId(), 'mp_arresting', 'idle', 3) and not IsEntityPlayingAnim(PlayerPedId(), 'mp_arrest_paired', 'crook_p2_back_right', 3)) and not QBCore.Functions.GetPlayerData().metadata['isdead'] then
loadAnimDict('mp_arresting')
TaskPlayAnim(PlayerPedId(), 'mp_arresting', 'idle', 8.0, -8, -1, cuffType, 0, 0, 0, 0)
end
end
if not isHandcuffed and not isEscorted then
Wait(2000)
end
end
end)