30.11.2010, 20:23
(
Последний раз редактировалось RyDeR`; 01.12.2010 в 12:04.
)
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.
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.
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)
Note
No bugs found in both.
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;
}
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;
}
No bugs found in both.