API Reference
Complete API reference for Tommy's Radio exports, functions, and events.
API Reference
Server Exports
Channel Management
getAllChannels()
Get all active channels with user counts.
local channels = exports['radio']:getAllChannels()
-- Returns: table of all channels with active user information
getUsersInChannel(frequency)
Get list of users currently in a specific channel.
local users = exports['radio']:getUsersInChannel(154.755)
-- Parameters:
-- frequency (number): The channel frequency to check
-- Returns: table of server IDs currently on the channel
changeUserChannel(serverId, frequency)
Move a user to a different channel.
local success = exports['radio']:changeUserChannel(1, 155.475)
-- Parameters:
-- serverId (number): The player's server ID
-- frequency (number): Target channel frequency
-- Returns: boolean indicating success
disconnectUser(serverId)
Disconnect a user from the radio system.
local success = exports['radio']:disconnectUser(1)
-- Parameters:
-- serverId (number): The player's server ID to disconnect
-- Returns: boolean indicating success
Emergency Functions
setSignal100OnChannel(channel, enabled)
Enable or disable Signal 100 on a channel.
exports['radio']:setSignal100OnChannel(154.755, true)
-- Parameters:
-- channel (number): Channel frequency
-- enabled (boolean): true to enable Signal 100, false to disable
setChannelPanic(frequency, serverId, enabled)
Set panic button state for a user on a channel.
exports['radio']:setChannelPanic(154.755, 1, true)
-- Parameters:
-- frequency (number): Channel frequency
-- serverId (number): Player's server ID
-- enabled (boolean): true to activate panic, false to deactivate
getChannelSignal(frequency)
Get current Signal 100 state of a channel.
local isSignal100 = exports['radio']:getChannelSignal(154.755)
-- Parameters:
-- frequency (number): Channel frequency to check
-- Returns: boolean indicating if Signal 100 is active
getChannelPanic(frequency)
Get panic button states for a channel.
local panicUsers = exports['radio']:getChannelPanic(154.755)
-- Parameters:
-- frequency (number): Channel frequency to check
-- Returns: table of server IDs with active panic buttons
Audio Management
playToneOnChannel(radioChannel, tone)
Play a tone on a specific channel.
exports['radio']:playToneOnChannel(154.755, "beep")
-- Parameters:
-- radioChannel (number): Target channel frequency
-- tone (string): Tone identifier
playToneOnSource(source, tone)
Play a tone to a specific player.
exports['radio']:playToneOnSource(1, "alert")
-- Parameters:
-- source (number): Player's server ID
-- tone (string): Tone identifier to play
User Information
getUserNacId(serverId)
Get a user's NAC ID.
local nacId = exports['radio']:getUserNacId(1)
-- Parameters:
-- serverId (number): Player's server ID
-- Returns: string NAC ID or nil if not found
getUserInfo(serverId)
Get complete user information.
local userInfo = exports['radio']:getUserInfo(1)
-- Parameters:
-- serverId (number): Player's server ID
-- Returns: table with user data (nacId, name, etc.)
getPlayerName(serverId)
Get player's display name/callsign.
local name = exports['radio']:getPlayerName(1)
-- Parameters:
-- serverId (number): Player's server ID
-- Returns: string formatted name/callsign
Client Exports
Radio State
isConnected()
Check if radio is connected to voice server.
local connected = exports['radio']:isConnected()
-- Returns: boolean indicating connection status
isPowerOn()
Check if radio power is on.
local powerOn = exports['radio']:isPowerOn()
-- Returns: boolean indicating power state
isRadioOpen()
Check if radio interface is open.
local radioOpen = exports['radio']:isRadioOpen()
-- Returns: boolean indicating if UI is displayed
Channel Information
getFrequency()
Get current channel frequency.
local frequency = exports['radio']:getFrequency()
-- Returns: number representing current frequency, or -1 if not connected
getChannel()
Get current channel object.
local channel = exports['radio']:getChannel()
-- Returns: table with channel information
getZone()
Get current zone name.
local zoneName = exports['radio']:getZone()
-- Returns: string name of current zone
Radio Control
setSignalOnFreq(freq, enabled)
Set Signal 100 state on frequency.
exports['radio']:setSignalOnFreq(154.755, true)
-- Parameters:
-- freq (number): Target frequency
-- enabled (boolean): Signal 100 state
panicButton(freq, enabled)
Activate or deactivate panic button.
exports['radio']:panicButton(154.755, true)
-- Parameters:
-- freq (number): Target frequency
-- enabled (boolean): Panic button state
Audio Control
setVolume(volume)
Set voice volume level.
exports['radio']:setVolume(80)
-- Parameters:
-- volume (number): Volume level from 0-100
setToneVolume(volume)
Set tone volume level.
exports['radio']:setToneVolume(15)
-- Parameters:
-- volume (number): Tone volume level from 0-100
Events
Client Events
radio:connected
Radio connects to voice server.
AddEventHandler('radio:connected', function()
print('Radio connected')
end)
radio:disconnected
Radio disconnects from voice server.
AddEventHandler('radio:disconnected', function()
print('Radio disconnected')
end)
radio:channelChanged
User changes channels.
AddEventHandler('radio:channelChanged', function(channel)
print('Changed to channel: ' .. channel.name)
end)
radio:emergencyActivated
Panic button is activated.
AddEventHandler('radio:emergencyActivated', function(frequency)
print('Emergency on: ' .. frequency)
end)
Server Events
radio:userConnected
User connects to radio system.
AddEventHandler('radio:userConnected', function(serverId)
print('User ' .. serverId .. ' connected')
end)
radio:userDisconnected
User disconnects from radio system.
AddEventHandler('radio:userDisconnected', function(serverId)
print('User ' .. serverId .. ' disconnected')
end)
Usage Examples
Basic Channel Management
-- Server-side: Move user to different channel
local success = exports['radio']:changeUserChannel(GetPlayerServerId(player), 155.475)
if success then
print('User moved to new channel')
end
-- Get all users on a channel
local users = exports['radio']:getUsersInChannel(154.755)
for _, userId in ipairs(users) do
print('User ' .. userId .. ' is on channel')
end
Emergency System Integration
-- Server-side: Activate Signal 100 when panic button is pressed
AddEventHandler('radio:emergencyActivated', function(serverId)
local nacId = exports['radio']:getUserNacId(serverId)
if nacId == "100" then -- Police NAC ID
exports['radio']:setSignal100OnChannel(154.755, true)
-- Notify dispatch or other systems
TriggerEvent('dispatch:emergencyAlert', serverId)
end
end)
Custom Radio Integration
-- Client-side: Check radio state before performing actions
if exports['radio']:isConnected() and exports['radio']:isPowerOn() then
local currentFreq = exports['radio']:getFrequency()
if currentFreq == 154.755 then
-- User is on dispatch channel, allow certain actions
TriggerServerEvent('myresource:dispatchAction')
end
end
Error Handling
Important Notes
- Always check return values from export functions
- Server exports may return
nil
if the radio system isn't running - Client exports return
-1
orfalse
when radio is disconnected - NAC ID checks should handle
nil
returns gracefully
Example Error Handling
-- Safe way to get user info
local function getSafeUserInfo(serverId)
local userInfo = exports['radio']:getUserInfo(serverId)
if userInfo and userInfo.nacId then
return userInfo
else
return { nacId = "000", name = "Unknown" }
end
end
-- Safe channel operations
local function moveUserSafely(serverId, frequency)
if exports['radio'] then
local success = exports['radio']:changeUserChannel(serverId, frequency)
return success or false
end
return false
end