[Include] SendExtendedChat (Alpha Stage!) 0.3C colors supported!
#1

[Description]
*NOTE* -> This code is not ready! May contain bugs, and even small dragons!


I actually post it here for help. Although it works, kind of, it still needs a lot of tweaking. And I need the communities help to do that!
So yeah...
If you're here just to test/use the code, go ahead. Add it to your includes and it will work in a way.
But if you're here and willing to help me out, I have commented the code for easier reading, and I'm pointing out some problems.
To be honest I'm simply tired of messing with this piece of code


What is it meant to do?!
It's idea is to make it support showing the whole text the user is typing in. Now this is nothing new. What is new is that this function also supports the new color feature of SA-MP 0.3C (Ooo.. shiny!)!

Problems:
  • Color code in middle of two lines might leave excessive space characters (' ') onto the next line.
  • Lines with more color codes are way shorter. (seemingly anyway.)
pawn Код:
stock SendExtendedChat(playerid, color, thestring[])
{
    #define DEBUG true // Debug mode?
    #define CharPerLine 50 // How many characters per line, includes the color codes.
    #define Max_Lines 3 // Maximum lines.
    #define StrColReserve 32 // Reserve in string for color code (8 chars per color code)

    #define Max_Strlen ((CharPerLine*Max_Lines) + StrColReserve)
    #define LinesZeroPos (CharPerLine * LinesSent - CharPerLine)
    #define LinesMax ( CharPerLine * LinesSent )
   
   
    // Lets set things up..
    new string[Max_Strlen];
    format(string, sizeof(string), "%s", thestring);
   
    new StringToSend[CharPerLine + StrColReserve], LastColor[7], colorPos;
    new Lines = floatround(floatdiv(strlen(string), CharPerLine), floatround_ceil);

    // ..when this is done, lets start sending lines..
    for( new LinesSent = 1; LinesSent <= Lines; LinesSent++ )
    {
        // First of all, we need to format the line.
       
            /* Did the following because I had some problems with the first line formatting
            and this fixed it. I don't really know what the problem is. it should also work
            like so, no?:
            format(StringToSend, CharPerLine, "%s", string[LinesZeroPos]);
            (Without the IF-ELSE statement)                         */

        if ( LinesSent == 1 ) format(StringToSend, CharPerLine, "%s", string);
        else format(StringToSend, CharPerLine+1, "%s", string[LinesZeroPos-1]);

        // If it's already second line, and there's color found, lets add it!
        if( strlen(LastColor) > 1 && LinesSent != 1 ) format(StringToSend, sizeof(StringToSend), "{%s}%s", LastColor, StringToSend);
       
        // And then, send it.
        SendClientMessage(playerid, color, StringToSend);
       
        #if DEBUG
        print(StringToSend);
        #endif
       
        //Finally, lets find out find out if there is a color for the next line to use.
        if( Lines > 1 )
        {
            // if color is found...
            colorPos = FindLastColorPos(string, LinesZeroPos, LinesMax);
            if( colorPos != -1 )
            {
                // .. lets store it! YAY! =D
                LastColor = GetColor(string, colorPos);
                // Also, if the color is in the middle of 2 lines, we have to delete it.
                // It gets messy when it does that, and the color wont have to be there until
                // the next line anyway.
                if( colorPos > (LinesMax - 7 ))
                {
                    format(string, sizeof(string), "%s", RemoveColor(string, colorPos));
                }
            }
        }
    }
   
    return true;
}
stock RemoveColor(string[], position)
{
    for( new pos = position; pos <= position + 8; pos++ )
    {
        string[pos] = ' ';
    }
    // This needs an improvement so it will use strdel as well.
    // So it will only add ' ' (space) characters until the end of the line.
    // So the next line starting position is correct. But delete the rest of the color code,
    // so there wont be any spaces infront of the line of text.
    return string;
}
stock FindLastColorPos(string[], start = 0, max = cellmax)
{
    new position = start, bool:CodeFound = false, foundPos = -1, returnFoundPos = -1;
    do{
        foundPos = strfind(string, "{", true, position);
       
        if( foundPos > max ) { CodeFound = true; continue; }
        if( foundPos != -1 )
        {
            position = foundPos+1;
            if( string[foundPos+7] == '}' )
            {
                GetColor(string, foundPos);
                returnFoundPos  = foundPos;
            }
        }
        else{ CodeFound = true; continue; }
    } while ( CodeFound == false );
    #if DEBUG
    printf("LastColorPos = %i", returnFoundPos);
    #endif
    return returnFoundPos;
}
stock GetColor(string[], position)
{
    new foundColor[7];

    format(foundColor, 7, "%s", string[position+1]);
    #if DEBUG
    printf("Color Found on Position %i = %s", position, foundColor);
    #endif

    return foundColor;
}
[Usage]
Use it just like SendClientMessage function!
err... except use SendExtendedChat
There are some other functions in this script, but all are needed for the SendExtendedChat to work.
Although functions could be used seperately I will not document them yet, as this is only so called "Alpha version" and will probably change.
You could just read the code if you wanted to.
Reply
#2

Nice one :P
Reply
#3

I have been hoping somebody would release something like this one day. This is similar to LS-RP, where if you have more then 128 characters on one line, it will split it to as many lines... correct?
Reply
#4

But does it also work on 0.3b?
Reply
#5

Quote:
Originally Posted by Andrus
Посмотреть сообщение
Nice one :P
Thanks.
Quote:
Originally Posted by RealCop228
Посмотреть сообщение
I have been hoping somebody would release something like this one day. This is similar to LS-RP, where if you have more then 128 characters on one line, it will split it to as many lines... correct?
Yup =) . You can specify the number of characters on one line, as well as maximum lines in the code.
Quote:
Originally Posted by Hiddos
Посмотреть сообщение
But does it also work on 0.3b?
Err.. it should. If it doesn't find any colors in the code it wont invent any either. Haven't testest..
Reply
#6

looks good sorry im stumped on what could be wrong
Reply
#7

Quote:
Originally Posted by Lookin
Посмотреть сообщение
looks good sorry im stumped on what could be wrong
Nothing is wrong really. It just lacks some functionality that could much improve it. One of which I have written about in the code and I have a possible solution for... But I simply don't have the inspiration to code it yet
Reply
#8

Nice!. Really good work
Reply
#9

Quote:
Originally Posted by TheXIII
Посмотреть сообщение
Nothing is wrong really. It just lacks some functionality that could much improve it. One of which I have written about in the code and I have a possible solution for... But I simply don't have the inspiration to code it yet
ok sorry i thought you were saying that it wasnt working or smthn like that my bad

(a tired chef is a hazard to sa-mp forums ) =D
Reply
#10

Thanks everyone!
Quote:
Originally Posted by Lookin
Посмотреть сообщение
ok sorry i thought you were saying that it wasnt working or smthn like that my bad

(a tired chef is a hazard to sa-mp forums ) =D
Nothing to be sorry about The big bad red NOTE up there is for a reason. Except the reason isn't that it's not working, it's just that it's not working like I want it do, and I don't want to release this as a completed code yet.
Reply
#11

This is really nice. Keep this up! ^^
Reply
#12

Wow, this is really nice. Pretty usefull too.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)