19.08.2009, 21:21
Here's code for announce command from my DM gamemode (with some little edits):
(Put it on OnPlayerCommandText)
If you get errors about the "cmd" or "idx" variable, put this at the bottom of your script:
and this at the top of OnPlayerCommandText:
And if you get errors about "strrest" put this too at the bottom of your script:
Enjoy
pawn Код:
if((!strcmp(cmd,"/ann",true) || !strcmp(cmd,"/announce",true)) && IsPlayerAdmin(playerid))
{
new string[128];
cmd = strrest(cmdtext,idx);
if(!strlen(cmd)) return SendClientMessage(playerid,white," Usage: /announce(ann) [text]");
GameTextForAll(string,5000,4);
return 1;
}
If you get errors about the "cmd" or "idx" variable, put this at the bottom of your script:
pawn Код:
stock strtok(const string[], &index, somechar = ' ')
{ // by CompuPhase, improved by Amit_B
new length = strlen(string), result[20];
while((index < length) && (string[index] <= somechar)) index++;
new offset = index;
while((index < length) && (string[index] > somechar) && ((index - offset) < (sizeof(result) - 1))) result[index - offset] = string[index], index++;
result[index - offset] = EOS;
return result;
}
pawn Код:
new cmd[256], idx;
cmd = strtok(cmdtext,idx);
pawn Код:
stock strrest(const string[], index)
{ // by CompuPhase, improved by Amit_B
new length = strlen(string), offset = index, result[M_S];
while((index < length) && ((index - offset) < (sizeof(result) - 1)) && (string[index] > '\r')) result[index - offset] = string[index], index++;
result[index - offset] = EOS;
if(result[0] == ' ' && string[0] != ' ') strdel(result,0,1);
return result;
}
