07.03.2011, 15:57
512 cells for a string? No, that's just too much, unless you're splitting a string that will cover the whole chat box, it's not recommended.
And there's no need for the 'char' in the string, and why did you format the string but not use it?
And you didn't define idx and cmd.
Fixed code:
Works perfectly, but next time, I'd recommend you use zcmd + sscanf for improved speed, plus it's easier.
And there's no need for the 'char' in the string, and why did you format the string but not use it?
And you didn't define idx and cmd.
Fixed code:
pawn Код:
new RandomMessages[][] =
{
"blabla",
"blabla2",
"blabla3",
"blabla4",
"blabla5",
"blabla6",
"blabla7",
"blabla8",
"blabla9",
"blabla10"
};
public OnPlayerCommandText(playerid, cmdtext[])
{
new string[128], sendername[24],
cmd[128], idx; // You forgot these.
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/chucknorris", true) == 0)
{
if(IsPlayerConnected(playerid))
{
if(!IsPlayerAdmin(playerid))
{
SendClientMessage(playerid, 0xFF9900AA, "You are not authorized to use that command.");
return 1;
}
new randMSG = random(sizeof(RandomMessages));
SendClientMessageToAll(0xFF9900AA, RandomMessages[randMSG]);
format(string, sizeof(string), "[ADMIN]: %s has Announced Chuck's Fact!.", sendername);
SendClientMessageToAll(0xFF9900AA, string);
}
return 1;
}
return 0;
}
strtok(const string[], &index)
{
// taken out of pawn_lang.pdf, credits to CompuPhase
new length = strlen(string);
/* skip leading white space */
while (index < length && string[index] <= ' ') index++;
/* store the word letter for letter */
new offset = index; /* save start position of token */
new result[20]; /* string to store the word in */
while (index < length
&& string[index] > ' '
&& index - offset < sizeof result - 1)
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS; /* zero-terminate the string */
return result;
}