String size not properly working.
#1

Код:
CMD:pm(playerid, params[])
{
	new str[128], str2[128], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
	if(sscanf(params, "us", id, str2))
	{
	    SendClientMessage(playerid, 0xDDBD0BFF, "Usage: /pm <id> <message>");
	    return 1;
	}
	if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xDDBD0BFF, "ERROR: Player not connected");
	if(playerid == id) return SendClientMessage(playerid, 0xDDBD0BFF, "ERROR: You cannot pm yourself!");
	{
		GetPlayerName(playerid, Name1, sizeof(Name1));
		GetPlayerName(id, Name2, sizeof(Name2));
		format(str, sizeof(str), "PM To %s(ID %d): %s", Name2, id, str2);
		SendClientMessage(playerid, 0xDDBD0BFF, str);
		format(str, sizeof(str), "PM From %s(ID %d): %s", Name1, playerid, str2);
		SendClientMessage(id, 0xC0A50AFF, str);
	}
	return 1;
}
When players send PM's to each other, the string is cut off very early (probably like 50-60 characters in) when they type a long PM.

Did I do something incorrectly?
Reply
#2

you need to specify the string size in sscanf

change this
PHP код:
if(sscanf(params"us"idstr2)) 
to
PHP код:
if(sscanf(params"us[128]"idstr2)) 
Reply
#3

Try to use sscanf(params, "us[128]", id, str2), and if it doesn't work, print strlen( str ) to see it's length. Max SendClientMessage length is 144 chars
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)