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

Radio QOL and bug fixes #55

Merged
merged 5 commits into from
Nov 13, 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
26 changes: 16 additions & 10 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ 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 @@ -155,7 +160,7 @@ end)

-- NUI
RegisterNUICallback('joinRadio', function(data, cb)
local rchannel = tonumber(data.channel)
local rchannel = round(tonumber(data.channel), 2)
if rchannel ~= nil then
if rchannel <= Config.MaxFrequency and rchannel > 0 then
if rchannel ~= RadioChannel then
Expand All @@ -164,6 +169,7 @@ RegisterNUICallback('joinRadio', function(data, cb)
canaccess = canaccess,
channel = RadioChannel
})
return
else
QBCore.Functions.Notify(Lang:t('you_on_radio') , 'error')
end
Expand All @@ -177,6 +183,7 @@ RegisterNUICallback('joinRadio', function(data, cb)
canaccess = false,
channel = RadioChannel
})
return
end)

RegisterNUICallback('leaveRadio', function(_, cb)
Expand Down Expand Up @@ -211,7 +218,8 @@ RegisterNUICallback("volumeDown", function(_, cb)
end)

RegisterNUICallback("increaseradiochannel", function(_, cb)
local newChannel = RadioChannel + 1
if not onRadio then return end
local newChannel = round(tonumber(RadioChannel + 1), 2)
local canaccess = connecttoradio(newChannel)
cb({
canaccess = canaccess,
Expand All @@ -221,14 +229,12 @@ end)

RegisterNUICallback("decreaseradiochannel", function(_, cb)
if not onRadio then return end
local newChannel = RadioChannel - 1
if newChannel >= 1 then
local canaccess = connecttoradio(newChannel)
cb({
canaccess = canaccess,
channel = newChannel
})
end
local newChannel = round(tonumber(RadioChannel - 1), 2)
local canaccess = connecttoradio(newChannel)
cb({
canaccess = canaccess,
channel = newChannel
})
end)

RegisterNUICallback('poweredOff', function(_, cb)
Expand Down
Loading