@@ -19,9 +19,8 @@ local areKeysJobShared = functions.areKeysJobShared
19
19
---- -------------------
20
20
21
21
local isTakingKeys = false
22
- local isCarjacking = false
23
22
local isHotwiring = false
24
- local canCarjack = true
23
+ local isCarjackingAvailable = true
25
24
26
25
---- -------------------
27
26
---- Functions ----
@@ -201,9 +200,9 @@ local function showHotwiringLabel()
201
200
end
202
201
203
202
local function carjackVehicle (target )
204
- if not config . carjackEnable then return end
205
- isCarjacking = true
206
- canCarjack = false
203
+ if not isCarjackingAvailable then return end
204
+ isCarjackingAvailable = false
205
+ local isCarjacking = true
207
206
local vehicle = GetVehiclePedIsUsing (target )
208
207
local occupants = getPedsInVehicle (vehicle )
209
208
@@ -244,10 +243,9 @@ local function carjackVehicle(target)
244
243
car = true ,
245
244
},
246
245
}) then
247
- local hasWeapon , weaponHash = GetCurrentPedWeapon (cache .ped , true )
248
- if hasWeapon and isCarjacking then
246
+ if cache .weapon and isCarjacking then
249
247
local carjackChance = 0.5
250
- local chance = config .carjackChance [GetWeapontypeGroup (weaponHash ) --[[ @as string]] ]
248
+ local chance = config .carjackChance [GetWeapontypeGroup (cache . weapon ) --[[ @as string]] ]
251
249
if chance then
252
250
carjackChance = chance
253
251
end
@@ -285,7 +283,7 @@ local function carjackVehicle(target)
285
283
end
286
284
287
285
Wait (config .delayBetweenCarjackingsInMs )
288
- canCarjack = true
286
+ isCarjackingAvailable = true
289
287
end
290
288
291
289
local function toggleEngine ()
@@ -296,48 +294,40 @@ local function toggleEngine()
296
294
end
297
295
end
298
296
299
- ---- -------------------
300
- ---- Threads ----
301
- ---- -------------------
302
-
303
- if config .carjackEnable then
297
+ local function watchCarjackingAttempts ()
304
298
CreateThread (function ()
305
- while true do
306
- if LocalPlayer .state .isLoggedIn then
307
- if canCarjack then
308
- local aiming , target = GetEntityPlayerIsFreeAimingAt (cache .playerId )
309
- if aiming
310
- and target
311
- and target ~= 0
312
- and DoesEntityExist (target )
313
- and IsPedInAnyVehicle (target , false )
314
- and not IsEntityDead (target )
315
- and not IsPedAPlayer (target )
316
- then
317
- local targetveh = GetVehiclePedIsIn (target , false )
318
- local carIsImmune = false
319
- for i = 1 , # config .immuneVehicles do
320
- if GetEntityModel (targetveh ) == joaat (config .immuneVehicles [i ]) then
321
- carIsImmune = true
322
- end
299
+ while cache .weapon do
300
+ if isCarjackingAvailable then
301
+ local aiming , target = GetEntityPlayerIsFreeAimingAt (cache .playerId )
302
+ if aiming
303
+ and target
304
+ and target ~= 0
305
+ and DoesEntityExist (target )
306
+ and IsPedInAnyVehicle (target , false )
307
+ and not IsEntityDead (target )
308
+ and not IsPedAPlayer (target )
309
+ then
310
+ local targetveh = GetVehiclePedIsIn (target , false )
311
+ local isVehicleImmune = false
312
+ for i = 1 , # config .immuneVehicles do
313
+ if GetEntityModel (targetveh ) == joaat (config .immuneVehicles [i ]) then
314
+ isVehicleImmune = true
323
315
end
316
+ end
324
317
325
- if not carIsImmune
326
- and GetPedInVehicleSeat (targetveh , - 1 ) == target
327
- and not isBlacklistedWeapon ()
328
- then
329
- local pos = GetEntityCoords (cache .ped )
330
- local targetpos = GetEntityCoords (target )
331
- if # (pos - targetpos ) < 5.0 and not carIsImmune then
332
- carjackVehicle (target )
333
- end
318
+ if not isVehicleImmune
319
+ and GetPedInVehicleSeat (targetveh , - 1 ) == target
320
+ and not isBlacklistedWeapon ()
321
+ then
322
+ local pos = GetEntityCoords (cache .ped )
323
+ local targetpos = GetEntityCoords (target )
324
+ if # (pos - targetpos ) < 5.0 and not isVehicleImmune then
325
+ carjackVehicle (target )
334
326
end
335
327
end
336
328
end
337
- Wait (100 )
338
- else
339
- Wait (1000 )
340
329
end
330
+ Wait (100 )
341
331
end
342
332
end )
343
333
end
@@ -371,11 +361,6 @@ engineBind = lib.addKeybind({
371
361
end
372
362
})
373
363
374
- AddEventHandler (' ox_lib:cache:vehicle' , function ()
375
- showHotwiringLabel ()
376
- end )
377
- showHotwiringLabel ()
378
-
379
364
RegisterNetEvent (' QBCore:Client:VehicleInfo' , function (data )
380
365
if not LocalPlayer .state .isLoggedIn and data .event ~= ' Entering' then return end
381
366
if isBlacklistedVehicle (data .vehicle ) then return end
@@ -425,7 +410,12 @@ RegisterNetEvent('QBCore:Client:VehicleInfo', function(data)
425
410
end
426
411
end
427
412
-- Parked car logic
428
- elseif driver == 0 and not Entity (data .vehicle ).state .isOpen and not hasKeys (plate ) and not isTakingKeys and not Entity (data .vehicle ).state .vehicleid then
413
+ elseif driver == 0 and
414
+ not (isTakingKeys
415
+ or Entity (data .vehicle ).state .isOpen
416
+ or Entity (data .vehicle ).state .vehicleid
417
+ or hasKeys (plate ))
418
+ then
429
419
TriggerServerEvent (' qb-vehiclekeys:server:setVehLockState' , data .netId , config .lockNPCParkedCars and 2 or 1 )
430
420
end
431
421
end )
@@ -466,6 +456,27 @@ RegisterNetEvent('lockpicks:UseLockpick', function(isAdvanced)
466
456
end
467
457
end )
468
458
459
+ AddEventHandler (' ox_lib:cache:vehicle' , function ()
460
+ showHotwiringLabel ()
461
+ end )
462
+
463
+
464
+ if config .carjackEnable then
465
+ AddEventHandler (' ox_lib:cache:weapon' , function ()
466
+ watchCarjackingAttempts ()
467
+ end )
468
+ end
469
+
470
+ AddEventHandler (' onResourceStart' , function (resourceName )
471
+ if (GetCurrentResourceName () ~= resourceName ) then return end
472
+
473
+ showHotwiringLabel ()
474
+
475
+ if config .carjackEnable then
476
+ watchCarjackingAttempts ()
477
+ end
478
+ end )
479
+
469
480
-- #region Backwards Compatibility ONLY -- Remove at some point --
470
481
RegisterNetEvent (' qb-vehiclekeys:client:AddKeys' , function (plate )
471
482
TriggerServerEvent (' qb-vehiclekeys:server:AcquireVehicleKeys' , plate )
0 commit comments