Violet

Chat

On this page

Read chat as it appears in the chat window, and send chat messages from a script.

Receiving

on_chat(sender: string, message: string, channel: string, type: number)

Available on GMS and CW

Called for every chat message the client displays. sender is the IGN that sent it (empty for system lines), message is the text, channel is the channel it arrived on, and type is the raw chat-log type code (handy for telling megaphone sub-kinds apart).

This callback is observe-only — it cannot block or modify the message.

channelSource
"public"Normal map chat (anyone speaking in your field)
"whisper"Whisper / private message
"party"Party chat
"buddy"Buddy (friend) chat
"guild"Guild chat
"alliance"Alliance chat
"megaphone"World / super megaphone
Info

System notices, item-drop messages and other non-chat log lines are not reported. Your own outgoing messages are included.

System messages

on_system_message(message: string, chat_type: number, channel_id: number)

Available on CW

Observes system and error text displayed in the chat log on the following tick; message is the complete text, without splitting it into a sender and message. This callback cannot block or change the message.

chat_type and channel_id are raw numeric chat-log values. Only non-player types (outside 0 through 5) with a negative channel_id are included. Player chat continues to use on_chat.

This does not report errors shown only in a dialog. Receiving a message does not by itself confirm that a store opened or identify which request caused it. Messages can be dropped when more than 128 await delivery or a message exceeds 8192 bytes before text conversion. Pending messages are discarded on map changes or Panic Mode.

Check callback registration before depending on it:

lua
local supported, callback_id = pcall(core.register_callback, "on_system_message", function(message, chat_type, channel_id)
    core.log(message)
end)

if not supported then
    core.log_warning("System messages are unavailable in this core")
end

Sending

core.chat.send(message: string, channel?: string) -> boolean

Available on GMS and CW

Sends a chat message. channel defaults to "public"; valid values are "public", "party", "buddy", "guild", and "alliance". Returns true on success, or false plus an error string.

Warning

For "public", a message beginning with / is sent as a chat command — exactly as if you had typed it into the chat box.

core.chat.whisper(target: string, message: string) -> boolean

Available on GMS and CW

Whispers message to the player named target. Returns true on success, or false plus an error string (target/message empty, or not currently in a field). This is the scripted equivalent of typing the whisper into the chat box — you must be in a field, and whispering yourself is ignored.

Plugin Required

on_chat must be part of a plugin with proper metadata structure.

Example

lua
plugin = {
    name = "Chat Logger",
    author = "YourName",
    version = "1.0",
    description = "Logs chat and auto-replies to whispers",
    load = true
}

function on_chat(sender, message, channel, type)
    core.log(string.format("[%s] %s: %s", channel, sender, message))

    if channel == "whisper" then
        core.chat.whisper(sender, "Auto-reply: I'm busy right now!")
    end
end