10.12.2016, 09:07
PHP код:
if(strcmp(cmd, "/tban", true) == 0)
{
new banner[MAX_PLAYER_NAME], banned[MAX_PLAYER_NAME], bannedid, reason[25], hours, string[400], secs, unbants, ip[16], query[180];
if(!IsPlayerAdmin(playerid) && PInfo[playerid][AdminLevel] < 0) return SendClientMessage(playerid, COLOR_ERROR, "You do not have sufficient permissions to use this command."); //this is just my admin check, yours may be different.
if(sscanf(params, "uds[25]", bannedid, hours, reason)) return SendClientMessage(playerid, -1, "Usage: /tempban [player name/ID] [hours] [reason]"); // here, we're checking if the administrator entered the command correctly. "u" is a player name or ID, "d" is the amount of hours as an integer, and "s[25]" is the reason.
if(!IsPlayerConnected(bannedid)) return SendClientMessage(playerid, -1, "Invalid player name/ID."); //checking if the player that the admin is trying to ban is connected to the server
if(PInfo[playerid][AdminLevel] < PInfo[bannedid][AdminLevel]) return SendClientMessage(playerid, -1, "You cannot ban someone with a higher level than you!"); //I don't allow admins to ban those with higher levels than their own.
if(strlen(reason) < 3 || strlen(reason) > 24) return SendClientMessage(playerid, -1, "Your reason must be between 3 and 24 characters."); //limiting the reason length to 3-24 characters
if(hours < 12 || hours > 720) return SendClientMessage(playerid, -1, "Ban hours are between 12 and 720 hours"); //making sure the ban duration is no shorter than 12 hours and no longer than 30 days
GetPlayerName(playerid, banner, sizeof(banner));
GetPlayerName(bannedid, banned, sizeof(banned));
GetPlayerIp(bannedid, ip, sizeof(ip));
secs = hours*3600;
unbants = gettime()+ secs;
format(query, sizeof(query), "INSERT INTO `tbans` (ban_id, player, ip, admin, reason, ban_time, unban_time) VALUES ('0', '%s', '%s', '%s', '%s', %d, %d)",
banned, ip, banner, reason, gettime(), unbants);
mysql_query(query);
format(string, sizeof(string), "You've been temporarily banned.\n\n{FFFFFF}Admin Banned: %s\nReason: %s", banner, reason);
ShowPlayerDialog(bannedid, 678, DIALOG_STYLE_MSGBOX, "Banned!", string, "Close", "");
format(string, sizeof(string), "%s(%d) has banned %s(%d) for %d hours for: %s", banner, playerid, banned, bannedid, hours, reason);
SendClientMessageToAll(-1, string);
SetTimerEx("KickEx", 500, false, "i", playerid);
return 1;
}