AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Extensions (https://forums.alliedmods.net/forumdisplay.php?f=134)
-   -   [EXTENSION] ConColors (v1.0 12/17/2018) (Windows only) (https://forums.alliedmods.net/showthread.php?t=312818)

Rachnus 12-16-2018 19:11

[EXTENSION] ConColors (v1.0 12/17/2018) (Windows only)
 
Manipulate the color of server console output.




concolors.inc
PHP Code:

#if defined _concolors_included
 #endinput
#endif
#define _concolors_included

#define CON_COLOR_BLACK   0
#define CON_COLOR_BLUE    1
#define CON_COLOR_GREEN   2
#define CON_COLOR_CYAN    3
#define CON_COLOR_RED     4
#define CON_COLOR_MAGENTA 5
#define CON_COLOR_BROWN   6
#define CON_COLOR_WHITE   7

#define FOREGROUND_CON_COLOR_GRAY            8
#define FOREGROUND_CON_COLOR_INTENSE_BLUE    9
#define FOREGROUND_CON_COLOR_INTENSE_GREEN   10
#define FOREGROUND_CON_COLOR_INTENSE_CYAN    11
#define FOREGROUND_CON_COLOR_INTENSE_RED     12
#define FOREGROUND_CON_COLOR_INTENSE_MAGENTA 13
#define FOREGROUND_CON_COLOR_YELLOW          14
#define FOREGROUND_CON_COLOR_INTENSE_WHITE   15

/*
bit 0 - foreground blue
bit 1 - foreground green
bit 2 - foreground red
bit 3 - foreground intensity

bit 4 - background blue
bit 5 - background green
bit 6 - background red
bit 7 - background intensity
*/

/**
 * Sets the color of all future console output
 *
 * @param background    text background color
 * @param foreground    text foreground color
 * @return void
 */
native void SetConsolePrintColor(int backgroundint foreground);

/**
 * Sets the color of all future console output with custom attributes
 *
 * @param attributes    text attributes
 * @return void
 */
native void SetConsolePrintColorEx(int attributes);

/**
 * Resets the console print color to default (white)
 *
 * @return void
 */
native void ResetConsolePrintColor();

/**
 * Resets the console print color to the previous print color
 *
 * @return void
 */
native void ResetPreviousConsolePrintColor();

/**
 * Print a colored message to the server console
 *
 * @param background    text background color
 * @param foreground    text foreground color
 * @param fmt            format
 * @param any             ...
 * @return void
 */
stock void ColorPrintToServer(int backgroundint foregroundchar[] fmtany ...)
{
    
SetConsolePrintColor(backgroundforeground);
    
char szBuffer[1024];
    
VFormat(szBuffersizeof(szBuffer), fmt4);
    
PrintToServer(szBuffer);
    
ResetPreviousConsolePrintColor();
}

/**
 * Print a colored message to the server console with custom attributes
 *
 * @param attributes    text attributes
 * @param fmt            format
 * @param any             ...
 * @return void
 */
stock void ColorPrintToServerEx(int attributeschar[] fmtany ...)
{
    
SetConsolePrintColorEx(attributes);
    
char szBuffer[1024];
    
VFormat(szBuffersizeof(szBuffer), fmt3);
    
PrintToServer(szBuffer);
    
ResetPreviousConsolePrintColor();
}

public 
Extension __ext_concolors 
{
    
name "ConColors",
    
file "concolors.ext",
#if defined AUTOLOAD_EXTENSIONS
    
autoload 1,
#else
    
autoload 0,
#endif
#if defined REQUIRE_EXTENSIONS
    
required 1,
#else
    
required 0,
#endif
}; 

SOURCE/BINARIES

enderandrew 07-16-2020 22:24

Re: [EXTENSION] ConColors (v1.0 12/17/2018) (Windows only)
 
Could you do syntax highlighting with this for connect messages in a given color, errors in another color, etc?

DJPlaya 07-29-2020 12:03

Re: [EXTENSION] ConColors (v1.0 12/17/2018) (Windows only)
 
Quote:

Originally Posted by enderandrew (Post 2710434)
Could you do syntax highlighting with this for connect messages in a given color, errors in another color, etc?

Hi again, idk why i always meet you in so many different Threads ^^
Ime not sure, but if i understand correctly, you do can set the Message Color of everything.
Instead of hooking out the connect message and then reprinting it, this should also do the trick(and is a bit simpler):
Code:

OnClientConnect()
{
        SetConsolePrintColor(RED IDK you know what i mean)
        RequestFrame(Frame)
}

public action Frame()
{
        SetConsolePrintColor(Default Color Here)
}

This isent failsafe since every message send in that frame does get colored, but yea.

The only other Way i could think of is hooking the Server Console Print, its propably possible todo this with PTAH or DHooks, here is some Pseudocode:
Code:

OnPluginStart()
{
        PTaH(PTaH_ServerConsolePrint, Hook, ServerConsolePrint);
}

public Action ServerConsolePrint(const char[] sMessage, LoggingSeverity severity)
{
        if(StrCmp(sMessage, "connected")) // Message to highlight goes here
        {
                ColorPrintToServer(BACKGROUND COLOR, FOREGROUND COLOR, sMessage)
                return Plugin_Handled;
        }

        else
                return Plugin_Continue;
}



All times are GMT -4. The time now is 09:16.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.