Skip to content

Commit

Permalink
Updating to use the native qb-core Round function. I didn't realize t…
Browse files Browse the repository at this point in the history
…his function existed in my previous PR that introduced it.
  • Loading branch information
mbiddle committed Nov 15, 2024
1 parent d548e14 commit 2841927
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ local function SplitStr(inputstr, sep)
return t
end

function round(number, decimalPlaces)
local multiple = 10^(decimalPlaces or 0)
return math.floor(number * multiple + 0.5) / multiple
end

local function connecttoradio(channel)
if channel > Config.MaxFrequency or channel <= 0 then QBCore.Functions.Notify(Lang:t('restricted_channel_error'), 'error') return false end
if Config.RestrictedChannels[channel] ~= nil then
Expand Down Expand Up @@ -160,7 +155,7 @@ end)

-- NUI
RegisterNUICallback('joinRadio', function(data, cb)
local rchannel = round(tonumber(data.channel), 2)
local rchannel = QBCore.Shared.Round(tonumber(data.channel), 2)
if rchannel ~= nil then
if rchannel <= Config.MaxFrequency and rchannel > 0 then
if rchannel ~= RadioChannel then
Expand Down Expand Up @@ -219,7 +214,7 @@ end)

RegisterNUICallback("increaseradiochannel", function(_, cb)
if not onRadio then return end
local newChannel = round(tonumber(RadioChannel + 1), 2)
local newChannel = QBCore.Shared.Round(tonumber(RadioChannel + 1), 2)
local canaccess = connecttoradio(newChannel)
cb({
canaccess = canaccess,
Expand All @@ -229,7 +224,7 @@ end)

RegisterNUICallback("decreaseradiochannel", function(_, cb)
if not onRadio then return end
local newChannel = round(tonumber(RadioChannel - 1), 2)
local newChannel = QBCore.Shared.Round(tonumber(RadioChannel - 1), 2)
local canaccess = connecttoradio(newChannel)
cb({
canaccess = canaccess,
Expand Down

0 comments on commit 2841927

Please sign in to comment.