Skip to content

Commit

Permalink
fix: compat fixes (#135)
Browse files Browse the repository at this point in the history
* fix: small fixes

* return boolean
  • Loading branch information
Manason authored Sep 28, 2024
1 parent 5193396 commit 252430f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
10 changes: 10 additions & 0 deletions bridge/qb/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,14 @@ end)

RegisterNetEvent('vehiclekeys:client:SetOwner', function(plate)
TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate)
end)

CreateQbExport('HasKeys', function(plate)
if not plate then return HasKeys(cache.vehicle) end
local vehicles = GetVehiclesFromPlate(plate)
local success = false
for i = 1, #vehicles do
success = success or HasKeys(vehicles[i])
end
return success
end)
9 changes: 9 additions & 0 deletions bridge/qb/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ end)

RegisterNetEvent('qb-vehiclekeys:server:removeKeys', function(plate)
removeKeys(source, plate)
end)

CreateQbExport('HasKeys', function(source, plate)
local vehicles = GetVehiclesFromPlate(plate)
local success = false
for i = 1, #vehicles do
success = success or HasKeys(source, vehicles[i])
end
return success
end)
11 changes: 1 addition & 10 deletions bridge/qb/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,4 @@ function GetVehiclesFromPlate(plate)
end

return vehEntityFromPlate
end

CreateQbExport('HasKeys', function(source, plate)
local vehicles = GetVehiclesFromPlate(plate)
local success = nil
for i = 1, #vehicles do
success = success or HasKeys(source, vehicles[i])
end
return success
end)
end
6 changes: 4 additions & 2 deletions client/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ end

---Checks if player has vehicle keys
---@param vehicle number
---@return boolean? `true` if player has vehicle keys, `nil` otherwise.
---@return boolean `true` if player has vehicle keys, `false` otherwise.
function HasKeys(vehicle)
vehicle = vehicle or cache.vehicle
if not vehicle then return false end
local keysList = LocalPlayer.state.keysList or {}
local sessionId = Entity(vehicle).state.sessionId
return keysList[sessionId]
return keysList[sessionId] or false
end

exports('HasKeys', HasKeys)
Expand Down
12 changes: 12 additions & 0 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ local function findKeys(vehicleModel, vehicleClass, vehicle)
local anim = config.anims.lockpick.model[vehicleModel]
or config.anims.lockpick.model[vehicleClass]
or config.anims.lockpick.default

local searchingForKeys = true
CreateThread(function()
while searchingForKeys do
if not IsEntityPlayingAnim(cache.ped, anim.dict, anim.clip, 49) then
lib.playAnim(cache.ped, anim.dict, anim.clip, 3.0, 1.0, -1, 49)
end
Wait(100)
end
end)
if lib.progressCircle({
duration = hotwireTime,
label = locale('progress.searching_keys'),
Expand All @@ -66,13 +76,15 @@ local function findKeys(vehicleModel, vehicleClass, vehicle)
combat = true,
}
}) then
searchingForKeys = false
local success = lib.callback.await('qbx_vehiclekeys:server:findKeys', false, VehToNet(vehicle))
if not success then
TriggerServerEvent('hud:server:GainStress', math.random(1, 4))
exports.qbx_core:Notify(locale("notify.failed_keys"), 'error')
end
return success
end
searchingForKeys = false
end

local isSearchLocked = false
Expand Down
6 changes: 3 additions & 3 deletions server/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ exports('GiveKeys', GiveKeys)

---@param src number
---@param vehicle number
---@return boolean?
---@return boolean
function HasKeys(src, vehicle)
local keysList = Player(src).state.keysList
if not keysList then return end
if not keysList then return false end

local sessionId = Entity(vehicle).state.sessionId
return keysList[sessionId]
return keysList[sessionId] or false
end

exports('HasKeys', HasKeys)
Expand Down

0 comments on commit 252430f

Please sign in to comment.