diff --git a/client.lua b/client.lua index 87e049b..22592a9 100644 --- a/client.lua +++ b/client.lua @@ -29,6 +29,13 @@ local function SplitStr(inputstr, sep) 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 + if not Config.RestrictedChannels[channel][PlayerData.job.name] or not PlayerData.job.onduty then + QBCore.Functions.Notify(Lang:t('restricted_channel_error'), 'error') + return false + end + end RadioChannel = channel if onRadio then exports["pma-voice"]:setRadioChannel(0) @@ -42,6 +49,7 @@ local function connecttoradio(channel) else QBCore.Functions.Notify(Lang:t('joined_to_radio', {channel = channel .. '.00 MHz'}), 'success') end + return true end local function closeEvent() @@ -61,9 +69,9 @@ local function toggleRadioAnimation(pState) LoadAnimDic("cellphone@") if pState then TriggerEvent("attachItemRadio","radio01") - TaskPlayAnim(PlayerPedId(), "cellphone@", "cellphone_text_read_base", 2.0, 3.0, -1, 49, 0, 0, 0, 0) - radioProp = CreateObject(`prop_cs_hand_radio`, 1.0, 1.0, 1.0, 1, 1, 0) - AttachEntityToEntity(radioProp, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), 57005), 0.14, 0.01, -0.02, 110.0, 120.0, -15.0, 1, 0, 0, 0, 2, 1) + TaskPlayAnim(PlayerPedId(), "cellphone@", "cellphone_text_read_base", 2.0, 3.0, -1, 49, 0, false, false, false) + radioProp = CreateObject(`prop_cs_hand_radio`, 1.0, 1.0, 1.0, true, true, false) + AttachEntityToEntity(radioProp, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), 57005), 0.14, 0.01, -0.02, 110.0, 120.0, -15.0, true, false, false, false, 2, true) else StopAnimTask(PlayerPedId(), "cellphone@", "cellphone_text_read_base", 1.0) ClearPedTasks(PlayerPedId()) @@ -149,17 +157,13 @@ end) RegisterNUICallback('joinRadio', function(data, cb) local rchannel = tonumber(data.channel) if rchannel ~= nil then - if rchannel <= Config.MaxFrequency and rchannel ~= 0 then + if rchannel <= Config.MaxFrequency and rchannel > 0 then if rchannel ~= RadioChannel then - if Config.RestrictedChannels[rchannel] ~= nil then - if Config.RestrictedChannels[rchannel][PlayerData.job.name] and PlayerData.job.onduty then - connecttoradio(rchannel) - else - QBCore.Functions.Notify(Lang:t('restricted_channel_error'), 'error') - end - else - connecttoradio(rchannel) - end + local canaccess = connecttoradio(rchannel) + cb({ + canaccess = canaccess, + channel = RadioChannel + }) else QBCore.Functions.Notify(Lang:t('you_on_radio') , 'error') end @@ -169,7 +173,10 @@ RegisterNUICallback('joinRadio', function(data, cb) else QBCore.Functions.Notify(Lang:t('invalid_radio') , 'error') end - cb("ok") + cb({ + canaccess = false, + channel = RadioChannel + }) end) RegisterNUICallback('leaveRadio', function(_, cb) @@ -205,18 +212,22 @@ end) RegisterNUICallback("increaseradiochannel", function(_, cb) local newChannel = RadioChannel + 1 - connecttoradio(newChannel) - QBCore.Functions.Notify(Lang:t("increase_decrease_radio_channel", {value = newChannel}), "success") - cb("ok") + local canaccess = connecttoradio(newChannel) + cb({ + canaccess = canaccess, + channel = newChannel + }) end) RegisterNUICallback("decreaseradiochannel", function(_, cb) if not onRadio then return end local newChannel = RadioChannel - 1 if newChannel >= 1 then - connecttoradio(newChannel) - QBCore.Functions.Notify(Lang:t("increase_decrease_radio_channel", {value = newChannel}), "success") - cb("ok") + local canaccess = connecttoradio(newChannel) + cb({ + canaccess = canaccess, + channel = newChannel + }) end end) diff --git a/fxmanifest.lua b/fxmanifest.lua index 980272c..55358ff 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -23,7 +23,7 @@ files { 'html/ui.html', 'html/js/script.js', 'html/css/style.css', - 'html/img/radio.png' + 'html/img/radio*.png' } dependency 'pma-voice' diff --git a/html/js/script.js b/html/js/script.js index 8b900ee..06ebd99 100644 --- a/html/js/script.js +++ b/html/js/script.js @@ -1,88 +1,127 @@ -$(function() { - window.addEventListener('message', function(event) { +$(function () { + window.addEventListener("message", function (event) { if (event.data.type == "open") { - QBRadio.SlideUp() + QBRadio.SlideUp(); } if (event.data.type == "close") { - QBRadio.SlideDown() + QBRadio.SlideDown(); } }); document.onkeyup = function (data) { - if (data.key == "Escape") { // Escape key - $.post('https://qb-radio/escape', JSON.stringify({})); - } else if (data.key == "Enter") { // Enter key - $.post('https://qb-radio/joinRadio', JSON.stringify({ - channel: $("#channel").val() - })); + if (data.key == "Escape") { + // Escape key + $.post("https://qb-radio/escape", JSON.stringify({})); + } else if (data.key == "Enter") { + // Enter key + $.post( + "https://qb-radio/joinRadio", + JSON.stringify({ + channel: $("#channel").val(), + }) + ).then((data) => { + if (data.canaccess) { + $("#channel").val(data.channel); + } + }); } }; }); -QBRadio = {} +QBRadio = {}; -$(document).on('click', '#submit', function(e){ +$(document).on("click", "#submit", function (e) { e.preventDefault(); - $.post('https://qb-radio/joinRadio', JSON.stringify({ - channel: $("#channel").val() - })); + $.post( + "https://qb-radio/joinRadio", + JSON.stringify({ + channel: $("#channel").val(), + }) + ).then((data) => { + if (data.canaccess) { + $("#channel").val(data.channel); + } + }); }); -$(document).on('click', '#disconnect', function(e){ +$(document).on("click", "#disconnect", function (e) { e.preventDefault(); - $.post('https://qb-radio/leaveRadio'); + $.post("https://qb-radio/leaveRadio"); }); -$(document).on('click', '#volumeUp', function(e){ +$(document).on("click", "#volumeUp", function (e) { e.preventDefault(); - $.post('https://qb-radio/volumeUp', JSON.stringify({ - channel: $("#channel").val() - })); + $.post( + "https://qb-radio/volumeUp", + JSON.stringify({ + channel: $("#channel").val(), + }) + ); }); -$(document).on('click', '#volumeDown', function(e){ +$(document).on("click", "#volumeDown", function (e) { e.preventDefault(); - $.post('https://qb-radio/volumeDown', JSON.stringify({ - channel: $("#channel").val() - })); + $.post( + "https://qb-radio/volumeDown", + JSON.stringify({ + channel: $("#channel").val(), + }) + ); }); -$(document).on('click', '#decreaseradiochannel', function(e){ +$(document).on("click", "#decreaseradiochannel", function (e) { e.preventDefault(); - $.post('https://qb-radio/decreaseradiochannel', JSON.stringify({ - channel: $("#channel").val() - })); + $.post( + "https://qb-radio/decreaseradiochannel", + JSON.stringify({ + channel: $("#channel").val(), + }) + ).then((data) => { + if (data.canaccess) { + $("#channel").val(data.channel); + } + }); }); -$(document).on('click', '#increaseradiochannel', function(e){ +$(document).on("click", "#increaseradiochannel", function (e) { e.preventDefault(); - $.post('https://qb-radio/increaseradiochannel', JSON.stringify({ - channel: $("#channel").val() - })); + $.post( + "https://qb-radio/increaseradiochannel", + JSON.stringify({ + channel: $("#channel").val(), + }) + ).then((data) => { + if (data.canaccess) { + $("#channel").val(data.channel); + } + }); }); -$(document).on('click', '#poweredOff', function(e){ +$(document).on("click", "#poweredOff", function (e) { e.preventDefault(); - $.post('https://qb-radio/poweredOff', JSON.stringify({ - channel: $("#channel").val() - })); + $.post( + "https://qb-radio/poweredOff", + JSON.stringify({ + channel: $("#channel").val(), + }) + ); }); -QBRadio.SlideUp = function() { +QBRadio.SlideUp = function () { $(".container").css("display", "block"); - $(".radio-container").animate({bottom: "6vh",}, 250); -} + $(".radio-container").animate({ bottom: "6vh" }, 250); +}; -QBRadio.SlideDown = function() { - $(".radio-container").animate({bottom: "-110vh",}, 400, function(){ +QBRadio.SlideDown = function () { + $(".radio-container").animate({ bottom: "-110vh" }, 400, function () { $(".container").css("display", "none"); }); -} +}; diff --git a/locales/de.lua b/locales/de.lua index 003ebd2..4af8be4 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -9,7 +9,6 @@ local Translations ={ ['volume_radio'] = 'Neue Lautstärke %{value}', ['decrease_radio_volume'] = 'Das Radio ist bereits auf maximaler Lautstärke eingestellt', ['increase_radio_volume'] = 'Das Radio ist bereits auf der niedrigsten Lautstärke eingestellt', - ['increase_decrease_radio_channel'] = 'Neuer Kanal %{value}', } if GetConvar('qb_locale', 'en') == 'de' then diff --git a/locales/en.lua b/locales/en.lua index f3066d5..634e50a 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -9,7 +9,6 @@ local Translations ={ ['volume_radio'] = 'New volume %{value}', ['decrease_radio_volume'] = 'The radio is already set to maximum volume', ['increase_radio_volume'] = 'The radio is already set to the lowest volume', - ['increase_decrease_radio_channel'] = 'New channel %{value}', } Lang = Lang or Locale:new({ diff --git a/locales/pt-br.lua b/locales/pt-br.lua index af3fd97..dc506ab 100644 --- a/locales/pt-br.lua +++ b/locales/pt-br.lua @@ -9,7 +9,6 @@ local Translations = { ['volume_radio'] = 'Novo volume %{value}', ['decrease_radio_volume'] = 'O rádio já está ajustado para o volume máximo', ['increase_radio_volume'] = 'O rádio já está ajustado para o volume mais baixo', - ['increase_decrease_radio_channel'] = 'Novo canal %{value}', } if GetConvar('qb_locale', 'en') == 'pt-br' then