Skip to content

nut.chat

Extended Chatbox Module.

The NutScript chatbox is a custom implementation, rather than using the default GMOD chatbox. This allows the chatbox to contain additional features, such as multiple different chat types and categories.

Functions

nut.chat.timestamp (ooc)
nut.chat.timestamp

Returns a formatted timestamp for chat messages.

Parameters:

boolean ooc Whether timestamp is for OOC chat

Returns:

string The formatted timestamp

nut.chat.register (chatType, data)
nut.chat.register

Registers a new chat type with the information provided.

Parameters:

string chatType Unique identifier for the chat type

table data Configuration table for the chat type

See also:

Usage:

    1
    2
    3
    4
    5
    nut.chat.register("ic", {
        format = "%s says \"%s\"",
        radius = function() return 280 end,
        color = Color(255, 255, 255)
    })
    

nut.chat.parse (client, message, noSend)
nut.chat.parse

Parses a chat message to determine its type and processes it.

Parameters:

Client client The player sending the message

string message The chat message content

boolean noSend optional. default: false Whether to skip sending the message

Returns:

string The chat type used

string The processed message

bool Whether the sender is anonymous

nut.chat.send (speaker, chatType, text, anonymous, receivers)
nut.chat.send

Send a chat message using the specified chat type.

Parameters:

Client speaker The player sending the message

string chatType The type of chat message

string text The message content

boolean anonymous optional. default: false Whether sender should be anonymous

table receivers optional Optional list of specific receivers

Tables

ChatType
ChatType

Configuration table for registering a new chat type

Fields:

vararg radius Maximum hearing distance. If number, fixed distance from speaker in HU. Otherwise Function()

vararg prefix Command prefix(es) (string or table of strings)

string format The message format string (uses %s for name/text)

Color color Default color for this chat type

string font Custom font to use

string filter The chat filter category ("ic", "ooc", etc.)

boolean deadCanChat Whether dead players can use this chat

boolean noSpaceAfter If true, no space required after prefix (For instance with // "ooc", //text would be valid without the need to separate // from the message with a space)

function onCanSay Function(speaker, text) - checks if player can speak

function onCanHear Function(speaker, listener) - checks if listener can hear

function onChatAdd Function(speaker, text, anonymous) - custom display handler

function onGetColor Function(speaker, text) - dynamic color handler

See also:

Usage:

    {
        format = "%s says \"%s\"",
        color = Color(255,255,255),
        radius = 280,
        prefix = "/me",
        font = "nutChatFontItalics",
        filter = "actions",
        deadCanChat = true,
        onCanSay = function(speaker, text)
            return speaker:Alive()
        end,
        onGetColor = function(speaker)
            return team.GetColor(speaker:Team())
        end
    }