Skip to content
Closed
Show file tree
Hide file tree
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
22 changes: 7 additions & 15 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,10 @@ local function IsRadioOn()
return onRadio
end

local function DoRadioCheck(PlayerItems)
local _hasRadio = false

for _, item in pairs(PlayerItems) do
if item.name == "radio" then
_hasRadio = true
break;
end
end

hasRadio = _hasRadio
local function DoRadioCheck()
QBCore.Functions.TriggerCallback("qb-radio::server::hasRadio", function(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the two double ::?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats stick with me when i was programming in altv

hasRadio = value
end)
end

--Exports
Expand All @@ -119,27 +112,26 @@ exports("IsRadioOn", IsRadioOn)
-- Handles state right when the player selects their character and location.
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
PlayerData = QBCore.Functions.GetPlayerData()
DoRadioCheck(PlayerData.items)
DoRadioCheck()
end)

-- Resets state on logout, in case of character change.
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
DoRadioCheck({})
PlayerData = {}
leaveradio()
end)

-- Handles state when PlayerData is changed. We're just looking for inventory updates.
RegisterNetEvent('QBCore:Player:SetPlayerData', function(val)
PlayerData = val
DoRadioCheck(PlayerData.items)
DoRadioCheck()
end)

-- Handles state if resource is restarted live.
AddEventHandler('onResourceStart', function(resource)
if GetCurrentResourceName() == resource then
PlayerData = QBCore.Functions.GetPlayerData()
DoRadioCheck(PlayerData.items)
DoRadioCheck()
end
end)

Expand Down
5 changes: 5 additions & 0 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ for channel, config in pairs(Config.RestrictedChannels) do
return config[Player.PlayerData.job.name] and Player.PlayerData.job.onduty
end)
end

QBCore.Functions.CreateCallback("qb-radio::server::hasRadio", function(source, cb)
local hasItems = exports['qb-inventory']:HasItem(source, "radio", 1)
cb(hasItems)
end)
Loading