diff --git a/README.md b/README.md index 7f25dc0..14a35f1 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This doorlock system is based on [nui_doorlock by thelindat](https://github.com/ * [qb-core](https://github.com/qbcore-framework/qb-core) * [qb-input](https://github.com/qbcore-framework/qb-input) - For Making New Doors -* [qb-lockpick](https://github.com/qbcore-framework/qb-lockpick) - For Lockpicking Doors +* [qb-minigames](https://github.com/qbcore-framework/qb-minigames) - For Lockpicking Doors ## Features diff --git a/client/main.lua b/client/main.lua index f048f40..f60fd9a 100644 --- a/client/main.lua +++ b/client/main.lua @@ -8,7 +8,6 @@ local playerCoords = GetEntityCoords(playerPed) local lastCoords = playerCoords local nearbyDoors, closestDoor = {}, {} local paused = false -local usingAdvanced = false local doorData = {} -- Functions @@ -295,37 +294,6 @@ local function updateDoors(specificDoor) lastCoords = playerCoords end -local function lockpickFinish(success) - if success then - QBCore.Functions.Notify(Lang:t("success.lockpick_success"), 'success', 2500) - if closestDoor.data.doors then - TaskTurnPedToFaceCoord(playerPed, closestDoor.data.doors[1].objCoords.x, closestDoor.data.doors[1].objCoords.y, closestDoor.data.doors[1].objCoords.z, 0) - else - TaskTurnPedToFaceCoord(playerPed, closestDoor.data.objCoords.x, closestDoor.data.objCoords.y, closestDoor.data.objCoords.z, 0) - end - Wait(300) - local count = 0 - while GetIsTaskActive(playerPed, 225) do - Wait(10) - if count == 150 then break end - count += 1 - end - Wait(1800) - TriggerServerEvent('qb-doorlock:server:updateState', closestDoor.id, false, false, true, false) -- Broadcast new state of the door to everyone - else - QBCore.Functions.Notify(Lang:t("error.lockpick_fail"), 'error', 2500) - if math.random(1,100) <= 17 then - if usingAdvanced then - TriggerServerEvent("qb-doorlock:server:removeLockpick", "advancedlockpick") - TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items["advancedlockpick"], "remove") - else - TriggerServerEvent("qb-doorlock:server:removeLockpick", "lockpick") - TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items["lockpick"], "remove") - end - end - end -end - local function isAuthorized(door) if door.allAuthorized then return true end @@ -484,9 +452,40 @@ RegisterNetEvent('qb-doorlock:client:setState', function(serverId, doorID, state end) RegisterNetEvent('lockpicks:UseLockpick', function(isAdvanced) - if not closestDoor.data or not next(closestDoor.data) or PlayerData.metadata['isdead'] or PlayerData.metadata['ishandcuffed'] or (not closestDoor.data.pickable and not closestDoor.data.lockpick) or not closestDoor.data.locked then return end - usingAdvanced = isAdvanced - TriggerEvent('qb-lockpick:client:openLockpick', lockpickFinish) + if not closestDoor.data or not next(closestDoor.data) or PlayerData.metadata['isdead'] or PlayerData.metadata['ishandcuffed'] or (not closestDoor.data.pickable and not closestDoor.data.lockpick) or not closestDoor.data.locked then + return + end + + local difficulty = isAdvanced and 'easy' or 'medium' -- Use 'easy' difficulty for advanced lockpicks, medium for others + local success = exports['qb-minigames']:Skillbar(difficulty) + if success then + QBCore.Functions.Notify(Lang:t("success.lockpick_success"), 'success', 2500) + -- Determine which coordinates to face based on door data + local coordsToFace = closestDoor.data.doors and closestDoor.data.doors[1].objCoords or closestDoor.data.objCoords + TaskTurnPedToFaceCoord(playerPed, coordsToFace.x, coordsToFace.y, coordsToFace.z, 0) + -- Wait for the ped to turn towards the door + Wait(300) + local count = 0 + while GetIsTaskActive(playerPed, 225) and count < 150 do + Wait(10) + count = count + 1 + end + Wait(1800) + -- Unlock the door + TriggerServerEvent('qb-doorlock:server:updateState', closestDoor.id, false, false, true, false) + else + QBCore.Functions.Notify(Lang:t("error.lockpick_fail"), 'error', 2500) + if isAdvanced then + local chanceToRemove = math.random(1,100) <= 17 + if chanceToRemove then + TriggerServerEvent("qb-doorlock:server:removeLockpick", "advancedlockpick") + TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items["advancedlockpick"], "remove") + end + else + TriggerServerEvent("qb-doorlock:server:removeLockpick", "lockpick") + TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items["lockpick"], "remove") + end + end end) RegisterNetEvent('qb-doorlock:client:addNewDoor', function()