[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.)
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;
}
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?
|
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 |