21.01.2011, 09:05
pawn Код:
dcmd_ban(playerid,params[])
{
new id, name[MAX_PLAYER_NAME],on[MAX_PLAYER_NAME];
new tmp[256], Index, str[49];
tmp = strtok(params,Index), id = strval(tmp); //gets the id of the player so the first characters that are behind each other without a space between and converts it into an integer
GetPlayerName(id,on,sizeof(on));
GetPlayerName(playerid,name,sizeof(name));
if(pInfo[playerid][Level] < 3) return SendClientMessage(playerid,RED,">> You Need To Be Level 3+ To Use This Command!");
if(!strlen(params)) return SendClientMessage(playerid,RED,"USAGE: /ban [id] ");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,RED,">> Invalid [id]!");
tmp = strrest(params, idx); //this gets the rest of the string, excluded the id... e.g. if you enter "/ban 10 you are a fool", it gets the "you are a fool"
if(!strlen(tmp)) return SendClientMessage(playerid, RED, "/USEAGE: /ban [id] [reason]"); //if there is no reason it sends this message
format(str,sizeof(str),">> Administrator %s Has Banned %s From The Server! (%s)",name,on, tmp); //the %s and the tmp include the reason into the string
SendClientMessageToAll(RED,str);
Ban(id);
return 1;
}
stock strrest(const string[], index) //this is the code you need to get the "rest" of a string which is not used by a strtok or so before
{
new length = strlen(string),offset = index,result[256];
while ((index < length) && ((index - offset) < (sizeof(result) - 1)) && (string[index] > '\r'))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}