[SOLVED]Weird thing with text length
#1

I have an announce command:
pawn Код:
dcmd_announce(playerid, params[])
{
    new message;
    new string[128];
    new string2[128];
    if(PlayerInfo[playerid][AdminLevel] < LEVEL_ANNOUNCE) ErrorMessage(playerid, "Error: You don't have a high enough admin level!");
  else if (sscanf(params, "s", message)) ErrorMessage(playerid, "Usage: '/announce [text]'");
    else
    {
    format(string, sizeof(string), "~n~~w~%s", message);
    GameTextForAll(string, 4000, 3);
    format(string2, sizeof(string2), "Administrator %s has announced this: %s", PlayerName(playerid), message);
    printf(string2);
    }
    return 1;
}
But there's something weird.
When I announce anything that's longer then 2 symbols, it gives me SERVER: Unknown Command, but it does announce the text anyways.
Do you know what's wrong?
Reply
#2

"message" is not an array as it should be. -> change it to new message[128].

I`d also suggest not to create two strings (string and string2) as you did but use string two times:

Код:
dcmd_announce(playerid, params[])
{
	new message[128];
	new string[128];
	if(PlayerInfo[playerid][AdminLevel] < LEVEL_ANNOUNCE) ErrorMessage(playerid, "Error: You don't have a high enough admin level!");
  else if (sscanf(params, "s", message)) ErrorMessage(playerid, "Usage: '/announce [text]'");
	else
	{
	format(string, sizeof(string), "~n~~w~%s", message);
	GameTextForAll(string, 4000, 3);
	format(string, sizeof(string), "Administrator %s has announced this: %s", PlayerName(playerid), message);
	printf(string);
	}
	return 1;
}
Reply
#3

Quote:
Originally Posted by ray187
Код:
	new message[128;
you might wanna do this instead
Код:
	new message[128];
Reply
#4

Oh well.. it`s late :P
Reply
#5

Thanks guys! it works
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)