Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Qbox-project/qbx_radio into…
Browse files Browse the repository at this point in the history
… fix_ui
  • Loading branch information
TonybynMp4 committed Feb 7, 2024
2 parents 68c956c + ba72f3c commit 9ff779e
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 115 deletions.
77 changes: 38 additions & 39 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local onRadio = false
local radioChannel = 0
local radioVolume = 50
local hasRadio = false
local radioProp = nil
local micClicks = true

local function connectToRadio(channel)
radioChannel = channel
Expand All @@ -13,59 +13,46 @@ local function connectToRadio(channel)
else
onRadio = true
exports['pma-voice']:setVoiceProperty('radioEnabled', true)
qbx.playAudio({
audioName = 'Start_Squelch',
audioRef = 'CB_RADIO_SFX',
source = cache.ped
})
end
exports['pma-voice']:setRadioChannel(channel)
if channel % 1 > 0 then
exports.qbx_core:Notify(Lang:t('joined_radio')..channel..' MHz', 'success')
exports.qbx_core:Notify(locale('joined_radio')..channel..' MHz', 'success')
else
exports.qbx_core:Notify(Lang:t('joined_radio')..channel..'.00 MHz', 'success')
exports.qbx_core:Notify(locale('joined_radio')..channel..'0 MHz', 'success')
end
end

local function closeEvent()
TriggerEvent('InteractSound_CL:PlayOnOne','click',0.6)
end

local function leaveradio()
closeEvent()
qbx.playAudio({
audioName = 'End_Squelch',
audioRef = 'CB_RADIO_SFX',
source = cache.ped
})
radioChannel = 0
onRadio = false
exports['pma-voice']:setRadioChannel(0)
exports['pma-voice']:setVoiceProperty('radioEnabled', false)
exports.qbx_core:Notify(Lang:t('left_channel'), 'error')
exports.qbx_core:Notify(locale('left_channel'), 'error')
end

local function toggleRadioAnimation(pState)
lib.requestAnimDict('cellphone@')
if pState then
TriggerEvent('attachItemRadio','radio01')
TaskPlayAnim(cache.ped, '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, cache.ped, GetPedBoneIndex(cache.ped, 57005), 0.14, 0.01, -0.02, 110.0, 120.0, -15.0, 1, 0, 0, 0, 2, 1)
else
StopAnimTask(cache.ped, 'cellphone@', 'cellphone_text_read_base', 1.0)
ClearPedTasks(cache.ped)
if radioProp ~= 0 then
DeleteObject(radioProp)
radioProp = 0
end
end
end

local function toggleRadio(toggle)
radioMenu = toggle
SetNuiFocus(radioMenu, radioMenu)
if radioMenu then
toggleRadioAnimation(true)
exports.scully_emotemenu:playEmoteByCommand('wt')
SendNUIMessage({type = 'open'})
else
toggleRadioAnimation(false)
exports.scully_emotemenu:cancelEmote()
SendNUIMessage({type = 'close'})
end
end



local function doRadioCheck()
hasRadio = exports.ox_inventory:Search('count', 'radio') > 0
end
Expand Down Expand Up @@ -111,21 +98,21 @@ end)
RegisterNUICallback('joinRadio', function(data, cb)
local rchannel = tonumber(data.channel)
if not rchannel or type(rchannel) ~= "number" or rchannel > config.maxFrequency or rchannel < 1 then
exports.qbx_core:Notify(Lang:t('invalid_channel'), 'error')
exports.qbx_core:Notify(locale('invalid_channel'), 'error')
cb('ok')
return
end
rchannel = qbx.math.round(rchannel, config.decimalPlaces)

if rchannel == radioChannel then
exports.qbx_core:Notify(Lang:t('on_channel'), 'error')
exports.qbx_core:Notify(locale('on_channel'), 'error')
cb('ok')
return
end

local frequency = not config.whitelistSubChannels and math.floor(rchannel) or rchannel
if config.restrictedChannels[frequency] and (not config.restrictedChannels[frequency][QBX.PlayerData.job.name] or not QBX.PlayerData.job.onduty) then
exports.qbx_core:Notify(Lang:t('restricted_channel'), 'error')
exports.qbx_core:Notify(locale('restricted_channel'), 'error')
cb('ok')
return
end
Expand All @@ -135,7 +122,7 @@ end)

RegisterNUICallback('leaveRadio', function(_, cb)
if radioChannel == 0 then
exports.qbx_core:Notify(Lang:t('not_on_channel'), 'error')
exports.qbx_core:Notify(locale('not_on_channel'), 'error')
else
leaveradio()
end
Expand All @@ -145,25 +132,25 @@ end)
RegisterNUICallback('volumeUp', function(_, cb)
if not onRadio then return cb('ok') end
if radioVolume > 95 then
exports.qbx_core:Notify(Lang:t('max_volume'), 'error')
exports.qbx_core:Notify(locale('max_volume'), 'error')
return
end

radioVolume += 5
exports.qbx_core:Notify(Lang:t('new_volume')..radioVolume, 'success')
exports.qbx_core:Notify(locale('new_volume')..radioVolume, 'success')
exports['pma-voice']:setRadioVolume(radioVolume)
cb('ok')
end)

RegisterNUICallback('volumeDown', function(_, cb)
if not onRadio then return cb('ok') end
if radioVolume < 10 then
exports.qbx_core:Notify(Lang:t('min_volume'), 'error')
exports.qbx_core:Notify(locale('min_volume'), 'error')
return
end

radioVolume -= 5
exports.qbx_core:Notify(Lang:t('new_volume')..radioVolume, 'success')
exports.qbx_core:Notify(locale('new_volume')..radioVolume, 'success')
exports['pma-voice']:setRadioVolume(radioVolume)
cb('ok')
end)
Expand All @@ -172,7 +159,7 @@ RegisterNUICallback('increaseradiochannel', function(_, cb)
if not onRadio then return cb('ok') end
radioChannel += 1
exports['pma-voice']:setRadioChannel(radioChannel)
exports.qbx_core:Notify(Lang:t('new_channel')..radioChannel, 'success')
exports.qbx_core:Notify(locale('new_channel')..radioChannel, 'success')
cb('ok')
end)

Expand All @@ -182,10 +169,22 @@ RegisterNUICallback('decreaseradiochannel', function(_, cb)
radioChannel = radioChannel < 1 and 1 or radioChannel

exports['pma-voice']:setRadioChannel(radioChannel)
exports.qbx_core:Notify(Lang:t('new_channel')..radioChannel, 'success')
exports.qbx_core:Notify(locale('new_channel')..radioChannel, 'success')
cb('ok')
end)

RegisterNUICallback('toggleClicks', function(_, cb)
micClicks = not micClicks
exports['pma-voice']:setVoiceProperty("micClicks", micClicks)
qbx.playAudio({
audioName = "Off_High",
audioRef = 'MP_RADIO_SFX',
source = cache.ped
})
exports.qbx_core:Notify(locale('clicks'..(micClicks and 'On' or 'Off')), micClicks and 'success' or 'error')
cb('ok')
end)

RegisterNUICallback('poweredOff', function(_, cb)
leaveradio()
cb('ok')
Expand Down
7 changes: 3 additions & 4 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ description 'qbx_radio'
repository 'https://github.com/Qbox-project/qbx_radio'
version '1.0.0'

ox_lib 'locale'
shared_scripts {
'@ox_lib/init.lua',
'@qbx_core/modules/utils.lua',
'@qbx_core/shared/locale.lua',
'locales/en.lua',
'locales/*.lua',
'@qbx_core/modules/lib.lua'
}

client_scripts {
Expand All @@ -28,6 +26,7 @@ files {
'html/css/style.css',
'html/img/radio.png',
'config/shared.lua',
'locales/*.json'
}

lua54 'yes'
Expand Down
14 changes: 14 additions & 0 deletions html/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ body {
transition: all 0.1s linear;
}

#toggleClicks {
position: absolute;
width: 4vh;
height: 3.5vh;
bottom: 37.5vh;
border-radius: 5px;
transition: all 0.1s linear;
left: 7.5vh;
}

#toggleClicks:hover {
background: rgba(255, 255, 255, 0.25);
}

#submit {
left: 4.2vh;
}
Expand Down
1 change: 1 addition & 0 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<div id="radio-container">
<img src="./img/radio.png" alt="" class="radio">

<div id="toggleClicks"></div>
<div class="channel">
<input id="channel" type="number" name="channel" min="1" max="500" placeholder="1-500">
</div>
Expand Down
7 changes: 7 additions & 0 deletions html/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ window.addEventListener('DOMContentLoaded', function () {
}
};

document.getElementById('toggleClicks').addEventListener('click', function (e) {
e.preventDefault();
fetch(`https://${GetParentResourceName()}/toggleClicks`, {
method: 'POST',
});
});

document.getElementById('submit').addEventListener('click', function (e) {
e.preventDefault();
fetch(`https://${GetParentResourceName()}/joinRadio`, {
Expand Down
12 changes: 12 additions & 0 deletions locales/cs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"not_on_channel": "Nejsi připojen k žádnému kanálu",
"on_channel": "Již jsi připojen k tomuto kanálu",
"joined_radio": "Připojil jsi se k: ",
"restricted_channel": "Nemůžeš se připojit k tomuto kanálu",
"invalid_channel": "Tato frekvence není k dispozici",
"left_channel": "Odešel jsi z kanálu",
"min_volume": "Rádio je již nastaveno na nejnižší hlasitost",
"max_volume": "Rádio je již nastaveno na maximální hlasitost",
"new_volume": "Nová hlasitost: ",
"new_channel": "Nový kanál: "
}
21 changes: 0 additions & 21 deletions locales/cs.lua

This file was deleted.

14 changes: 14 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"not_on_channel": "You're not connected to a channel",
"on_channel": "You're already connected to this channel",
"joined_radio": "You're connected to: ",
"restricted_channel": "You can not connect to this channel",
"invalid_channel": "This frequency is not available",
"left_channel": "You left the channel",
"min_volume": "The radio is already set to the lowest volume",
"max_volume": "he radio is already set to maximum volume",
"new_volume": "New volume: ",
"new_channel": "New channel: ",
"clicksOn": "Mic clicks are now on",
"clicksOff": "Mic clicks are now off"
}
17 changes: 0 additions & 17 deletions locales/en.lua

This file was deleted.

12 changes: 12 additions & 0 deletions locales/fi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"not_on_channel": "Et ole yhdistetty kanavalle",
"on_channel": "Olet jo yhdistetty tälle kanavalle",
"joined_radio": "Olet yhdistetty: ",
"restricted_channel": "Et voi yhdistää tähän kanavaan",
"invalid_channel": "Tämä taajuus ei ole käytettävissä",
"left_channel": "Poistuit kanavalta",
"min_volume": "Radio on jo asetettu alimpaan äänenvoimakkuuteen",
"max_volume": "Radio on jo asetettu maksimiäänenvoimakkuuteen",
"new_volume": "Uusi äänenvoimakkuus: ",
"new_channel": "Uusi kanava: "
}
17 changes: 0 additions & 17 deletions locales/fi.lua

This file was deleted.

14 changes: 14 additions & 0 deletions locales/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"not_on_channel": "Vous n'êtes pas connectés a une fréquence",
"on_channel": "Vous êtes déjà connectés a cette fréquence",
"joined_radio": "Vous vous êtes connectés à : ",
"restricted_channel": "Vous ne pouvez pas vous connecter à cette fréquence",
"invalid_channel": "Cette fréquence n'est pas disponible",
"left_channel": "Vous avez quitté la fréquence",
"min_volume": "Cette radio est déjà au volume minimum",
"max_volume": "Cette radio est déjà au volume maximum",
"new_volume": "Nouveau volume : ",
"new_channel": "Nouvelle fréquence : ",
"clicksOn": "Clicks radio activés",
"clicksOff": "Clicks radio désactivés"
}
17 changes: 0 additions & 17 deletions locales/fr.lua

This file was deleted.

0 comments on commit 9ff779e

Please sign in to comment.