qb-vehiclekeys

Improve qb-vehiclekeys compatibility with our Chop Shop

If you are looking to improve the compatibility of our Chop Shop script with qb-vehiclekeys, then you are in the right spot! Below we'll describe how you can disable the ability to lockpick a vehicle as normal ensuring that your Chop Shop vehicle's are only unlockable through the proper means!

Step 1 - Getting Started

This process is very simple, but let's try to explain what we're going to accomplish here so you understand. We're going to use an export from our Exports page to determine if the player is currently trying to interact with the assigned chop vehicle. The export is:

exports.lation_chopshop:IsChopping()

What this does is when used in a line of code is returns true or false. It will return true if the player is currently attempting to interact with a vehicle they are assigned via the chopping mission. If it is not a vehicle assigned to them from the chopping mission it will return false. We can use this export to stop the players from completing certain actions, such as lockpicking a vehicle the normal method to ensure they use the proper method on the assigned vehicle.

Since we're talking about qb-vehiclekeys specifically here, let's show you how to implement this into qb-vehiclekeys properly.

Step 2 - Open qb-vehiclekeys

Navigate to your server resources folder, find your qb-vehiclekeys folder and open client/main.lua. We need to find the lockpicks:UseLockpick event, which currently is on line 264 and looks like this:

RegisterNetEvent('lockpicks:UseLockpick', function(isAdvanced)
    local ped = PlayerPedId()
    local pos = GetEntityCoords(ped)
    local vehicle = QBCore.Functions.GetClosestVehicle()

    if vehicle == nil or vehicle == 0 then return end
    if HasKeys(QBCore.Functions.GetPlate(vehicle)) then return end
    if #(pos - GetEntityCoords(vehicle)) > 2.5 then return end
    if GetVehicleDoorLockStatus(vehicle) <= 0 then return end

    local difficulty = isAdvanced and 'easy' or 'medium' -- Easy for advanced lockpick, medium by default
    local success = exports['qb-minigames']:Skillbar(difficulty)

    local chance = math.random()
    if success then
        TriggerServerEvent('hud:server:GainStress', math.random(1, 4))
        lastPickedVehicle = vehicle

        if GetPedInVehicleSeat(vehicle, -1) == PlayerPedId() then
            TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', QBCore.Functions.GetPlate(vehicle))
        else
            QBCore.Functions.Notify(Lang:t('notify.vlockpick'), 'success')
            TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(vehicle), 1)
        end
    else
        TriggerServerEvent('hud:server:GainStress', math.random(1, 4))
        AttemptPoliceAlert('steal')
    end

    if isAdvanced then
        if chance <= Config.RemoveLockpickAdvanced then
            TriggerServerEvent('qb-vehiclekeys:server:breakLockpick', 'advancedlockpick')
        end
    else
        if chance <= Config.RemoveLockpickNormal then
            TriggerServerEvent('qb-vehiclekeys:server:breakLockpick', 'lockpick')
        end
    end
end)

We can basically ignore the whole bulk of code above, as all we need to do is add a single line at the top. So let's add our export here, right at the top, to stop them from lockpicking the chop vehicle the normal way when they are in a chopping mission. We can do that by simply editing this event to look like this:

RegisterNetEvent('lockpicks:UseLockpick', function(isAdvanced)
    if exports.lation_chopshop:IsChopping() then return end -- Add export here
    local ped = PlayerPedId()
    local pos = GetEntityCoords(ped)
    local vehicle = QBCore.Functions.GetClosestVehicle()

    if vehicle == nil or vehicle == 0 then return end
    if HasKeys(QBCore.Functions.GetPlate(vehicle)) then return end
    if #(pos - GetEntityCoords(vehicle)) > 2.5 then return end
    if GetVehicleDoorLockStatus(vehicle) <= 0 then return end

    local difficulty = isAdvanced and 'easy' or 'medium' -- Easy for advanced lockpick, medium by default
    local success = exports['qb-minigames']:Skillbar(difficulty)

    local chance = math.random()
    if success then
        TriggerServerEvent('hud:server:GainStress', math.random(1, 4))
        lastPickedVehicle = vehicle

        if GetPedInVehicleSeat(vehicle, -1) == PlayerPedId() then
            TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', QBCore.Functions.GetPlate(vehicle))
        else
            QBCore.Functions.Notify(Lang:t('notify.vlockpick'), 'success')
            TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(vehicle), 1)
        end
    else
        TriggerServerEvent('hud:server:GainStress', math.random(1, 4))
        AttemptPoliceAlert('steal')
    end

    if isAdvanced then
        if chance <= Config.RemoveLockpickAdvanced then
            TriggerServerEvent('qb-vehiclekeys:server:breakLockpick', 'advancedlockpick')
        end
    else
        if chance <= Config.RemoveLockpickNormal then
            TriggerServerEvent('qb-vehiclekeys:server:breakLockpick', 'lockpick')
        end
    end
end)

Step 3 - Done

After adding in our export we can save, restart our server & try again - you'll notice now you will not be able to lockpick this vehicle via the normal method while you are in a chopping mission. You will have to use the proper method! However, with recent improvements, this export will allow you to continue to lockpick any vehicles that are not your assigned chop vehicle. Hope this helped!

Last updated