@@ -188,46 +188,60 @@ end)
188
188
local function SetRadioData (src , slot )
189
189
local player = Framework .core .GetPlayer (src )
190
190
local radioId = player .id .. math.random (1000 , 9999 )
191
+ local name = player .charinfo .firstname .. " " .. player .charinfo .lastname
191
192
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 })
193
194
return radioId
194
195
elseif Shared .Inventory == ' qb' or Shared .Inventory == ' ps' then
195
196
local items = player .items
196
197
local item = items [slot ]
197
198
if item then
198
199
item .info = item .info or {}
199
- item .info .radioId = radioId
200
+ item .info = {
201
+ radioId = radioId ,
202
+ name = name
203
+ }
200
204
local invResourceName = exports .bl_bridge :getFramework (' inventory' )
201
205
exports [invResourceName ]:SetInventory (src , items )
202
206
return radioId
203
207
end
204
208
return false
205
209
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 })
207
211
return radioId
208
212
else
209
213
return false
210
214
end
211
215
end
212
216
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
215
229
local battery = 100
216
230
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
228
241
end
242
+ battery = id and batteryData [id ] or 100
229
243
end
230
- return battery
244
+ return battery , id
231
245
end )
232
246
233
247
lib .callback .register (' mm_radio:server:getjammer' , function ()
@@ -267,8 +281,8 @@ lib.versionCheck('SOH69/mm_radio')
267
281
268
282
if Shared .Ready then
269
283
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 )
272
286
end )
273
287
end
274
288
0 commit comments