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

Updated skillbar export with qb-minigames #154

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
69 changes: 34 additions & 35 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ local playerCoords = GetEntityCoords(playerPed)
local lastCoords = playerCoords
local nearbyDoors, closestDoor = {}, {}
local paused = false
local usingAdvanced = false
local doorData = {}

-- Functions
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
Loading