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.
exports.cuxial_chat:message(target, data)| Parameter | Type | Description |
|---|---|---|
target | number | number[] | nil | A server id, a list of ids, or -1 / nil for everyone. |
data.text | string | Message text. Required. Cut at 600 characters. |
data.channel | string | Channel id from data/channels.lua. Unknown or missing = system. |
data.author | string | Name shown as author. |
data.authorId | number | Server id of the author. In a channel with bubbles, the message also appears above that player's head. |
data.to | string | Name of the recipient, shown next to the author. |
data.tags | table | List of tags: { { label = 'Text', color = '#rrggbb' } }. |
data.image | string | URL of an image shown with the message. It is not checked against images.hosts. |
data.system | boolean | Marks 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.
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.
exports.cuxial_chat:system(target, text)| Parameter | Type | Description |
|---|---|---|
target | number | number[] | nil | A server id, a list of ids, or -1 / nil for everyone. |
text | string | Message text. |
Returns: boolean.
exports.cuxial_chat:system(-1, 'Server restart in 10 minutes.')getChannels
Returns the channel list with the labels already translated.
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...).
for _, channel in ipairs(exports.cuxial_chat:getChannels()) do
print(channel.id, channel.label, channel.color)
endClient exports
addMessage
Shows a system message to the local player.
exports.cuxial_chat:addMessage(text, channel)| Parameter | Type | Description |
|---|---|---|
text | string | Message text. |
channel | string | Channel id. Optional; system by default. |
exports.cuxial_chat:addMessage('Vehicle stored.')open
Opens the chat, optionally on a given channel. Does nothing if the chat is already open.
exports.cuxial_chat:open(channel)| Parameter | Type | Description |
|---|---|---|
channel | string | Channel id. Optional. |
exports.cuxial_chat:open('ooc')close
Closes the chat.
exports.cuxial_chat:close()isOpen
Tells whether the chat is open.
local open = exports.cuxial_chat:isOpen()Returns: boolean.
if exports.cuxial_chat:isOpen() then return endrefreshMask
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.
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
exports.chat:addMessage({
color = { 255, 200, 0 },
args = { 'Garage', 'Vehicle stored.' },
})Accepted forms of the message:
| Form | Result |
|---|---|
| A plain string | Shown as the text. |
args = { 'Author', 'Text' } | Author and text. |
args = { 'Text' } | Text only. |
template | Used 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
| Event | Parameters | What it does |
|---|---|---|
chat:addMessage | message | Adds a message. Same forms as the export. |
chatMessage | author, color, text | Adds a message in the legacy format. |
chat:clear | none | Clears the chat. |
chat:show | none | Opens the chat. |
chat:addSuggestion | command, help, params | Adds a command to the autocomplete list. |
chat:addSuggestions | list | Adds several commands. Each entry has name, help and params. |
chat:removeSuggestion | command | Removes a command from the list. |
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.
| Parameter | Type | Description |
|---|---|---|
source | number | Server id of the author. |
name | string | Character name. |
text | string | Message text. |
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.
