[Include] Coloured Chat Text [2 Versions]
#1

Version I

Foreword
I know ****** released this kind of script before, but I wanted to do something different.
Before releasing, I asked allowance to share this with you guys via PM and he told me it's fine.

This works as following: you put the '#' char followed by your 6-char hex color then your text (without leaving a space). (See picture)

Picture


Download
Well, I didn't want to put a download link because it's a short code.
pawn Код:
stock ColouredText(text[])
{
    new
        pos = -1,
        string[(128 + 16)]
    ;
    strmid(string, text, 0, 128, (sizeof(string) - 16));

    while((pos = strfind(string, "#", true, (pos + 1))) != -1)
    {
        new
            i = (pos + 1),
            hexCount
        ;
        for( ; ((string[i] != 0) && (hexCount < 6)); ++i, ++hexCount)
        {
            if(!(('a' <= string[i] <= 'f') || ('A' <= string[i] <= 'F') || ('0' <= string[i] <= '9')))
            {
                break;
            }
        }
        if((hexCount == 6) && !(hexCount < 6))
        {
            string[pos] = '{';
            strins(string, "}", i);
        }
    }
    return string;
}

Version II

Foreword
This works as following: you put the '#' char followed by the name of the color you want and (without leaving a space) your text. (See picture)

Picture


Download
Well, this code is longer but it's easier than the previous to use ingame because not everyone knows how to use hex colors.
pawn Код:
stock ColouredText(text[])
{
    enum
        colorEnum
        {
            colorName[16],
            colorID[7]
        }
    ;
    new
        colorInfo[][colorEnum] =
        {
            { "BLUE",           "1B1BE0" },
            { "PINK",           "E81CC9" },
            { "YELLOW",         "DBED15" },
            { "LIGHTGREEN",     "8CED15" },
            { "LIGHTBLUE",      "15D4ED" },
            { "RED",            "FF0000" },
            { "GREY",           "BABABA" },
            { "WHITE",          "FFFFFF" },
            { "ORANGE",         "DB881A" },
            { "GREEN",          "37DB45" },
            { "PURPLE",         "7340DB" }
        },
        string[(128 + 32)],
        tempString[16],
        pos = -1,
        x
    ;
    strmid(string, text, 0, 128, sizeof(string));

    for( ; x != sizeof(colorInfo); ++x)
    {
        format(tempString, sizeof(tempString), "#%s", colorInfo[x][colorName]);

        while((pos = strfind(string, tempString, true, (pos + 1))) != -1)
        {
            new
                tempLen = strlen(tempString),
                tempVar,
                i = pos
            ;
            format(tempString, sizeof(tempString), "{%s}", colorInfo[x][colorID]);

            if(tempLen < 8)
            {
                for(new j; j != (8 - tempLen); ++j)
                {
                    strins(string, " ", pos);
                }
            }
            for( ; ((string[i] != 0) && (tempVar != 8)) ; ++i, ++tempVar)
            {
                string[i] = tempString[tempVar];
            }
            if(tempLen > 8)
            {
                strdel(string, i, (i + (tempLen - 8)));
            }
            x = -1;
        }
    }
    return string;
}
How to add more colors?
Well, just do as I do in the function. First the name than the 6-char hex color in the 2D-Array.

Example (For Version I and II)
pawn Код:
public OnPlayerText(playerid, text[])
{
    return SendPlayerMessageToAll(playerid, ColouredText(text)), 0;
}
Note
No bugs found in both.
Reply
#2

Awesome job Ryder!

By the way, why did you used it like this? What's the 0; at the end?

pawn Код:
SendPlayerMessageToAll(playerid, ColouredText(text)), 0;
Reply
#3

In order not to carry out 2 times a function. Change and the default, I think.
Reply
#4

It's so it will still return the 0 for the callback, which will make the original message not send.
Reply
#5

@Zh3r0:
Thanks, it's to return false so the normal message won't send.

EDIT: Didn't refresh the page, now responsed late.
Reply
#6

What's the difference with the ****** include?
Reply
#7

Well, I guess we have found someone who can't read.
Reply
#8

Hate to tell you that you will have to get use to it. It happens all around these forums.

Nice job. I forgot to tell you on my last reply.

EDIT: I may also suggest you adding in default colors, like "#BLUE" since everyone doesn't understand hex codes. Especially off of their heads.
Reply
#9

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
@Zh3r0:
Thanks, it's to return false so the normal message won't send.

EDIT: Didn't refresh the page, now responsed late.
Never knew you can do without return, thanks Ryder! Once again, i learned something new!
Reply
#10

Quote:
Originally Posted by Zh3r0
Посмотреть сообщение
Never knew you can do without return, thanks Ryder! Once again, i learned something new!
It's returning a value still, just 0 instead of the default, 1. (Returning the 0 will make it not send the original message)

The code he has can be written different ways to. Hopefully this will make you understand it more:
pawn Код:
public OnPlayerText(playerid, text[])
{
   SendPlayerMessageToAll(playerid, ColouredText(text));
   return 0;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)