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

Update to use the native qb-core Round function #57

Merged
merged 1 commit into from
Nov 19, 2024
Merged
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
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
Loading