13.12.2009, 13:42
Код:
public OnPlayerCommandText(playerid, cmdtext[]) { new cmd[256]; new idx; new string[256]; if(strcmp(cmd, "/rp", true) == 0) { new tmp[256]; tmp = strtok(cmdtext, idx); new otherplayer = strval(tmp); new pName[MAX_PLAYER_NAME]; if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /rp [playerid] [reason]"); new length = strlen(cmdtext); while ((idx < length) && (cmdtext[idx] <= ' ')) { idx++; } new offset = idx; new result[64]; while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))) { result[idx - offset] = cmdtext[idx]; idx++; } result[idx - offset] = EOS; if(!strlen(result)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /rp [playerid] [reason]"); if(!IsPlayerConnected(otherplayer)) return SendClientMessage(playerid, COLOR_WHITE, "Invalid Player ID."); GetPlayerName(playerid, pName, sizeof(pName)); SendClientMessage(playerid, COLOR_BRIGHTRED, "Report Message has sent to the Admins."); format(string,sizeof(string),"Report from %s: [ID:%d Reason: %s.]", pName, otherplayer, result); for(new i=0;i<MAX_PLAYERS;i++) { if(IsPlayerConnected(i) && IsPlayerAdmin(playerid)) { SendClientMessage(i,COLOR_CYAN,string); } } return 1; } return 0; }
Код:
strtok(const string[], &index) { new length = strlen(string); while ((index < length) && (string[index] <= ' ')) { index++; } new offset = index; new result[20]; while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) { result[index - offset] = string[index]; index++; } result[index - offset] = EOS; return result; }