# API Reference

## Server Exports

### Channel Management

#### getAllChannels()

Get all active channels with user counts.

```lua
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.

```lua
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.

```lua
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.

```lua
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.

```lua
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.

```lua
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.

```lua
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.

```lua
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.

```lua
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.

```lua
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.

```lua
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.

```lua
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.

```lua
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.

```lua
local connected = exports['radio']:isConnected()
-- Returns: boolean indicating connection status
```

#### isPowerOn()

Check if radio power is on.

```lua
local powerOn = exports['radio']:isPowerOn()
-- Returns: boolean indicating power state
```

#### isRadioOpen()

Check if radio interface is open.

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

### Channel Information

#### getFrequency()

Get current channel frequency.

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

#### getChannel()

Get current channel object.

```lua
local channel = exports['radio']:getChannel()
-- Returns: table with channel information
```

#### getZone()

Get current zone name.

```lua
local zoneName = exports['radio']:getZone()
-- Returns: string name of current zone
```

### Radio Control

#### setSignalOnFreq(freq, enabled)

Set Signal 100 state on frequency.

```lua
exports['radio']:setSignalOnFreq(154.755, true)
-- Parameters:
--   freq (number): Target frequency
--   enabled (boolean): Signal 100 state
```

#### panicButton(freq, enabled)

Activate or deactivate panic button.

```lua
exports['radio']:panicButton(154.755, true)
-- Parameters:
--   freq (number): Target frequency
--   enabled (boolean): Panic button state
```

### Audio Control

#### setVolume(volume)

Set voice volume level.

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

#### setToneVolume(volume)

Set tone volume level.

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

***

## Events

### Client Events

#### radio:connected

Radio connects to voice server.

```lua
AddEventHandler('radio:connected', function()
    print('Radio connected')
end)
```

#### radio:disconnected

Radio disconnects from voice server.

```lua
AddEventHandler('radio:disconnected', function()
    print('Radio disconnected')
end)
```

#### radio:channelChanged

User changes channels.

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

#### radio:emergencyActivated

Panic button is activated.

```lua
AddEventHandler('radio:emergencyActivated', function(frequency)
    print('Emergency on: ' .. frequency)
end)
```

### Server Events

#### radio:userConnected

User connects to radio system.

```lua
AddEventHandler('radio:userConnected', function(serverId)
    print('User ' .. serverId .. ' connected')
end)
```

#### radio:userDisconnected

User disconnects from radio system.

```lua
AddEventHandler('radio:userDisconnected', function(serverId)
    print('User ' .. serverId .. ' disconnected')
end)
```

***
