SA-MP Forums Archive
Checking if strval of string, and make a new line. - 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: Checking if strval of string, and make a new line. (/showthread.php?tid=415695)



Checking if strval of string, and make a new line. - PaulDinam - 14.02.2013

I made a /me command and when someone writes something it's pretty ugly like that.




How can I check if the length of the string is for example 50 and copy the rest of the text to a new line./


Re: Checking if strval of string, and make a new line. - zxc1 - 14.02.2013

I've ******'d it since I'm wondering too.
Here is what I've found:
pawn Код:
new string[2][160];
if(strlen([PARAMETER VARIABLE] > 127)
{
    strins(string[1], ,[PARAMETER VARIABLE], 128);
    strdel([PARAMETER VARIABLE], 128, sizeof(PARAMETER VARIABLE));
    new Pname[24];
    GetPlayerName(playerid, Pname, 24);
    format(string[0], sizeof(string[0]), "%s(%d):%s", Pname, playerid, [PARAMETER VARIABLE]);
    format(string[1], sizeof(string[1]), "%s(%d):%s", Pname, playerid, string[1]);
    SendClientMessage(playerid, 0xFFFFFF, string[0]);
    SendClientMessage(playerid, 0xFFFFFF, string[1]);
}
pawn Код:
SendCustomPlayerMessage(playerid, color, text[])
{
    if(strlen(text) > 64)
    {
        new text1[65],
            text2[65];
           
        strmid(text2, text, 64, 128);
        strmid(text1, text, 0, 64);
               
        format(string, 128, "%s...", text1);
        SendClientMessage(playerid, color, string);
       
        format(string, 128, "...%s", text2);
        SendClientMessage(playerid, color, string);
    }
    else SendClientMessage(playerid, color, text);
}
Untested, copied.
Credits to the creators.

Check them and tell me afterwards if it worked.


Re: Checking if strval of string, and make a new line. - RajatPawar - 14.02.2013

You must be doing something like this, right?
pawn Код:
new text[128];
if(sscanf(params,"s[128]",text)) return ...
if(strlen(text)>50)) return SCM(playerid, -1 , "Your message cannot be longer than 50 characters.."); /*Add this line*/
format(text, 128, "%s %s",GetPlayerName(..), text);
SCM(..);



Re: Checking if strval of string, and make a new line. - PaulDinam - 14.02.2013

I'm getting messed up with this thing, strmid

Like if I have

Код:
CMD:me(playerid, params[])
{
	new string[256],action[256];
	if(sscanf(params, "s[256]", action)) return SCM(playerid, -1, "USAGE: /me [action]");
	format(string, sizeof(string), "* %s %s", GetNameWithMask(playerid), action);
	ProxDetector(30, playerid, string, COLOR_PURPLE);
	return 1;
}
Can someone make it to start a new line after 128 characters?