SA-MP Forums Archive
Chat - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Chat (/showthread.php?tid=496593)



Chat - Mattakil - 22.02.2014

This chat system is supposed to split the string once the message is 50 characters long, and continue it on the next line. However, it splits the string then repeats the last few charaters. I will change the length to 100, but the line doesn't stop at 100, if you understand what im saying

pawn Код:
new string[150], string1[150], string2[150];
        if(strlen(text) > 50)
        {
            format(string, sizeof(string), "%s says: %s", GetName(playerid), text);
            strmid(string1, string, 53, 100);
            format(string2, sizeof(string2), "... %s", string1);
            ProxDetector(10, playerid, string, 0xE6E6E6AA, 0xC8C8C8AA, 0xAAAAAAAA, 0x8C8C8CAA, 0x6E6E6EAA);
            ProxDetector(10, playerid, string2, 0xE6E6E6AA, 0xC8C8C8AA, 0xAAAAAAAA, 0x8C8C8CAA, 0x6E6E6EAA);
            print(string);
            print(string2);
        }

        else
        {
            format(string, sizeof(string), "%s says: %s", GetName(playerid), text);
            ProxDetector(10, playerid, string, 0xE6E6E6AA, 0xC8C8C8AA, 0xAAAAAAAA, 0x8C8C8CAA, 0x6E6E6EAA);
            print(string);
        }



Re: Chat - Mattakil - 25.02.2014

Anybody?


Re: Chat - Kapupc - 25.02.2014

can you post to result of that script send out ?


Re: Chat - Kapupc - 25.02.2014

Quote:

new string[144];//max char in one line
if(strlen(text) > 50)
{
new string1[50], string2[100];
strmid(string1, text, 0, 49);// cut 50 first to string 1(0-49 = 50)
strmid(string2, text, 50, strlen(string));//and more to string 2(50 - real sizeof text)
format(string, sizeof(string), "%s says: %s", GetName(playerid), string1);
ProxDetector(10, playerid, string, 0xE6E6E6AA, 0xC8C8C8AA, 0xAAAAAAAA, 0x8C8C8CAA, 0x6E6E6EAA);
format(string, sizeof(string), "...%s", string2);
ProxDetector(10, playerid, string2, 0xE6E6E6AA, 0xC8C8C8AA, 0xAAAAAAAA, 0x8C8C8CAA, 0x6E6E6EAA);
}
else
{
format(string, sizeof(string), "%s says: %s", GetName(playerid), text);
ProxDetector(10, playerid, string, 0xE6E6E6AA, 0xC8C8C8AA, 0xAAAAAAAA, 0x8C8C8CAA, 0x6E6E6EAA);
print(string);
}

you wanna do like this ?


Re: Chat - Mattakil - 25.02.2014

Quote:
Originally Posted by Kapupc
Посмотреть сообщение
you wanna do like this ?
That's what I was looking for, i'll try it and let you know.


Re: Chat - Kapupc - 25.02.2014

not surely i'm newbie let try i'm making gamemode too


Re: Chat - Kapupc - 25.02.2014

sorry my bad edit it to
Quote:

new string[144];//max char in one line
if(strlen(text) > 50)
{
new string1[50], string2[100];
strmid(string1, text, 0, 49);// cut 50 first to string 1(0-49 = 50)
strmid(string2, text, 50, strlen(text));//and more to string 2(50 - real sizeof text)
format(string, sizeof(string), "%s says: %s", GetName(playerid), string1);
ProxDetector(10, playerid, string, 0xE6E6E6AA, 0xC8C8C8AA, 0xAAAAAAAA, 0x8C8C8CAA, 0x6E6E6EAA);
format(string, sizeof(string), "...%s", string2);
ProxDetector(10, playerid, string, 0xE6E6E6AA, 0xC8C8C8AA, 0xAAAAAAAA, 0x8C8C8CAA, 0x6E6E6EAA);
}
else
{
format(string, sizeof(string), "%s says: %s", GetName(playerid), text);
ProxDetector(10, playerid, string, 0xE6E6E6AA, 0xC8C8C8AA, 0xAAAAAAAA, 0x8C8C8CAA, 0x6E6E6EAA);
print(string);
}




Re: Chat - Scenario - 25.02.2014

I wrote this for my GM:

pawn Код:
stock real_SendClientMessage(playerid, COLOR, string[], size = sizeof(string))
{
    new
        szString2[128],
        bool:iSplit;
       
    if(strlen(string) > 128)
    {
        new
            szLastHexColor[9],
            iStartPosition;
           
        while((iStartPosition = strfind(string, "{", true, iStartPosition)) != -1)
        {
            strmid(szLastHexColor, string, iStartPosition, iStartPosition+8);
            iStartPosition += 8;
        }
       
        strmid(szString2, string, 128, 256);
        strdel(string, 128, 256);
        strcat(string, " ..", size);
        strins(szString2, " .. ", 0);
        if(!isnull(szLastHexColor)) strins(szString2, szLastHexColor, 0);
        iSplit = true;
    }
       
    if(iSplit) SendClientMessage(playerid, COLOR, string), SendClientMessage(playerid, COLOR, szString2);
    else SendClientMessage(playerid, COLOR, string);
    return 1;
}
It also tries to take into account the possibility of HEX colors being embedded into the string. I noticed that it would cut the string in bad places (i.e. in the middle of a HEX color code) and would screw it all up. The function works like a charm though!


Re: Chat - Mattakil - 25.02.2014

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
I wrote this for my GM:

pawn Код:
stock real_SendClientMessage(playerid, COLOR, string[], size = sizeof(string))
{
    new
        szString2[128],
        bool:iSplit;
       
    if(strlen(string) > 128)
    {
        new
            szLastHexColor[9],
            iStartPosition;
           
        while((iStartPosition = strfind(string, "{", true, iStartPosition)) != -1)
        {
            strmid(szLastHexColor, string, iStartPosition, iStartPosition+8);
            iStartPosition += 8;
        }
       
        strmid(szString2, string, 128, 256);
        strdel(string, 128, 256);
        strcat(string, " ..", size);
        strins(szString2, " .. ", 0);
        if(!isnull(szLastHexColor)) strins(szString2, szLastHexColor, 0);
        iSplit = true;
    }
       
    if(iSplit) SendClientMessage(playerid, COLOR, string), SendClientMessage(playerid, COLOR, szString2);
    else SendClientMessage(playerid, COLOR, string);
    return 1;
}
It also tries to take into account the possibility of HEX colors being embedded into the string. I noticed that it would cut the string in bad places (i.e. in the middle of a HEX color code) and would screw it all up. The function works like a charm though!
Thanks!