/ban help -
Chiao - 31.05.2013
Hello I need a /ban command for my server I have tried lost of them but almost none worked either something was not defined or it was used in another line...
I also need a /unban cmd...
please help me.
Re: /ban help -
Stanford - 31.05.2013
Here you go:
pawn Код:
if(strcmp(cmd, "/ban", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /ban [playerid/PartOfName] [reason]");
return 1;
}
giveplayerid = ReturnUser(tmp);
if(IsPlayerNPC(giveplayerid)) return 1;
if(PlayerInfo[playerid][pAdmin] >= 1)
{
if(IsPlayerConnected(giveplayerid))
{
if(giveplayerid != INVALID_PLAYER_ID)
{
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[96];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /ban [playerid/PartOfName] [reason]");
return 1;
}
new logstring[256];
new year, month, day;
getdate(year, month, day);
if(AdmCmdProtection[playerid] > 4)
{
RemovePlayerAdmin(playerid);
format(logstring, sizeof(logstring), "[ADMIN][IP]:[%s] [DATE]:[%d/%d/%d] [Admin]:[%s]:[Command Spam (/ban)].", GetPlayerIpEx(playerid),day,month,year,PlayerName(playerid));
Log("Logs/admin.log", logstring);
return 1;
}
if(PlayerInfo[giveplayerid][pAdmin] > PlayerInfo[playerid][pAdmin])
{
RemovePlayerAdmin(playerid);
format(logstring, sizeof(logstring), "[ADMIN][IP]:[%s] [DATE]:[%d/%d/%d] [Admin]:[%s]:[Attempting to ban a higher Admin].", GetPlayerIpEx(playerid),day,month,year,PlayerName(playerid));
Log("Logs/admin.log", logstring);
return 1;
}
if(AdminOnDuty[playerid] == false)
{
format(string, sizeof(string), "AdmCmd: %s was banned by an Admin, reason: %s", GetPlayerNameEx(giveplayerid), result);
}
else if(AdminOnDuty[playerid] == true)
{
format(string, sizeof(string), "AdmCmd: %s was banned by %s, reason: %s", GetPlayerNameEx(giveplayerid),GetPlayerNameEx(playerid), result);
}
SendClientMessageToAll(COLOR_LIGHTRED, string);
AdmCmdProtection[playerid]++;
BanPlayer(playerid, giveplayerid, result, 1);
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, "The player you are looking for is Offline.");
}
}
else
{
InvalidCommandAcces(playerid);
return 1;
}
}
return 1;
}
Re: /ban help -
Konstantinos - 31.05.2013
I'm sure they are. If I ****** it, I can find many results and some of them are good enough.
@Stanford - Please, don't do that. strcmp and strtok are outdated and SLOW.. There're so many good command processors and stuff such as sscanf for paramaters with one line!
Re: /ban help -
Stanford - 31.05.2013
Alright you've convinced me here I improved a few stuff:
pawn Код:
CMD:ban(playerid, params[])
{
new id, name[MAX_PLAYER_NAME], reason[35], name1[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME], string[128];
if(!(PlayerInfo[playerid][pAdmin] >= 1)) return SCM(playerid, COLOR_GREY,"You are not authorized to use this command");
if(sscanf(params,"uz", id, reason)) return SCM(playerid, COLOR_WHITE,"USAGE: /ban [playerid/partofname] [reason]");
if(id == INVALID_PLAYER_ID) return SCM(playerid, COLOR_GREY,"Invalid player id");
else
{
if(PlayerInfo[id][pAdmin] >= 1)
{
SendClientMessage(playerid,COLOR_GREY,"That player can not be banned");
GetPlayerName(playerid, name, sizeof(name));
format(string, 128, "AdmWarning: %s tryes banning an admin!", name);
ABroadCast(COLOR_YELLOW,string,1);
return 1;
}
GetPlayerName(playerid, name1, sizeof(name1));
GetPlayerName(id, name2, sizeof(name2));
format(string, sizeof(string), "AdmCmd: %s was banned by %s, reason: %s", name2, name1, reason);
SendClientMessageToAll(COLOR_LIGHTRED, string);
PlayerInfo[id][pLocked] = 1;
new plrIP[16];
GetPlayerIp(id,plrIP, sizeof(plrIP));
SendClientMessage(id,COLOR_DBLUE,"|___________[BAN INFO]___________|");
format(string, sizeof(string), "Your name: %s.",name2);
SendClientMessage(id, COLOR_WHITE, string);
format(string, sizeof(string), "Your ip is: %s.",plrIP);
SendClientMessage(id, COLOR_WHITE, string);
format(string, sizeof(string), "You were banned by: %s.",name1);
SendClientMessage(id, COLOR_WHITE, string);
format(string, sizeof(string), "You were banned for: %s.",reason);
SendClientMessage(id, COLOR_WHITE, string);
SendClientMessage(id,COLOR_DBLUE,"|___________[BAN INFO]___________|");
Ban(id);
}
return 1;
}