Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUGGESTION] #269

Open
t0xicVybez opened this issue Dec 15, 2024 · 0 comments
Open

[SUGGESTION] #269

t0xicVybez opened this issue Dec 15, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@t0xicVybez
Copy link

#carjacking
** Current Behavior**
Press F at vehicle with NPC in it then Aim gun to start carjacking

Currently this isn't very realistic or effective

Describe the feature you'd like
Only require a player to aim gun at NPC driver.
then play default animation and have a configurable chance for the NPC to get out and draw a weapon. If ped pulls a gun/weapon then the carjack automatically fails.

If ped doesn't pull weapon, then carjacking succeeds.

Describe alternatives you've considered
N/A

**Suggested modification **
config.lua

-- Carjack Settings
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'] = 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
}

client/main.lua

function CarjackVehicle(target)
    if not Config.CarJackEnable then return end
    isCarjacking = true
    canCarjack = false
    loadAnimDict('mp_am_hold_up')
    local vehicle = GetVehiclePedIsIn(target, false)
    local occupants = GetPedsInVehicle(vehicle)
    for p = 1, #occupants do
        local ped = occupants[p]
        CreateThread(function()
            TaskPlayAnim(ped, 'mp_am_hold_up', 'holdup_victim_20s', 8.0, -8.0, -1, 49, 0, false, false, false)
            PlayPain(ped, 6, 0)
            FreezeEntityPosition(vehicle, true)
            SetVehicleUndriveable(vehicle, true)
        end)
        Wait(math.random(200, 500))
    end
    -- Cancel progress bar if: Ped dies during robbery, car gets too far away
    CreateThread(function()
        while isCarjacking do
            local distance = #(GetEntityCoords(PlayerPedId()) - GetEntityCoords(target))
            if IsPedDeadOrDying(target) or distance > 7.5 then
                TriggerEvent('progressbar:client:cancel')
                FreezeEntityPosition(vehicle, false)
                SetVehicleUndriveable(vehicle, false)
            end
            Wait(100)
        end
    end)
    QBCore.Functions.Progressbar('rob_keys', Lang:t('progress.acjack'), Config.CarjackingTime, false, true, {}, {}, {}, {}, function()
        local hasWeapon, weaponHash = GetCurrentPedWeapon(PlayerPedId(), true)
        if hasWeapon and isCarjacking then
            local carjackChance
            if Config.CarjackChance[tostring(GetWeapontypeGroup(weaponHash))] then
                carjackChance = Config.CarjackChance[tostring(GetWeapontypeGroup(weaponHash))]
            else
                carjackChance = 0.5
            end
            if math.random() <= carjackChance then
                -- 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)
                        
                        -- 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(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
            else
                QBCore.Functions.Notify(Lang:t('notify.cjackfail'), 'error')
                FreezeEntityPosition(vehicle, false)
                SetVehicleUndriveable(vehicle, false)
                MakePedFlee(target)
                TriggerServerEvent('hud:server:GainStress', math.random(1, 4))
            end
            isCarjacking = false
            Wait(2000)
            AttemptPoliceAlert('carjack')
            Wait(Config.DelayBetweenCarjackings)
            canCarjack = true
        end
    end, function()
        MakePedFlee(target)
        isCarjacking = false
        Wait(Config.DelayBetweenCarjackings)
        canCarjack = true
    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)
                    -- Check if target is the driver
                    if GetPedInVehicleSeat(targetveh, -1) == target then
                        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
        end
        Wait(100)
    end
end)

function AttemptPoliceAlert(type)
    if not AlertSend then
        local chance = Config.PoliceAlertChance
        if GetClockHours() >= 1 and GetClockHours() <= 6 then
            chance = Config.PoliceNightAlertChance
        end
        if math.random() <= chance then
            TriggerServerEvent('police:server:policeAlert', Lang:t('info.palert') .. type)
        end
        AlertSend = true
        SetTimeout(Config.AlertCooldown, function()
            AlertSend = false
        end)
    end
end

function MakePedFlee(ped)
    SetPedFleeAttributes(ped, 0, 0)
    TaskReactAndFleePed(ped, PlayerPedId())
end

function DrawText3D(x, y, z, text)
    SetTextScale(0.35, 0.35)
    if GetConvar('qb_locale', 'en') == 'en' then
        SetTextFont(4)
    else
        SetTextFont(1)
    end
    SetTextProportional(1)
    SetTextColour(255, 255, 255, 215)
    SetTextEntry('STRING')
    SetTextCentre(true)
    AddTextComponentString(text)
    SetDrawOrigin(x, y, z, 0)
    DrawText(0.0, 0.0)
    local factor = (string.len(text)) / 370
    DrawRect(0.0, 0.0 + 0.0125, 0.017 + factor, 0.03, 0, 0, 0, 75)
    ClearDrawOrigin()
end```

the above has been tested and found to be working effectively on latest qb-core and qb-vehiclekeys version.
@t0xicVybez t0xicVybez added the enhancement New feature or request label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant