Skip to main content
The Chat component manages command registration, message broadcasting, and service communication (911/311 dispatch).

Overview

Access via Chat (server-side only).

Commands

Register custom chat commands

Messaging

System, OOC, and broadcast messages

Emergency Services

911/311 calls and dispatch

Staff Commands

Admin and staff command registration
Server-Side Only: All chat operations must be performed on the server.

Command Registration

Chat:RegisterCommand

Register a custom chat command accessible to all players.
Chat:RegisterCommand(command, callback, suggestion, arguments, job)
command
string
required
Command name without the / prefix
callback
function
required
Handler function: function(source, args, rawCommand)
suggestion
table
Command suggestion shown in chat: { help = "description", params = {} }
arguments
number
Expected argument count. Use -1 for variable arguments.
job
table
Job requirements to use the command
Examples:
-- Simple command
Chat:RegisterCommand('me', function(source, args, rawCommand)
    local message = table.concat(args, ' ')
    local player = Fetch:Source(source)
    local char = player:GetData('Character')
    local name = char:GetData('First') .. ' ' .. char:GetData('Last')

    -- Broadcast to nearby players
    Chat.Send.System:Single(source, name .. ' ' .. message)
end, {
    help = 'Roleplay action',
    params = {
        { name = 'action', help = 'What your character does' }
    }
}, -1)

-- Job-restricted command
Chat:RegisterCommand('cuff', function(source, args, rawCommand)
    local targetId = tonumber(args[1])
    if not targetId then return end

    TriggerEvent('mythic-police:server:CuffPlayer', source, targetId)
end, {
    help = 'Cuff a player',
    params = {
        { name = 'id', help = 'Target player ID' }
    }
}, 1, {
    job = 'police',
    reqDuty = true
})

Chat:RegisterAdminCommand

Register a command that requires admin permissions.
Chat:RegisterAdminCommand(command, callback, suggestion, arguments)
Parameters are the same as RegisterCommand (without job). Example:
Chat:RegisterAdminCommand('heal', function(source, args, rawCommand)
    local targetId = tonumber(args[1]) or source
    Callbacks:ClientCallback(targetId, 'Damage:Heal', true)

    Chat.Send.System:Single(source, 'Player healed')
end, {
    help = 'Heal a player',
    params = {
        { name = 'id', help = 'Target player ID (optional)' }
    }
}, -1)

Chat:RegisterStaffCommand

Register a command that requires staff permissions.
Chat:RegisterStaffCommand(command, callback, suggestion, arguments)

Chat:Refresh:Commands

Refresh the command suggestion list for a specific player. Call this after duty changes or job updates.
Chat:Refresh:Commands(source)
source
number
required
Player server ID

Chat:ClearAll

Clear the chat for all connected players.
Chat:ClearAll()

Message Sending

Chat.Send.Server:All

Send a server message to all players.
Chat.Send.Server:All(message)
message
string
required
Message text
Example:
Chat.Send.Server:All('Server restart in 5 minutes')

Chat.Send.Server:Single

Send a server message to a single player.
Chat.Send.Server:Single(source, message)
source
number
required
Player server ID
message
string
required
Message text

Chat.Send.System:All

Broadcast a system message to all players.
Chat.Send.System:All(message)

Chat.Send.System:Single

Send a system message to a single player.
Chat.Send.System:Single(source, message)
Example:
-- Feedback to a player after a command
Chat.Send.System:Single(source, 'Your request has been submitted')

Chat.Send.System:Broadcast

Broadcast a system-wide message.
Chat.Send.System:Broadcast(message)

Chat.Send.Broadcast:All

Send a broadcast message with an author.
Chat.Send.Broadcast:All(author, message)
author
string
required
Author/sender name
message
string
required
Message text

Chat.Send.OOC

Send an Out-of-Character message from a player.
Chat.Send.OOC(source, message)

Emergency Services

Chat.Send.Services:Emergency

Send a 911 emergency call (visible to on-duty police and EMS).
Chat.Send.Services:Emergency(source, message)
source
number
required
Caller’s server ID
message
string
required
Emergency description
Example:
-- Player calls 911
Chat.Send.Services:Emergency(source, 'Shots fired at Legion Square, multiple victims')

Chat.Send.Services:EmergencyAnonymous

Send an anonymous 911 call.
Chat.Send.Services:EmergencyAnonymous(source, message)

Chat.Send.Services:EmergencyRespond

Send a 911 response to a specific caller.
Chat.Send.Services:EmergencyRespond(source, target, message)
source
number
required
Responder’s server ID
target
number
required
Original caller’s server ID
message
string
required
Response message

Chat.Send.Services:NonEmergency

Send a 311 non-emergency call.
Chat.Send.Services:NonEmergency(source, message)

Chat.Send.Services:NonEmergencyAnonymous

Send an anonymous 311 call.
Chat.Send.Services:NonEmergencyAnonymous(source, message)

Chat.Send.Services:NonEmergencyRespond

Send a 311 response to a caller.
Chat.Send.Services:NonEmergencyRespond(source, target, message)

Chat.Send.Services:Dispatch

Send a dispatch message to a player.
Chat.Send.Services:Dispatch(source, message)

Chat.Send.Services:TestResult

Send a test result message to a player.
Chat.Send.Services:TestResult(source, message)

Best Practices

-- When a player goes on duty, refresh their commands
AddEventHandler('mythic-jobs:server:ClockedIn', function(source, characterId, jobName)
    Chat:Refresh:Commands(source)
end)

AddEventHandler('mythic-jobs:server:ClockedOut', function(source, characterId, jobName)
    Chat:Refresh:Commands(source)
end)
Chat:RegisterCommand('give', function(source, args, rawCommand)
    local targetId = tonumber(args[1])
    local item = args[2]
    local count = tonumber(args[3]) or 1

    if not targetId or not item then
        Chat.Send.System:Single(source, 'Usage: /give [id] [item] [count]')
        return
    end

    -- Process command
end, {
    help = 'Give item to player',
    params = {
        { name = 'id', help = 'Target player ID' },
        { name = 'item', help = 'Item name' },
        { name = 'count', help = 'Amount (default: 1)' }
    }
}, 2)

Next Steps

Chat - Events

Chat events and message types

Admin Commands

Admin command reference

Jobs API

Job system for command restrictions