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

fix: notify spam #142

Merged
merged 2 commits into from
Oct 3, 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
18 changes: 15 additions & 3 deletions bridge/qb/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ if GetConvar('qbx_vehiclekeys:enableBridge', 'true') ~= 'true' then return end

local function giveKeys(source, plate)
local vehicles = plate and GetVehiclesFromPlate(plate) or {GetVehiclePedIsIn(GetPlayerPed(source), false)}
local success = nil
local success = false
for i = 1, #vehicles do
success = success or GiveKeys(source, vehicles[i])
if GiveKeys(source, vehicles[i], true) then
success = true
end
end
if success then
exports.qbx_core:Notify(source, locale('notify.keys_taken'))
end
return success
end
Expand All @@ -13,9 +18,16 @@ CreateQbExport('GiveKeys', giveKeys)

local function removeKeys(source, plate)
local vehicles = GetVehiclesFromPlate(plate)
local success = false
for i = 1, #vehicles do
RemoveKeys(source, vehicles[i])
if RemoveKeys(source, vehicles[i], true) then
success = true
end
end
if success then
exports.qbx_core:Notify(source, locale('notify.keys_removed'))
end
return success
end

CreateQbExport('RemoveKeys', removeKeys)
Expand Down
14 changes: 10 additions & 4 deletions server/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ end, {debug = debug})
--- Removing the vehicle keys from the user
---@param source number ID of the player
---@param vehicle number
function RemoveKeys(source, vehicle)
---@param skipNotification? boolean
function RemoveKeys(source, vehicle, skipNotification)
local citizenid = getCitizenId(source)
if not citizenid then return end

Expand All @@ -73,7 +74,9 @@ function RemoveKeys(source, vehicle)
Player(source).state:set('keysList', keys, true)

TriggerClientEvent('qbx_vehiclekeys:client:OnLostKeys', source)
exports.qbx_core:Notify(source, locale('notify.keys_removed'))
if not skipNotification then
exports.qbx_core:Notify(source, locale('notify.keys_removed'))
end

return true
end
Expand All @@ -82,7 +85,8 @@ exports('RemoveKeys', RemoveKeys)

---@param source number
---@param vehicle number
function GiveKeys(source, vehicle)
---@param skipNotification? boolean
function GiveKeys(source, vehicle, skipNotification)
local citizenid = getCitizenId(source)
if not citizenid then return end

Expand All @@ -93,7 +97,9 @@ function GiveKeys(source, vehicle)
keys[sessionId] = true

Player(source).state:set('keysList', keys, true)
exports.qbx_core:Notify(source, locale('notify.keys_taken'))
if not skipNotification then
exports.qbx_core:Notify(source, locale('notify.keys_taken'))
end
return true
end

Expand Down