SA-MP Forums Archive
String size not properly working. - 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: String size not properly working. (/showthread.php?tid=596625)



String size not properly working. - Sebz - 20.12.2015

Код:
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?


Re: String size not properly working. - JeaSon - 20.12.2015

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



Re: String size not properly working. - prineside - 20.12.2015

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