SA-MP Forums Archive
Strings getting cut short - 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: Strings getting cut short (/showthread.php?tid=427785)



Strings getting cut short - liam1412 - 03.04.2013

Can anyone help. Messages are been sent but getting cut short.

pawn Код:
CMD:pm(playerid, params[])
{

    new recipient,msg[255],playerName[MAX_PLAYER_NAME+1],stringProc[255];
   
    //check it looks right and contains correct format data
    if(sscanf(params,"us",recipient,msg)) return SendClientMessage(playerid,COLOR_INDIGO, "Syntax error.Correct usage: /pm [playerid] [message]");

    //check player is online
    if(!IsPlayerConnected(recipient)) return SendClientMessage(playerid,COLOR_INDIGO, "That player is not online");

    //get the player name
    GetPlayerName(playerid,playerName,sizeof(playerName));

    //format the string for output
    format(stringProc,sizeof(stringProc), "pm from %s(%i) %s:",playerName,playerid,msg);

    //All checks out so send the formatted string
    SendClientMessage(recipient,COLOR_YELLOW,stringProc);

    return 1;
}



Re: Strings getting cut short - 3ventic - 03.04.2013

The string can only be up to sizeof(stringProc) which is currently 255. This includes pm from [name]([id]) [message]:

You can make array size larger to allow longer message.


AW: Strings getting cut short - [AK]Nazgul - 03.04.2013

Try splitting the string, max size is 144 or 128, I'm not sure


Re: Strings getting cut short - liam1412 - 03.04.2013

Quote:
Originally Posted by 3ventic
Посмотреть сообщение
The string can only be up to sizeof(stringProc) which is currently 255. This includes pm from [name]([id]) [message]:

You can make array size larger to allow longer message.
There is definitely enough room :-/

Quote:
Originally Posted by [AK]Nazgul
Посмотреть сообщение
Try splitting the string, max size is 144 or 128, I'm not sure
Not quite sure I understand you. Could you give an example!


Re: Strings getting cut short - RajatPawar - 03.04.2013

The maximum characters you can send at a time are 128. So, I remember there was an easier way of doing this, but I CANNOT remember it, so this way: Declare
pawn Код:
msg[ 128 ] = 0;
Then before formatting, use this line:
pawn Код:
new count;
for ( new i; i < sizeof( msg ); i++ )
{
     if( msg[ i ] != 0 ) { count++; continue; }
     else continue;
}
if ( count > 110 ) return SendClientMessage(playerid, -1, "Make it shorter, men!");
There is a better way, but I cannot remember it. I guess it was something to do with size of and things.


Re: Strings getting cut short - liam1412 - 03.04.2013

Mmm. That sounds awfully complicated for something as simple as printing a string :-/

Is there anyway I can make that a function so I can just call say

splitString(stringtosplit)


Re: Strings getting cut short - Konstantinos - 03.04.2013

SendClientMessage's message has a limit which is 128 chars. Any message longer than that will be cut and won't be sent. Use split to send the message into 2 messages.


Re: Strings getting cut short - liam1412 - 03.04.2013

I just added the string length in the sscanf line and it works. Can I limit the number of chars someone can type in the text bar anyway

Thanks


Re: Strings getting cut short - Sithis - 03.04.2013

Sscanf depreceated not defining string sizes, so you will need to do that in order to make it work.