From 8d93d3051f7f8f18ebb938c0c47b8abf44661573 Mon Sep 17 00:00:00 2001 From: t0xicVybez Date: Tue, 17 Dec 2024 17:41:22 -0800 Subject: [PATCH 1/4] fix for pressing F then pulling weapon to start carjack Fixed so you no longer have to flex F first then draw your weapon to start the carjacking proccess. Also adding the ability to configure peds to fight back. New behavior Point gun at driver Script then does a Chance the ped will getout and pull a gun and start shooting, If ped does and dies Carjacking = failed. If ped doesnt exit with a weapon they exit then flee giving you keys. --- client/main.lua | 91 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 16 deletions(-) diff --git a/client/main.lua b/client/main.lua index 436e327..f1558b7 100644 --- a/client/main.lua +++ b/client/main.lua @@ -252,10 +252,8 @@ RegisterNetEvent('qb-vehiclekeys:client:GiveKeys', function(id) end end) -RegisterNetEvent('QBCore:Client:VehicleInfo', function(data) - if data.event == 'Entering' then - robKeyLoop() - end +RegisterNetEvent('QBCore:Client:EnteringVehicle', function() + robKeyLoop() end) RegisterNetEvent('qb-weapons:client:DrawWeapon', function() @@ -642,7 +640,7 @@ function CarjackVehicle(target) isCarjacking = true canCarjack = false loadAnimDict('mp_am_hold_up') - local vehicle = GetVehiclePedIsUsing(target) + local vehicle = GetVehiclePedIsIn(target, false) local occupants = GetPedsInVehicle(vehicle) for p = 1, #occupants do local ped = occupants[p] @@ -676,22 +674,50 @@ function CarjackVehicle(target) carjackChance = 0.5 end if math.random() <= carjackChance then - local plate = QBCore.Functions.GetPlate(vehicle) - for p = 1, #occupants do - local ped = occupants[p] + -- Check if ped fights back + if math.random() <= Config.PedDefenseChance then + -- Make the ped defend themselves + local plate = QBCore.Functions.GetPlate(vehicle) CreateThread(function() FreezeEntityPosition(vehicle, false) SetVehicleUndriveable(vehicle, false) - TaskLeaveVehicle(ped, vehicle, 0) - PlayPain(ped, 6, 0) + + -- Setup combat attributes + GiveWeaponToPed(target, `WEAPON_PISTOL`, 255, false, true) + SetPedCombatAttributes(target, 46, true) + SetPedFleeAttributes(target, 0, false) + SetPedCombatRange(target, 2) + SetPedCombatMovement(target, 2) + SetPedAccuracy(target, Config.PedAccuracy) + + -- Make them exit and attack + TaskLeaveVehicle(target, vehicle, 0) Wait(1250) - ClearPedTasksImmediately(ped) - PlayPain(ped, math.random(7, 8), 0) - MakePedFlee(ped) + ClearPedTasksImmediately(target) + TaskCombatPed(target, PlayerPedId(), 0, 16) + + QBCore.Functions.Notify('The driver is fighting back!', 'error') + TriggerServerEvent('hud:server:GainStress', math.random(2, 6)) end) + else + -- Normal success behavior + local plate = QBCore.Functions.GetPlate(vehicle) + for p = 1, #occupants do + local ped = occupants[p] + CreateThread(function() + FreezeEntityPosition(vehicle, false) + SetVehicleUndriveable(vehicle, false) + TaskLeaveVehicle(ped, vehicle, 0) + PlayPain(ped, 6, 0) + Wait(1250) + ClearPedTasksImmediately(ped) + PlayPain(ped, math.random(7, 8), 0) + MakePedFlee(ped) + end) + end + TriggerServerEvent('hud:server:GainStress', math.random(1, 4)) + TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate) end - TriggerServerEvent('hud:server:GainStress', math.random(1, 4)) - TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate) else QBCore.Functions.Notify(Lang:t('notify.cjackfail'), 'error') FreezeEntityPosition(vehicle, false) @@ -713,6 +739,40 @@ function CarjackVehicle(target) end) end +-- Continuous check for aiming at vehicles +CreateThread(function() + while true do + if Config.CarJackEnable and canCarjack then + local playerid = PlayerId() + local aiming, target = GetEntityPlayerIsFreeAimingAt(playerid) + + if aiming and target ~= nil and target ~= 0 then + if DoesEntityExist(target) and IsPedInAnyVehicle(target, false) and not IsEntityDead(target) and not IsPedAPlayer(target) then + local targetveh = GetVehiclePedIsIn(target) + local carIsImmune = false + + for _, veh in ipairs(Config.ImmuneVehicles) do + if GetEntityModel(targetveh) == joaat(veh) then + carIsImmune = true + break + end + end + + if not IsBlacklistedWeapon() and not carIsImmune then + local pos = GetEntityCoords(PlayerPedId(), true) + local targetpos = GetEntityCoords(target, true) + + if #(pos - targetpos) < 5.0 then + CarjackVehicle(target) + end + end + end + end + end + Wait(100) + end +end) + function AttemptPoliceAlert(type) if not AlertSend then local chance = Config.PoliceAlertChance @@ -752,7 +812,6 @@ function DrawText3D(x, y, z, text) DrawRect(0.0, 0.0 + 0.0125, 0.017 + factor, 0.03, 0, 0, 0, 75) ClearDrawOrigin() end - ----------------------- ---- NUICallback ---- ----------------------- From 38cefe76f912b33b1f3587663e6b94cfa25acff9 Mon Sep 17 00:00:00 2001 From: t0xicVybez Date: Tue, 17 Dec 2024 17:43:24 -0800 Subject: [PATCH 2/4] Added configuration options for carjacking Config.PedDefenseChance = 0.6 -- Probability (0-1) that a ped will defend themselves Config.PedAccuracy = 50 -- How accurate the ped's shooting will be (1-100) Config options added to support the new ped defense feature. --- config.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/config.lua b/config.lua index 84cd0d7..5c0788e 100644 --- a/config.lua +++ b/config.lua @@ -26,17 +26,19 @@ Config.RemoveLockpickAdvanced = 0.2 -- Chance to remove advanced lockpick on fai Config.CarJackEnable = true -- True allows for the ability to car jack peds. Config.CarjackingTime = 7500 -- How long it takes to carjack Config.DelayBetweenCarjackings = 10000 -- Time before you can carjack again +Config.PedDefenseChance = 0.6 -- Probability (0-1) that a ped will defend themselves +Config.PedAccuracy = 50 -- How accurate the ped's shooting will be (1-100) Config.CarjackChance = { ['2685387236'] = 0.0, -- melee - ['416676503'] = 0.5, -- handguns - ['-957766203'] = 0.75, -- SMG - ['860033945'] = 0.90, -- shotgun - ['970310034'] = 0.90, -- assault - ['1159398588'] = 0.99, -- LMG - ['3082541095'] = 0.99, -- sniper - ['2725924767'] = 0.99, -- heavy + ['416676503'] = 100, -- handguns + ['-957766203'] = 75.00, -- SMG + ['860033945'] = 75.00, -- shotgun + ['970310034'] = 0.75, -- assault + ['1159398588'] = 0.80, -- LMG + ['3082541095'] = 65.00, -- sniper + ['2725924767'] = 65.00, -- heavy ['1548507267'] = 0.0, -- throwable - ['4257178988'] = 0.0, -- misc + ['4257178988'] = 50.0, -- misc } -- Hotwire Settings @@ -106,4 +108,4 @@ Config.NoCarjackWeapons = { "WEAPON_Ball", "WEAPON_Snowball", "WEAPON_SmokeGrenade", -} \ No newline at end of file +} From 2ee152c74223d1aa7158042008248043a7fa3d0b Mon Sep 17 00:00:00 2001 From: t0xicVybez Date: Thu, 19 Dec 2024 12:34:54 -0800 Subject: [PATCH 3/4] Made requested changes --- client/main.lua | 80 ++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/client/main.lua b/client/main.lua index f1558b7..869132c 100644 --- a/client/main.lua +++ b/client/main.lua @@ -66,7 +66,7 @@ local function robKeyLoop() end end end - -- Parked car logic + -- Parked car logic elseif driver == 0 and entering ~= lastPickedVehicle and not HasKeys(plate) and not isTakingKeys then QBCore.Functions.TriggerCallback('qb-vehiclekeys:server:checkPlayerOwned', function(playerOwned) if not playerOwned then @@ -252,13 +252,36 @@ RegisterNetEvent('qb-vehiclekeys:client:GiveKeys', function(id) end end) -RegisterNetEvent('QBCore:Client:EnteringVehicle', function() - robKeyLoop() -end) - -RegisterNetEvent('qb-weapons:client:DrawWeapon', function() - Wait(2000) - robKeyLoop() +RegisterNetEvent('QBCore:Client:VehicleInfo', function(data) + if data.event == 'Entering' then + -- Handle vehicle entry attempt + local ped = PlayerPedId() + local entering = GetVehiclePedIsTryingToEnter(ped) + if entering ~= 0 and not isBlacklistedVehicle(entering) then + local plate = QBCore.Functions.GetPlate(entering) + local driver = GetPedInVehicleSeat(entering, -1) + + if driver ~= 0 and not IsPedAPlayer(driver) and not HasKeys(plate) then + if IsEntityDead(driver) then + if not isTakingKeys then + isTakingKeys = true + TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(entering), 1) + QBCore.Functions.Progressbar('steal_keys', Lang:t('progress.takekeys'), 2500, false, false, { + disableMovement = false, + disableCarMovement = true, + disableMouse = false, + disableCombat = true + }, {}, {}, {}, function() -- Done + TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate) + isTakingKeys = false + end, function() + isTakingKeys = false + end) + end + end + end + end + end end) RegisterNetEvent('lockpicks:UseLockpick', function(isAdvanced) @@ -616,7 +639,7 @@ function Hotwire(vehicle, plate) anim = 'machinic_loop_mechandplayer', flags = 16 }, {}, {}, function() -- Done - StopAnimTask(ped, 'anim@amb@clubhouse@tutorial@bkr_tut_ig3@', 'machinic_loop_mechandplayer', 1.0) + StopAnimTask(ped, 'anim@amb@clubhouse@tutorial@bkr_tut_ig3@', 'machinic_loop_mechandplayer', 1.0) TriggerServerEvent('hud:server:GainStress', math.random(1, 4)) if (math.random() <= Config.HotwireChance) then TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate) @@ -652,7 +675,7 @@ function CarjackVehicle(target) end) Wait(math.random(200, 500)) end - -- Cancel progress bar if: Ped dies during robbery, car gets too far away +-- Cancel progress bar if: Ped dies during robbery, car gets too far away CreateThread(function() while isCarjacking do local distance = #(GetEntityCoords(PlayerPedId()) - GetEntityCoords(target)) @@ -699,7 +722,7 @@ function CarjackVehicle(target) QBCore.Functions.Notify('The driver is fighting back!', 'error') TriggerServerEvent('hud:server:GainStress', math.random(2, 6)) end) - else + else -- Normal success behavior local plate = QBCore.Functions.GetPlate(vehicle) for p = 1, #occupants do @@ -739,40 +762,6 @@ function CarjackVehicle(target) end) end --- Continuous check for aiming at vehicles -CreateThread(function() - while true do - if Config.CarJackEnable and canCarjack then - local playerid = PlayerId() - local aiming, target = GetEntityPlayerIsFreeAimingAt(playerid) - - if aiming and target ~= nil and target ~= 0 then - if DoesEntityExist(target) and IsPedInAnyVehicle(target, false) and not IsEntityDead(target) and not IsPedAPlayer(target) then - local targetveh = GetVehiclePedIsIn(target) - local carIsImmune = false - - for _, veh in ipairs(Config.ImmuneVehicles) do - if GetEntityModel(targetveh) == joaat(veh) then - carIsImmune = true - break - end - end - - if not IsBlacklistedWeapon() and not carIsImmune then - local pos = GetEntityCoords(PlayerPedId(), true) - local targetpos = GetEntityCoords(target, true) - - if #(pos - targetpos) < 5.0 then - CarjackVehicle(target) - end - end - end - end - end - Wait(100) - end -end) - function AttemptPoliceAlert(type) if not AlertSend then local chance = Config.PoliceAlertChance @@ -812,6 +801,7 @@ function DrawText3D(x, y, z, text) DrawRect(0.0, 0.0 + 0.0125, 0.017 + factor, 0.03, 0, 0, 0, 75) ClearDrawOrigin() end + ----------------------- ---- NUICallback ---- ----------------------- From 0a027027d18f71f3ef1e6c8b0d24785106f4a972 Mon Sep 17 00:00:00 2001 From: t0xicVybez Date: Thu, 19 Dec 2024 12:38:33 -0800 Subject: [PATCH 4/4] Fixed Numbers for mathrandom --- config.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/config.lua b/config.lua index 5c0788e..4f38f5d 100644 --- a/config.lua +++ b/config.lua @@ -29,16 +29,16 @@ Config.DelayBetweenCarjackings = 10000 -- Time before you can carjack again Config.PedDefenseChance = 0.6 -- Probability (0-1) that a ped will defend themselves Config.PedAccuracy = 50 -- How accurate the ped's shooting will be (1-100) Config.CarjackChance = { - ['2685387236'] = 0.0, -- melee + ['2685387236'] = 0, -- melee ['416676503'] = 100, -- handguns - ['-957766203'] = 75.00, -- SMG - ['860033945'] = 75.00, -- shotgun - ['970310034'] = 0.75, -- assault - ['1159398588'] = 0.80, -- LMG - ['3082541095'] = 65.00, -- sniper - ['2725924767'] = 65.00, -- heavy - ['1548507267'] = 0.0, -- throwable - ['4257178988'] = 50.0, -- misc + ['-957766203'] = 75, -- SMG + ['860033945'] = 75, -- shotgun + ['970310034'] = 75, -- assault + ['1159398588'] = 80, -- LMG + ['3082541095'] = 65, -- sniper + ['2725924767'] = 65, -- heavy + ['1548507267'] = 0, -- throwable + ['4257178988'] = 50, -- misc } -- Hotwire Settings