Skip to content

Chatbox Library

Comprehensive chat system management with message routing and formatting for the Lilia framework.


Overview

The chatbox library provides comprehensive functionality for managing chat systems in the Lilia framework. It handles registration of different chat types (IC, OOC, whisper, etc.), message parsing and routing, distance-based hearing mechanics, and chat formatting. The library operates on both server and client sides, with the server managing message distribution and validation, while the client handles parsing and display formatting. It includes support for anonymous messaging, custom prefixes, radius-based communication, and integration with the command system for chat-based commands.


lia.chat.timestamp(ooc)

Prepend a timestamp to chat messages based on option settings.

During chat display formatting (client) to show the time.

Parameters:

boolean ooc Whether the chat is OOC (affects spacing).

Returns:

string Timestamp text or empty string.

Example Usage:

    chat.AddText(lia.chat.timestamp(false), Color(255,255,255), message)

lia.chat.register(chatType, data)

Register a chat class (IC/OOC/whisper/custom) with prefixes and rules.

On initialization to add new chat types and bind aliases/commands.

Parameters:

string chatType

table data Fields: prefix, radius/onCanHear, onCanSay, format, color, arguments, etc.

Example Usage:

    lia.chat.register("yell", {
        prefix = {"/y", "/yell"},
        radius = 600,
        format = "chatYellFormat",
        arguments = {{name = "message", type = "string"}},
        onChatAdd = function(speaker, text) chat.AddText(Color(255,200,120), "[Y] ", speaker:Name(), ": ", text) end
    })

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

Parse a raw chat message to determine chat type, strip prefixes, and send.

On client (local send) and server (routing) before dispatching chat.

Parameters:

Player client

string message

boolean noSend optional If true, do not forward to recipients (client-side parsing only).

Returns:

string, string, boolean chatType, message, anonymous

Example Usage:

    -- client
    lia.chat.parse(LocalPlayer(), "/y Hello there!")
    -- server hook
    hook.Add("PlayerSay", "LiliaChatParse", function(ply, txt)
        if lia.chat.parse(ply, txt) then return "" end
    end)

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

Send a chat message to eligible listeners, honoring canHear/canSay rules.

Server-side after parsing chat or programmatic chat generation.

Parameters:

Player speaker

string chatType

string text

boolean anonymous

table receivers optional Optional explicit receiver list.

Example Usage:

    lia.chat.send(ply, "ic", "Hello world", false)