27.03.2011, 11:03
Please someone, i need /kick & /ban command..
can you make it for me?
can you make it for me?
if(strcmp(cmd, "/kick", true) == 0) { new tmp[256]; tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, BLUE, "USAGE: /kick [playerid] [reason]"); return 1; } new player; player = strval(tmp); if(!IsPlayerConnected(player) || player == INVALID_PLAYER_ID) { SendClientMessage(playerid,HOMER,"Player disconnected, or its yourself!"); return 1; } 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(AdminLvl[playerid] >= 2) { tmp = strtok(cmdtext, idx); GetPlayerName(player, pName, sizeof(pName)); GetPlayerName(playerid, aName, sizeof(aName)); format(string,256," %s has been kicked by admin %s. Reason: %s",pName,aName,(result)); SendClientMessageToAll(ORANGE,string); //Kick(player); }else{ SendClientMessage(playerid,HOMER," You are not an higher level to use this command"); } return 1; }
if(strcmp(cmd, "/ban", true) == 0) { new tmp[256]; tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, BLUE, "USAGE: /ban [playerid] [reason]"); return 1; } new player; player = strval(tmp); if(!IsPlayerConnected(player) || player == INVALID_PLAYER_ID) { SendClientMessage(playerid,HOMER,"Player disconnected, or its yourself!"); return 1; } 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(AdminLvl[playerid] >= 3) { tmp = strtok(cmdtext, idx); GetPlayerName(player, pName, sizeof(pName)); GetPlayerName(playerid, aName, sizeof(aName)); format(string,256,"%s has been banned by admin %s. Reason: %s",pName,aName,(result)); SendClientMessageToAll(ORANGE,string); //Ban(player); }else{ SendClientMessage(playerid,HOMER,"You are not an higher level to use this command"); } return 1; }
CMD:kick( playerid, params[ ] )
{
new ID, string[128], reason[66];
if( !IsPlayerAdmin( playerid ) ) return 0;
if(sscanf(params, "uS(No Reason Given)[65]", ID, reason)) return SendClientMessage(playerid, -1, "USAGE: /kick [PlayerID] [reason]");
if(IsPlayerConnected(ID) && ID != INVALID_PLAYER_ID && ID != playerid)
{
format(string,sizeof(string), "You are kicked by Administrator \"%s\" Reason: %s", pName(playerid),reason);
SendClientMessage(ID , -1, string);
format(string, sizeof(string), "You have kicked \"%s\" Reason: %s", pName(ID), reason);
SendClientMessage(playerid, -1 , string);
format(string, sizeof(string), "Administrator \"%s\" has kicked \"%s\" Reason: %s",pName(playerid),pName(ID),reason);
SendClientMessageToAll( -1 , string );
TogglePlayerControllable(ID, false);
Kick(ID);
printf(string);
}
else return SendClientMessage(playerid, -1, "Player is not connected or is yourself");
return 1;
}
CMD:ban( playerid, params[ ] )
{
new ID, string[128], reason[66];
if( !IsPlayerAdmin( playerid ) ) return 0;
if(sscanf(params, "uS(No Reason Given)[65]", ID, reason)) return SendClientMessage(playerid, -1, "USAGE: /ban [PlayerID] [reason]");
if(IsPlayerConnected(ID) && ID != INVALID_PLAYER_ID && ID != playerid)
{
format(string,sizeof(string), "You are Banned by Administrator \"%s\" Reason: %s", pName(playerid),reason);
SendClientMessage(ID , -1, string);
format(string, sizeof(string), "You have Banned \"%s\" Reason: %s", pName(ID), reason);
SendClientMessage(playerid, -1 , string);
format(string, sizeof(string), "Administrator \"%s\" has Banned \"%s\" Reason: %s",pName(playerid),pName(ID),reason);
SendClientMessageToAll( -1 , string );
TogglePlayerControllable(ID, false);
Ban(ID);
printf(string);
}
else return SendClientMessage(playerid, -1, "Player is not connected or is yourself");
return 1;
}
stock pName(playerid)
{
new Name[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, sizeof(Name));
return Name;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
//Kick Command
if(strcmp("/kick", cmd, true) == 0)
{
if(IsPlayerAdmin(playerid)) {
tmp = strtok(cmdtext,idx);
if(!strlen(tmp) || strlen(tmp) > 5) {
return SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /kick (id) [reason]");
}
new id = strval(tmp);
if(!IsPlayerConnected(id)) {
SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/kick : Bad player ID");
return 1;
}
gMessage = strrest(cmdtext,idx);
GetPlayerName(id,iName,sizeof(iName));
SendClientMessage(id,ADMINFS_MESSAGE_COLOR,"-- You have been kicked from the server.");
if(strlen(gMessage) > 0) {
format(Message,sizeof(Message),"Reason: %s",gMessage);
SendClientMessage(id,ADMINFS_MESSAGE_COLOR,Message);
}
format(Message,sizeof(Message),">> %s(%d) has been kicked.",iName,id);
SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,Message);
Kick(id);
return 1;
} else {
SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/kick : You are not an admin");
return 1;
}
}
//Ban Command
if(strcmp("/ban", cmd, true) == 0)
{
if(IsPlayerAdmin(playerid)) {
tmp = strtok(cmdtext,idx);
if(!strlen(tmp) || strlen(tmp) > 5) {
return SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /ban (id) [reason]");
}
new id = strval(tmp);
if(!IsPlayerConnected(id)) {
SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/ban : Bad player ID");
return 1;
}
gMessage = strrest(cmdtext,idx);
GetPlayerName(id,iName,sizeof(iName));
SendClientMessage(id,ADMINFS_MESSAGE_COLOR,"-- You have been banned from the server.");
if(strlen(gMessage) > 0) {
format(Message,sizeof(Message),"Reason: %s",gMessage);
SendClientMessage(id,ADMINFS_MESSAGE_COLOR,Message);
}
format(Message,sizeof(Message),">> %s(%d) has been banned.",iName,id);
SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,Message);
Ban(id);
return 1;
} else {
SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/ban : You are not an admin");
return 1;
}
}
return 0;
}