Make admin command only?
#1

I have an /unban, /checkban and /tempban system, it's currently set at rcon command only, but I wanna set it as level 5+ admin command. MySQL is working fine. So this is my admin command style:

Код:
if(PlayerInfo[playerid][pAdmin] >= 1)
	{
And here is the /checkban /unban /tempban system:
Код:
#include <a_samp>
#include <a_mysql>
#include <zcmd>
#include <sscanf2>

#define SCRIPT_VERSION "1.5"

#define RED_COLOR 0xFF0000FF
#define GREEN_COLOR 0x00FF32FF

#define dbHost ""
#define dbPass ""
#define dbUser ""
#define dbName ""


new Plname[32];
new Otherid;
new PIP[16];

public OnFilterScriptInit()
{
	mysql_connect(dbHost,dbUser,dbUser,dbPass);
	mysql_debug(1);
	mysql_query("CREATE TABLE IF NOT EXISTS Bans(Username VARCHAR(32), Admin VARCHAR(32), IP VARCHAR(16), Reason VARCHAR(64), Seconds INT(12), Banned INT(5) )");
	return 1;
}
public OnFilterScriptExit()
{
	mysql_close();
	return 1;
}
CMD:tempban(playerid, params[])
{
	new reason[64], Reason[64], Mins, Hours, Days, Query[256], String[128];
	if(!IsPlayerAdmin(playerid)) return 0; //You have to be logged into rcon.
	if(sscanf(params, "uiiiS(No reason)[64]", Otherid, Mins, Hours, Days, reason)) return SendClientMessage(playerid, RED_COLOR, "Syntax: /ban <playerid> <minutes> <hours> <days> <reason[Optional]>");
	if(!IsPlayerConnected(Otherid)) return SendClientMessage(playerid, RED_COLOR, "[Error]: Player not connected");
	if(strlen(reason) > 64) return SendClientMessage(playerid, RED_COLOR, "[Error]: The ban reason cannot exceed 64 characters!");
	new CTS = ((Mins*60) + (Hours*3600) + (Days*86400));
	mysql_real_escape_string(reason, Reason);
	format(Query, sizeof(Query), "INSERT INTO `Bans` (Username, Admin, IP, Reason, Seconds, Banned) VALUES ('%s', '%s', '%s', '%s', '%d', 1)", PlayerName(Otherid), PlayerName(playerid), GetIP(Otherid), Reason, (CTS+gettime()));
	mysql_query(Query);
	format(String, sizeof(String), "%s (%i) has been banned by %s (%i) for: %s", PlayerName(Otherid), Otherid, PlayerName(playerid), playerid, reason);
	SendClientMessageToAll(RED_COLOR, String);
	Kick(Otherid);
	return 1;
}
CMD:checkban(playerid, params[])
{
	new account[24], Query[128], String[128];
	new reason[64], user[32], admin[24], IP[16], i[128];
	if(!IsPlayerAdmin(playerid)) return 0; //You have to be logged into rcon.
	if(sscanf(params, "s[24]", account)) return SendClientMessage(playerid, RED_COLOR, "Syntax: /checkban [Account]");
	if(strlen(account) > 24) return SendClientMessage(playerid, RED_COLOR, "[Error]: Player name cannot exceed 24 characters!");
	format(Query, sizeof(Query), "SELECT Username, Reason, Admin, IP FROM `Bans` WHERE `Username` = '%s' AND `Banned` = 1 LIMIT 1", account);
	mysql_query(Query);
	mysql_store_result();
	if(mysql_num_rows() == 0)
	{
	    mysql_free_result();
	    format(String, sizeof(String), "[Error]: Name %s doesn't exists in ban database!", account);
	    SendClientMessage(playerid, RED_COLOR, String);
	    return 1;
	}
	else if(mysql_num_rows() != 0)
	{
		while(mysql_fetch_row_format(Query, "|"))
	    {
			mysql_fetch_field_row(i, "Username"); format(user, sizeof(user), i);
			mysql_fetch_field_row(i, "Reason"); format(reason, sizeof(reason), i);
			mysql_fetch_field_row(i, "Admin"); format(admin, sizeof(admin), i);
			mysql_fetch_field_row(i, "IP"); format(IP, sizeof(IP), i);
		}
		format(String, sizeof(String), "Account name: %s (%s) is banned by %s for: %s", user, IP, admin, reason);
		SendClientMessage(playerid, GREEN_COLOR, String);
	}
	mysql_free_result();
	return 1;
}
CMD:unban(playerid, params[])
{
	new account[24], Query[128], String[128];
	if(!IsPlayerAdmin(playerid)) return 0; //You have to be logged into rcon.
	if(sscanf(params, "s[24]", account)) return SendClientMessage(playerid, RED_COLOR, "Syntax: /unban [Account]");
	if(strlen(account) > 24) return SendClientMessage(playerid, RED_COLOR, "[Error]: Player name cannot exceed 24 characters!");
	format(Query, sizeof(Query), "SELECT `Username` FROM `Bans` WHERE `Username` = '%s' AND `Banned` = 1 LIMIT 1", account);
	mysql_query(Query);
	mysql_store_result();
	if(!mysql_num_rows())
	{
		mysql_free_result();
	    format(String, sizeof(String), "[Error]: Name %s doesn't exists in ban database!", account);
	   	return SendClientMessage(playerid, RED_COLOR, String);
	}
	else if(mysql_num_rows() != 0)
	{
		format(Query, sizeof(Query), "UPDATE `Bans` SET `Banned` = 0 WHERE `Username` = '%s'", account);
		mysql_query(Query);
  		format(String, sizeof(String), "You have unbanned %s!", account);
	   	SendClientMessage(playerid, GREEN_COLOR, String);
	}
	return 1;
}
stock IsPlayerBanned(playerid)
{
	new IP[16], String[128], Query[128], reason[64], admin[32], i[128], seconds;
	GetPlayerIp(playerid, IP, sizeof(IP));
	format(Query, sizeof(Query), "SELECT * FROM `Bans` WHERE (`Username` = '%s' OR `IP` = '%s') AND `Banned` = 1 LIMIT 1", PlayerName(playerid), IP);
	mysql_query(Query);
	mysql_store_result();
	if(mysql_num_rows() != 0)
	{
	    while(mysql_fetch_row_format(Query, "|"))
	    {
	        mysql_fetch_field_row(i, "Reason"); format(reason, sizeof(reason), i);
	        mysql_fetch_field_row(i, "Seconds"); seconds = strval(i);
	        mysql_fetch_field_row(i, "Admin"); format(admin, sizeof(admin), i);
		}
		if(seconds > gettime())
		{
		    SendClientMessage(playerid, RED_COLOR, "[BAN] You are banned from this server!");
		    format(String, sizeof(String), "* Ban reason: %s", reason);
		    SendClientMessage(playerid, RED_COLOR, String);
		    format(String, sizeof(String), "* Admin: %s", admin);
		    SendClientMessage(playerid, RED_COLOR, String);
		    format(String, sizeof(String), "* You'll be unbanned in: %s", timec(gettime()-(gettime()-seconds)));
		    SendClientMessage(playerid, RED_COLOR, String);
		    Kick(playerid);
		}
		else
		{
			format(Query, sizeof(Query), "UPDATE `Bans` SET `Banned` = 0 WHERE `Username` = '%s'", PlayerName(playerid));
		    mysql_query(Query);
		    format(String, sizeof(String), "[UNBAN] %s (%i) has been unbanned from the server!", PlayerName(playerid), playerid);
		    SendClientMessageToAll(GREEN_COLOR, String);
		}
	}
	mysql_free_result();
	return 1;
}
//Thanks to Blacklite
stock timec(timestamp, compare = -1)
{
	if (compare == -1) {
        compare = gettime();
    }
    new
        n,
        Float:d = (timestamp > compare) ? timestamp - compare : compare - timestamp,
        returnstr[32];
    if (d < 60) {
        format(returnstr, sizeof(returnstr), "Less than a minute");
        return returnstr;
    } else if (d < 3600) { // 3600 = 1 hour
        n = floatround(floatdiv(d, 60.5), floatround_floor);
        format(returnstr, sizeof(returnstr), "minute");
    } else if (d < 86400) { // 86400 = 1 day
        n = floatround(floatdiv(d, 3600.5), floatround_floor);
        format(returnstr, sizeof(returnstr), "hour");
    } else if (d < 2592000) { // 2592000 = 1 month
        n = floatround(floatdiv(d, 86400.5), floatround_floor);
        format(returnstr, sizeof(returnstr), "day");
    } else if (d < 31536000) { // 31536000 = 1 year
        n = floatround(floatdiv(d, 2592000.5), floatround_floor);
        format(returnstr, sizeof(returnstr), "month");
    } else {
        n = floatround(floatdiv(d, 31536000.5), floatround_floor);
        format(returnstr, sizeof(returnstr), "year");
    }
    if (n == 1) {
        format(returnstr, sizeof(returnstr), "1 %s", returnstr);
    } else {
        format(returnstr, sizeof(returnstr), "%d %ss", n, returnstr);
    }
    return returnstr;
}
stock PlayerName(Playerid)
{
	GetPlayerName(Playerid, Plname, 24);
 	return Plname;
}
stock GetIP(Playerid)
{
	GetPlayerIp(Playerid, PIP, sizeof PIP);
	return PIP;
}
public OnPlayerConnect(playerid)
{
	IsPlayerBanned(playerid);
	return 1;
}
Reply
#2

Unless you can Switch the Callbacks Between Scripts, You may have to integrate this into your Script you have already
Reply
#3

Just remove !IsPlayerAdmin lines and replace them with

pawn Код:
if(PlayerInfo[playerid][pAdmin] <= 4)
    {
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)