TIMMYG Studios

API Reference

Complete API reference for Tommy's Radio exports, functions, and events.

API Reference

Server ExportsClient ExportsEvents

Server Exports

Channel Management

getAllChannels()

Get all active channels with user counts.

Get All Channels
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.

Get Users in 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.

Change User 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.

Disconnect User
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.

Set Signal 100
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.

Set Channel Panic
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.

Get Channel Signal
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.

Get Channel Panic
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.

Play Tone on 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.

Play Tone to 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.

Get User 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.

Get User Info
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.

Get Player Name
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.

Check Connection Status
local connected = exports['radio']:isConnected()
-- Returns: boolean indicating connection status

isPowerOn()

Check if radio power is on.

Check Power State
local powerOn = exports['radio']:isPowerOn()
-- Returns: boolean indicating power state

isRadioOpen()

Check if radio interface is open.

Check Radio UI State
local radioOpen = exports['radio']:isRadioOpen()
-- Returns: boolean indicating if UI is displayed

Channel Information

getFrequency()

Get current channel frequency.

Get Current Frequency
local frequency = exports['radio']:getFrequency()
-- Returns: number representing current frequency, or -1 if not connected

getChannel()

Get current channel object.

Get Current Channel
local channel = exports['radio']:getChannel()
-- Returns: table with channel information

getZone()

Get current zone name.

Get Current Zone
local zoneName = exports['radio']:getZone()
-- Returns: string name of current zone

Radio Control

setSignalOnFreq(freq, enabled)

Set Signal 100 state on frequency.

Set Signal 100 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.

Control 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.

Set Voice Volume
exports['radio']:setVolume(80)
-- Parameters:
--   volume (number): Volume level from 0-100

setToneVolume(volume)

Set tone volume level.

Set Tone Volume
exports['radio']:setToneVolume(15)
-- Parameters:
--   volume (number): Tone volume level from 0-100

Events

Client Events

radio:connected

Radio connects to voice server.

Radio Connected Event
AddEventHandler('radio:connected', function()
    print('Radio connected')
end)

radio:disconnected

Radio disconnects from voice server.

Radio Disconnected Event
AddEventHandler('radio:disconnected', function()
    print('Radio disconnected')
end)

radio:channelChanged

User changes channels.

Channel Changed Event
AddEventHandler('radio:channelChanged', function(channel)
    print('Changed to channel: ' .. channel.name)
end)

radio:emergencyActivated

Panic button is activated.

Emergency Activated Event
AddEventHandler('radio:emergencyActivated', function(frequency)
    print('Emergency on: ' .. frequency)
end)

Server Events

radio:userConnected

User connects to radio system.

User Connected Event
AddEventHandler('radio:userConnected', function(serverId)
    print('User ' .. serverId .. ' connected')
end)

radio:userDisconnected

User disconnects from radio system.

User Disconnected Event
AddEventHandler('radio:userDisconnected', function(serverId)
    print('User ' .. serverId .. ' disconnected')
end)

Usage Examples

Code Examples

Basic Channel Management

Channel Management Example
-- 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

Emergency Integration Example
-- 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

Custom Integration Example
-- 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

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 or false when radio is disconnected
  • NAC ID checks should handle nil returns gracefully

Example Error Handling

Error Handling Example
-- 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