Jump to content

How to add a LUA File ?


Recommended Posts


 * Requested script by Llowyanr.
 * Chat System.
 * Neglected
 * ForumGods.com
 * Configuration information.
    This system is fairly configurable. You can edit most visual aspects of it.
    * chat_prefix
        * default: "#chat".
        * This is the prefix if you want to send a message.. ie, "#chat Hello, World!" would send "Hello, World!" via the system.
    * message_format
        * default: "<&rank> &name: &message
        * The script will replace &rank with the rank of the sender, &name with the name and &message with the message. Thus, if I was an Admin called Neglected sending "Hello, World!", this would show in the system:
        <Administrator> Neglected: Hello, World!
    * ranks
        * default: many
        * This is the rank table. The ranks run off player ranks in the DB. When you create an account you make an account flag (ie, az, a, etc). This script will use those flags in tandem with this script to work. To add a rank you would add a new line like the example format. The first string inside the example is the rank level. This coincides with the account rank flags in the logon database. " " will be the player rank. The second one is the tag that shows before the player's name in World messages, or before the message in Channel messages. The third is the colour of the TAG, and the fourth is the colour of the MESSAGE. Both can be omitted. If you use those, they must either be a preset colour in the preset_colours list, or a hex value, ie #FF6060.
        * example: {"az", "Administrator", "RED", "RED"}

local chat_prefix = "#chat";
local message_format = "<&rank> &name: &message" -- &rank for rank, &name for sender name and &message for sender message.
local ranks = {
     * format: {"rank level", "tag", "colour"}
     * the "rank level" is what rank they have in the db. Ie, "az" would be for admins. A single whitespace (" ") is the player rank.
     * the "tag" is what is shown before their name when they talk. This should be set to false if you do not want a tag to appear.
     * prefix colour is the colour of the prefix. It can be a hex code or a preset colour (when omitted this is just the normal colour).
     * text colour is the colour of the message. It can be a hex code or a preset colour (when omitted this is just the normal colour).
    -- Though these guys would have their tag set normally, whatever. :P
    {"az", "Administrator", "RED", "WHITE"},
    {"a", "Gamemaster", "CYAN"},
    -- Special ranks?
    {"d", "Donor", "GREEN"},
    -- Player rank
    {" ", "Player"}
local preset_colours = {
    -- Source - Chat.h
    -- colour ref = "hex"
    LIGHTRED = "#ff6060",
    LIGHTBLUE = "#00ccff",
    TORQUOISEBLUE = "#00C78C",
    SPRINGGREEN = "#00FF7F",
    BLUE = "#0000ff",
    PURPLE = "#DA70D6",
    GREEN = "#00ff00",
    RED = "#ff0000",
    GOLD = "#ffcc00",
    GOLD2 = "#FFC125",
    GREY = "#888888",
    WHITE = "#ffffff",
    SUBWHITE = "#bbbbbb",
    MAGENTA = "#ff00ff",
    YELLOW = "#ffff00",
    ORANGE = "#FF4500",
    CHOCOLATE = "#CD661D",
    CYAN = "#00ffff",
    IVORY = "#8B8B83",

local function OnChat(_, pPlayer, pMessage)
    if pMessage:find(chat_prefix) then
        -- Remove the prefix.
        local m_message = pMessage:gsub(chat_prefix, ""); 
        -- This isn't a blank message, right?
        if m_message == nil or m_message == "" or m_message == " " then
            return 0;
        -- Remove the beginning white space.
        if not m_message:find("%w") == 1 then
            local m_firstchar = m_message:find("%a");
            m_message = m_message:sub(m_firstchar, string.len(m_message));
        -- Function to colour our string.
        local function ColourifyString(str, colour)
            local m_color;
            if not colour then colour = preset_colours["WHITE"]; end
            if preset_colours[colour] then 
                m_color = preset_colours[colour]:gsub("#", "");
            elseif colour:find("#") then
                m_color = colour:gsub("#", "");
                m_color = preset_colours["WHITE"];
                print("No colour was specified in call ColourifyString("..str..", "..colour..")!");
            return "|cff"..m_color..str.."|r";
        -- Function to grab our rank details from the ranks table.
        local function GetRankDetails(rank)
            for _, v in pairs(ranks) do
                if v[1] == rank then
                    return v;
            return nil;
        -- Get our rank.
        local rank = pPlayer:GetGmRank();
        if not rank then rank = " "; end
        local m_rankDetails = GetRankDetails(rank);
        -- If the player has a rank we don't recognize, report and use the Player rank instead.
        if not m_rankDetails then 
            m_rankDetails = GetRankDetails(" "); 
            print(pPlayer:GetName().."'s rank ("..rank..") is not in the chat system!"); 
        -- Create our string.
        local m_tag = ColourifyString(m_rankDetails[2], m_rankDetails[3]);
        local m_name = pPlayer:GetName();
        -- Are we colouring our main text?
        if m_rankDetails[4] then
            m_message = ColourifyString(m_message, m_rankDetails[4]);
        -- Push message to world.
        local m_string = message_format:gsub("&rank", m_tag);
        m_string = m_string:gsub("&name", m_name);
        m_string = m_string:gsub("&message", m_message);
        SendWorldMessage(m_string, 2);
        return 0;

RegisterServerHook(16, OnChat);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...