14.02.2014, 13:29
I must mention that in my gamemode I render the message of the player before using it, so it does not use native chat.
Try doing something similar, render the message of the player and use a custom function (such as SendClientMessage) to send the text, return 0 at OnPlayerText.
Also a little function of mine:
Will split a message into many lines as needed after a space is found after the 100th character. Keeps the last color code used too.
pawn Код:
for(new i = 0; i < PLAYERS; i ++)
{
if(IsPlayerConnected(i))
{
if(GetPVarInt(i,"AccountLevel") >= 4)
{
format(msg, sizeof(msg),"{BBBBBB}(%s) {%s}%s (%d){FFFFFF}: %s",accountname, GetPlayerTeamHexColor(playerid),PlayerName(playerid),playerid, text);
RenderMessage(i, 0xFFFFFFFF, msg);
}
else
{
format(msg, sizeof(msg),"{%s}%s{FFFFFF}: %s",GetPlayerTeamHexColor(playerid),PlayerName(playerid), text);
RenderMessage(i, 0xFFFFFFFF, msg);
}
}
}
Also a little function of mine:
pawn Код:
stock RenderMessage(top, color, const text[])
{
new temp[156], tosearch = 0, colorint, posscolor, lastcol[12];
new mess[356], colors, tempc; format(mess, 356, "%s",text);
while(strlen(mess) > 0)
{
if(strlen(mess) < 140)
{
SendClientMessage(top, color, mess);
break;
}
strmid(temp, mess, 0, 128);
while(strfind(temp, "{", true) != -1)
{
tempc = strfind(temp, "{", true);
if(temp[tempc+7] == '}')
{
colors ++;
strdel(temp, tempc, tempc+7);
}
else
{
temp[tempc] = '0';
continue;
}
}
temp = "";
if(strfind(mess," ",true,100+colors*8) != -1)
{
tosearch = strfind(mess," ",true,100+colors*8)+1;
while(tosearch > 140)
{
colors --;
tosearch = strfind(mess," ",true,100+colors*8)+1;
}
}
if(strfind(mess,"{",true) != -1) //color codes detection , YAY
{
posscolor = strfind(mess,"{",true);
if(mess[posscolor+7] == '}') //detected one color
colorint = posscolor;
while(strfind(mess,"{",true,colorint+1) != -1) //repeat until none are found
{
posscolor = strfind(mess,"{",true,colorint+1);
if(posscolor > tosearch) //if next color will be on the other line, use last color found to render on the next line
{
posscolor = colorint;
break;
}
if(mess[posscolor+7] == '}') //if found, then assign the color
{
colorint = posscolor;
}
else
{
posscolor = colorint; //else, leave the last color.
break;
}
}
if(colorint == posscolor) //if the color position equals the one that was found
strmid(lastcol,mess,colorint,colorint+8); //get the last used color string.
}
strmid(temp, mess, 0, tosearch);
SendClientMessage(top, color, temp);
strdel(mess, 0, tosearch);
strins(mess, lastcol, 0); //insert last used color into the new line to be processed.
temp = "";
tosearch = 0;
colors = 0;
}
return 1;
}