Skip to content

Exports & events

Public API of Cuxial Chat: exports and events to send messages from other resources.

Send messages to the chat, open it or read its channels from your own resources. Resources written for the standard chat need no changes.

Server exports ​

message ​

Sends a message to one player, several players or everyone.

lua
exports.cuxial_chat:message(target, data)
ParameterTypeDescription
targetnumber | number[] | nilA server id, a list of ids, or -1 / nil for everyone.
data.textstringMessage text. Required. Cut at 600 characters.
data.channelstringChannel id from data/channels.lua. Unknown or missing = system.
data.authorstringName shown as author.
data.authorIdnumberServer id of the author. In a channel with bubbles, the message also appears above that player's head.
data.tostringName of the recipient, shown next to the author.
data.tagstableList of tags: { { label = 'Text', color = '#rrggbb' } }.
data.imagestringURL of an image shown with the message. It is not checked against images.hosts.
data.systembooleanMarks the message as a system message. Defaults to true when there is no author.

Returns: boolean. true when the message was sent; false when the data is invalid or no valid id was given.

lua
exports.cuxial_chat:message(source, {
    channel = 'sancion',
    text = 'You have been warned: *respect the safe zone*.',
    tags = { { label = 'Warning', color = '#f59e0b' } },
})

system ​

Shortcut for a system message.

lua
exports.cuxial_chat:system(target, text)
ParameterTypeDescription
targetnumber | number[] | nilA server id, a list of ids, or -1 / nil for everyone.
textstringMessage text.

Returns: boolean.

lua
exports.cuxial_chat:system(-1, 'Server restart in 10 minutes.')

getChannels ​

Returns the channel list with the labels already translated.

lua
local channels = exports.cuxial_chat:getChannels()

Returns: table[]. Each entry has the fields of data/channels.lua (id, label, voice, color, tab, order, icon, command...).

lua
for _, channel in ipairs(exports.cuxial_chat:getChannels()) do
    print(channel.id, channel.label, channel.color)
end

Client exports ​

addMessage ​

Shows a system message to the local player.

lua
exports.cuxial_chat:addMessage(text, channel)
ParameterTypeDescription
textstringMessage text.
channelstringChannel id. Optional; system by default.
lua
exports.cuxial_chat:addMessage('Vehicle stored.')

open ​

Opens the chat, optionally on a given channel. Does nothing if the chat is already open.

lua
exports.cuxial_chat:open(channel)
ParameterTypeDescription
channelstringChannel id. Optional.
lua
exports.cuxial_chat:open('ooc')

close ​

Closes the chat.

lua
exports.cuxial_chat:close()

isOpen ​

Tells whether the chat is open.

lua
local open = exports.cuxial_chat:isOpen()

Returns: boolean.

lua
if exports.cuxial_chat:isOpen() then return end

refreshMask ​

Re-checks whether the player is wearing a mask. The chat already checks each time it opens. Call this export from your clothing resource after changing the mask so the anonymous name updates at once.

lua
exports.cuxial_chat:refreshMask()

The result is published in the player state bag chatMasked (boolean), which other resources can read. It is only published with anonymous.enabled = true.

Standard chat compatibility ​

Cuxial Chat provides the chat resource, so code written for the default chat keeps working. These messages are shown in the system channel.

exports.chat:addMessage ​

lua
exports.chat:addMessage({
    color = { 255, 200, 0 },
    args = { 'Garage', 'Vehicle stored.' },
})

Accepted forms of the message:

FormResult
A plain stringShown as the text.
args = { 'Author', 'Text' }Author and text.
args = { 'Text' }Text only.
templateUsed only when args carries no text. Shown as plain text, with HTML tags removed.
color = { r, g, b }Adds a coloured tag to the message.

Client events ​

EventParametersWhat it does
chat:addMessagemessageAdds a message. Same forms as the export.
chatMessageauthor, color, textAdds a message in the legacy format.
chat:clearnoneClears the chat.
chat:shownoneOpens the chat.
chat:addSuggestioncommand, help, paramsAdds a command to the autocomplete list.
chat:addSuggestionslistAdds several commands. Each entry has name, help and params.
chat:removeSuggestioncommandRemoves a command from the list.
lua
TriggerClientEvent('chat:addSuggestion', -1, '/repair', 'Repair the vehicle', {
    { name = 'id', help = 'Player id' },
})

Server event: chatMessage ​

Triggered on the server before a message written without a command is delivered. Cancel it to block the message.

ParameterTypeDescription
sourcenumberServer id of the author.
namestringCharacter name.
textstringMessage text.
lua
AddEventHandler('chatMessage', function(source, name, text)
    if text:find('forbidden') then
        CancelEvent()
    end
end)

Messages sent with a command (/me, /do, /pm...) do not trigger this event.

© Cuxial