Strings getting cut short
#1

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;
}
Reply
#2

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.
Reply
#3

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

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!
Reply
#5

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.
Reply
#6

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)
Reply
#7

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.
Reply
#8

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
Reply
#9

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


Forum Jump:


Users browsing this thread: 3 Guest(s)