Skip to content

Exports & Events

Client and server exports, chat compatibility events, hooks, and suggestions.

0r-chat registers exports and stays compatible with the default chat event names via provide 'chat'. Prefer exports from your own resources; use the chat:* events when you need stock-chat compatibility.


Message payload#

FieldTypeNotes
typestringMust exist in messageTypes (falls back to defaultMessageType)
authorstringDisplay name
messagestringBody text (sanitized)
argstableLegacy: [author, message] or [message] — still accepted on server
multilinebooleanOptional
tagstableOptional author tags
colorstringOptional color override
senderIdnumberOptional server id
proximitybooleanMark as proximity-related when relevant
imageUrlstringUsed for image messages from the UI / /img flow

Client exports#

ExportSignaturePurpose
openChat()Open and focus chat
closeChat()Close chat
isChatOpen() → booleanWhether chat is focused
clearChat()Clear local message list
addMessage(data)Add a message on this client
registerChatHook(callback) → hook|falseBlock open if callback returns false
canOpenChat() → booleanRun all hooks; false if any blocks
addSuggestion(command, help, params?)Register one suggestion
addSuggestions(suggestions[])Register many
removeSuggestion(command)Remove a suggestion
display3D(playerId, data)Show a local 3D bubble above a player

Open / close example#

lua
exports['0r-chat']:openChat()

if exports['0r-chat']:isChatOpen() then
    exports['0r-chat']:closeChat()
end

Hook example#

Requires enableHooks = true in config. Return false to prevent opening.

lua
local hook = exports['0r-chat']:registerChatHook(function()
    if LocalPlayer.state.busy then
        return false
    end
end)

-- later
if hook then
    hook:delete()
end

Suggestion example#

lua
exports['0r-chat']:addSuggestion('/report', 'Report a player', {
    { name = 'id', help = 'Server ID' },
    { name = 'reason', help = 'Why you are reporting' },
})

Server exports#

ExportSignaturePurpose
addMessage(targets?, data)Send chat to targets; message table alone broadcasts
display3D(targets, sourceId, data)Show a 3D bubble above sourceId for targets

targets can be a player id, a list of ids, or -1 for everyone. If the first argument is already a message table (message or args), it broadcasts.

Broadcast example#

lua
exports['0r-chat']:addMessage({
    type = 'system',
    author = 'SYSTEM',
    message = 'Server restart in 5 minutes.',
})

Targeted example#

lua
exports['0r-chat']:addMessage(source, {
    type = 'pm',
    author = 'Staff',
    message = 'Please read the rules.',
})

3D example#

lua
exports['0r-chat']:display3D(nil, source, {
    text = 'looks around',
    type = 'me',
})

Pass nil for targets to use nearby players when useServerProximity is on, or everyone otherwise. data supports text, optional type, author, and duration.


Compatibility events#

These mirror the default chat API so older scripts keep working:

EventSideRole
chat:addMessageClient + serverAdd / relay a message
chat:addSuggestionClientAdd one suggestion
chat:addSuggestionsClientAdd many
chat:removeSuggestionClientRemove one

Resource-scoped events also cover addMessage, suggestions, proximity sends, dice/RPS, typing, display3D, and song preview. Prefer exports for new integrations.


Client listenables#

Other resources can listen for:

EventWhen
0r-chat:client:chatOpenedChat gained focus
0r-chat:client:chatClosedChat lost focus
0r-chat:client:messageAddedA message was added to the local list
0r-chat:client:messageSentThe local player sent a message