Skip to content

Commit a433464

Browse files
authored
Merge pull request #58 from SOH69/dev
New Updates v2.0.7
2 parents 95bc528 + 46c2a06 commit a433464

24 files changed

+1093
-838
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
/build

client/event.lua

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ AddEventHandler('onResourceStop', function(resource)
1818
end
1919
end)
2020

21-
RegisterNetEvent('mm_radio:client:use', function()
21+
RegisterNetEvent('mm_radio:client:use', function(slot)
2222
if Radio.PlayerDead or IsPedFatallyInjured(cache.ped) then return end
2323
Radio.usingRadio = true
2424
SetNuiFocus(true, true)
2525
Radio:toggleRadioAnimation(true)
26-
local battery = lib.callback.await('mm_radio:server:getbatterydata', false)
26+
local battery, radioId = lib.callback.await('mm_radio:server:getradiodata', false, slot)
27+
local userdata = Radio.userData[Radio.identifier]
2728
Radio:SendSvelteMessage("setRadioVisible", {
29+
radioId = radioId,
2830
onRadio = Radio.onRadio,
2931
channel = Radio.RadioChannel,
3032
volume = Radio.Volume,
3133
favourite = Radio.favourite,
3234
recomended = Radio.recomended,
33-
userData = Radio.userData[Radio.identifier],
35+
userData = userdata,
3436
time = Radio:CalculateTimeToDisplay(),
3537
street = Radio:getCrossroads(),
3638
maxChannel = Shared.MaxFrequency,
@@ -41,7 +43,7 @@ RegisterNetEvent('mm_radio:client:use', function()
4143
overlay = Shared.Overlay
4244
})
4345
UpdateTime()
44-
if Radio.userData[Radio.identifier].allowMovement then
46+
if userdata.allowMovement then
4547
SetNuiFocusKeepInput(true)
4648
DisableControls()
4749
end

client/function.lua

+7-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ function Radio:Init(data)
9191
self.favourite[#self.favourite+1] = val
9292
end
9393
end
94+
95+
if not self.userData[self.identifier].enableClicks then
96+
exports['pma-voice']:setVoiceProperty('micClicks', false)
97+
end
98+
9499
self:doRadioCheck()
95100
end
96101

@@ -145,8 +150,9 @@ function Radio:leaveradio()
145150
end
146151

147152
function Radio:update()
148-
local battery = lib.callback.await('mm_radio:server:getbatterydata', false)
153+
local battery, radioId = lib.callback.await('mm_radio:server:getradiodata', false)
149154
self:SendSvelteMessage("updateRadio", {
155+
radioId = radioId,
150156
onRadio = Radio.onRadio,
151157
channel = Radio.RadioChannel,
152158
volume = Radio.Volume,

client/nui.lua

+25-3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ RegisterNUICallback('allowMovement', function(data, cb)
101101
cb("ok")
102102
end)
103103

104+
RegisterNUICallback('enableClicks', function(data, cb)
105+
Radio.userData[Radio.identifier].enableClicks = data
106+
SetResourceKvp('radioSettings2', json.encode(Radio.userData))
107+
exports['pma-voice']:setVoiceProperty('micClicks', data)
108+
cb("ok")
109+
end)
110+
104111
RegisterNUICallback('updateRadioSize', function(data, cb)
105112
Radio.userData[Radio.identifier].radioSizeMultiplier = data.radio
106113
Radio.userData[Radio.identifier].overlaySizeMultiplier = data.overlay
@@ -112,9 +119,24 @@ RegisterNUICallback('saveData', function(data, cb)
112119
local player = Framework.core.getPlayerData()
113120
local identifier = player.cid
114121
if not identifier then return Radio:Notify(locale('unsuccess_name', channel)) end
115-
Radio.userData[Radio.identifier].name = data
122+
Radio.userData[Radio.identifier].name = data.name
116123
Radio:update()
117-
TriggerServerEvent('mm_radio:server:addToRadioChannel', Radio.RadioChannel, data)
124+
TriggerServerEvent('mm_radio:server:addToRadioChannel', Radio.RadioChannel, data.name)
118125
SetResourceKvp('radioSettings2', json.encode(Radio.userData))
119-
cb("ok")
126+
cb(retreval)
127+
end)
128+
129+
RegisterNUICallback('getMutedList', function(_, cb)
130+
cb(exports['pma-voice']:getMutedPlayers())
131+
end)
132+
133+
RegisterNUICallback('togglemutePlayer', function(data, cb)
134+
if data == cache.serverId then
135+
Radio:Notify(locale('failed_mute'))
136+
return cb(nil)
137+
end
138+
exports['pma-voice']:toggleMutePlayer(data)
139+
Wait(100)
140+
print(json.encode(exports['pma-voice']:getMutedPlayers()))
141+
cb(exports['pma-voice']:getMutedPlayers())
120142
end)

fxmanifest.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fx_version 'cerulean'
22
game "gta5"
33

44
author "Master Mind"
5-
version '2.0.6'
5+
version '2.0.7'
66
description 'A beautiful Radio Resource for FiveM'
77
repository 'https://github.com/SOH69/mm_radio'
88

locales/cs.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"frequency": "Frekvence",
1515
"disconnect": "ODPOJIT",
1616
"notconnected": "NEPŘIPOJENO",
17+
"settings": "Nastavení",
1718
"channels": "Kanály",
1819
"radio": "Rádio",
1920
"members": "Členové",

locales/de.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"frequency": "Frequenz",
1515
"disconnect": "TRENNEN",
1616
"notconnected": "NICHT VERBUNDEN",
17+
"settings": "Einstellungen",
1718
"channels": "Kanäle",
1819
"radio": "Radio",
1920
"members": "Mitglieder",
@@ -26,6 +27,7 @@
2627
"radio_settings": "RADIOEINSTELLUNGEN",
2728
"move_radio": "RADIO BEWEGEN",
2829
"allow_move": "BEWEGEN ERLAUBEN",
29-
"overlay_settings": "OVERLAYEINSTELLUNGEN"
30+
"overlay_settings": "OVERLAYEINSTELLUNGEN",
31+
"enableClicks": "Funkgeräusch"
3032
}
3133
}

locales/en.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
"jammer_notify_description": "Failed to Connect to Station %.2f MHz",
99
"toggle_defean": "Radio Deafened",
1010
"toggle_undeafen": "Radio Undeafened",
11+
"failed_mute": "Failed to Mute Player",
1112

1213
"ui": {
1314
"header": "IN RADIO",
1415
"frequency": "Frequency",
1516
"disconnect": "DISCONNECT",
1617
"notconnected": "NOT CONNECTED",
18+
"settings": "Settings",
1719
"channels": "Channels",
1820
"radio": "Radio",
1921
"members": "Members",
@@ -26,6 +28,7 @@
2628
"radio_settings": "Radio Settings",
2729
"move_radio": "Move Radio",
2830
"allow_move": "Allow Move",
29-
"overlay_settings": "Overlay Settings"
31+
"overlay_settings": "Overlay Settings",
32+
"enableClicks": "Radio Sound"
3033
}
3134
}

locales/es.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"frequency": "Frecuencia",
1515
"disconnect": "DESCONECTAR",
1616
"notconnected": "NO CONECTADA",
17+
"settings": "Ajustes",
1718
"channels": "Canales",
1819
"radio": "Radio",
1920
"members": "Miembros",

locales/fr.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"frequency": "Fréquence",
1515
"disconnect": "DÉCONNECTER",
1616
"notconnected": "PAS CONNECTÉ",
17+
"settings": "Paramètres",
1718
"channels": "Canaux",
1819
"radio": "Radio",
1920
"members": "Membres",

server/main.lua

+33-19
Original file line numberDiff line numberDiff line change
@@ -188,46 +188,60 @@ end)
188188
local function SetRadioData(src, slot)
189189
local player = Framework.core.GetPlayer(src)
190190
local radioId = player.id .. math.random(1000, 9999)
191+
local name = player.charinfo.firstname .. " " .. player.charinfo.lastname
191192
if Shared.Inventory == 'ox' then
192-
exports.ox_inventory:SetMetadata(src, slot, { radioId = radioId })
193+
exports.ox_inventory:SetMetadata(src, slot, { radioId = radioId, name = name })
193194
return radioId
194195
elseif Shared.Inventory == 'qb' or Shared.Inventory == 'ps' then
195196
local items = player.items
196197
local item = items[slot]
197198
if item then
198199
item.info = item.info or {}
199-
item.info.radioId = radioId
200+
item.info ={
201+
radioId = radioId,
202+
name = name
203+
}
200204
local invResourceName = exports.bl_bridge:getFramework('inventory')
201205
exports[invResourceName]:SetInventory(src, items)
202206
return radioId
203207
end
204208
return false
205209
elseif Shared.Inventory == 'qs' then
206-
exports['qs-inventory']:SetItemMetadata(src, slot, { radioId = radioId })
210+
exports['qs-inventory']:SetItemMetadata(src, slot, { radioId = radioId, name = name })
207211
return radioId
208212
else
209213
return false
210214
end
211215
end
212216

213-
lib.callback.register('mm_radio:server:getbatterydata', function(source)
214-
if not Shared.Inventory or not Shared.Battery.state then return 100 end
217+
local function GetSlotWithRadio(source)
218+
local player = Framework.core.GetPlayer(source)
219+
for i=1, #Shared.RadioItem do
220+
local item = player.getItem(Shared.RadioItem[i])
221+
if item then
222+
return item.slot
223+
end
224+
end
225+
end
226+
227+
lib.callback.register('mm_radio:server:getradiodata', function(source, slot)
228+
if not Shared.Inventory or not Shared.Battery.state then return 100, 'PERSONAL' end
215229
local battery = 100
216230
local player = Framework.core.GetPlayer(source)
217-
for _, slotData in pairs(player.items) do
218-
if slotData and lib.table.contains(Shared.RadioItem, slotData.name) then
219-
local item = slotData
220-
local id = false
221-
if not item.metadata?.radioId then
222-
id = SetRadioData(source, item.slot)
223-
else
224-
id = item.metadata?.radioId
225-
end
226-
battery = id and batteryData[id] or 100
227-
break
231+
if not slot then
232+
slot = GetSlotWithRadio(source)
233+
end
234+
local slotData = player.items[slot]
235+
if slotData and lib.table.contains(Shared.RadioItem, slotData.name) then
236+
local id = false
237+
if not slotData.metadata?.radioId then
238+
id = SetRadioData(source, slot)
239+
else
240+
id = slotData.metadata?.radioId
228241
end
242+
battery = id and batteryData[id] or 100
229243
end
230-
return battery
244+
return battery, id
231245
end)
232246

233247
lib.callback.register('mm_radio:server:getjammer', function()
@@ -267,8 +281,8 @@ lib.versionCheck('SOH69/mm_radio')
267281

268282
if Shared.Ready then
269283
for i=1, #Shared.RadioItem do
270-
Framework.core.RegisterUsableItem(Shared.RadioItem[i], function(source)
271-
TriggerClientEvent('mm_radio:client:use', source)
284+
Framework.core.RegisterUsableItem(Shared.RadioItem[i], function(source, slot, metadata)
285+
TriggerClientEvent('mm_radio:client:use', source, slot, metadata)
272286
end)
273287
end
274288

0 commit comments

Comments
 (0)