Basic ban system ( by gamingpro )

Started by gamingpro, Mar 29, 2023, 02:03 PM

Previous topic - Next topic

gamingpro

Hello guys to day i maded this ban system And Have baninfo cmd for Yours Guys and i hopy for yours install it in your script and in near day(s) i'll mading Gang system :), ok let me made it for yours


Add That in onScriptLoad() Function
[noae]
Bans <- ConnectSQL("Bans.db");
QuerySQL(Bans, "CREATE TABLE IF NOT EXISTS Bans(player TEXT, Admin TEXT, Reason TEXT, UID TEXT, UID2 TEXT, IP FLOAT)");
print("Basic ban system has been loaded successfully by gamingpro...");
[/noae]
But that line add it in onScriptUnload Function
[noae]
DisconnectSQL( Bans );
[/noae]
Add that in onPlayerJoin function to check player banned or not!
[noae]
CheckBan( player ); // Check if player banned or Not.
[/noae]
Add that in onPlayerCommand Function
[noae]
if(cmd == "ban"){
if(!text) MessagePlayer("[#FF0000]Error: [#FFFFFF]Correct Syntax /"+cmd+" <Player> <Reason>",player);
else {
local plr = GetPlayer(GetTok(text, " ",1)),
Reason = GetTok(text, " ",2 NumTok(text, " "));
if(!plr) MessagePlayer("[#FF0000]Error: [#FFFFFF]Unknow Player...",player);
else {
if(!Reason) Reason = "No_Reason"; // here if the admin not giving reason return to No_Reason.
Ban( plr, player.Name, Reason );
}
}
else if(cmd == "unban"){
if(!text) MessagePlayer("[#FF0000]Error: [#FFFFFF]Correct syntax /"+cmd+" <Full-Nick>",player);
else {
local q = QuerySQL(Bans, "SELECT * FROM Bans WHERE player='"+text.tolower()+"'");
if(!q) MessagePlayer("[#FF0000]"+text+" is Not banned yet...",player);
else {
QuerySQL(Bans, "DELETE FROM Bans WHERE player='"+text.tolower()+"'");
ClientMessage("Adminstrator:[ "+player.Name+" ] Unbanned:[ "+text+" ]",player,0,255,0);
}
}
}
else if(cmd == "baninfo"){
if(!text) MessagePlayer("[#FF0000]Error: [#FFFFFF]Correct syntax /"+cmd+" <Full-Nick>",player);
else {
local q = QuerySQL(Bans, "SELECT * FROM Bans WHERE player='"+text.tolower()+"'");
if(!q) MessagePlayer("[#FF0000]"+text+" is Not banned yet...",player);
else {
MessagePlayer("[#00FF00][BAN INFO]: [#FFFFFF]"+text+" Banned Reason:[ "+GetSQLColumnData(q,2)+" ], Admin:[ "+GetSQLColumnData(q,1)+" ]",player);
FreeSQLQuery(q);
}
}
}
}
[/noae]



Functions

[noae]
function Ban( banned, admin, reason ){
               local nick = banned.Name.tolower();
QuerySQL(Bans, "INSERT INTO Bans(player, Admin, Reason, UID, UID2, IP) VALUES('"+nick+"', '"+admin+"', '"+reason+"', '"+banned.UniqueID+"', '"+banned.UniqueID2+"', '"+banned.IP+"')");
Message("[#db0000]Adminstrator:[#FFFFFF][ "+admin+" ] [#db0000]Banned:[#FFFFFF][ "+banned.Name+" ] [#db0000]For Reason: [#FFFFFF]"+reason);
banned.Kick(); // kicking player.
}

function CheckBan( plr ){
   local q = QuerySQL(Bans, "SELECT * FROM Bans WHERE player='"+plr.Name.tolower()+"'");
if(q){
Message("[#FF0000]"+plr.Name+" Banned Reason:[ "+GetSQLColumnData(q,2)+" ] Admin:[ "+GetSQLColumnData(q,1)+" ].");
plr.Kick();
}
else {
local q2 = QuerySQL(Bans, "SELECT * FROM Bans WHERE UID='"+plr.UniqueID+"'");
if(q2){
Message("[#FF0000]"+plr.Name+" Banned Reason:[ "+GetSQLColumnData(q2,2)+" ], Admin:[ "+GetSQLColumnData(q2,1)+" ].");
plr.Kick();
}
else {
local uid2 = QuerySQL(Bans, "SELECT * FROM Bans WHERE UID2='"+plr.UniqueID2+"'");
if(uid2){
Message("[#FF0000]"+plr.Name+" Banned Reason:[ "+GetSQLColumnData(uid2,2)+" ], Admin:[ "+GetSQLColumnData(uid2,1)+" ].");
plr.Kick();
}
else {
local ip = QuerySQL(Bans, "SELECT * FROM Bans WHERE IP='"+plr.IP+"'");
if(ip){
Message("[#FF0000]"+plr.Name+" Banned Reason:[ "+GetSQLColumnData(ip,2)+" ], Admin:[ "+GetSQLColumnData(ip,1)+" ].");
plr.Kick();
}
}
}
}
                   try
                   {
                     FreeSQLQuery(q);
                   if(q2) FreeSQLQuery(q2);
                   if(uid2) FreeSQLQuery(uid2);
                   if(ip) FreeSQLQuery(ip);
}
                  catch(e)
                    return false;
}


function GetTok( string, separator, n, ... )
{
 local m = ( vargv.len() > 0 ) ? vargv[ 0 ] : n, tokenized = split( string, separator ), text = "";

 if ( ( n > tokenized.len() ) || ( n < 1 ) ) return null;

 for ( ; n <= m; n++ )
 {
  text += text == "" ? tokenized[ n - 1 ] : separator + tokenized[ n - 1 ];
 }

 return text;
}
function NumTok(string, separator)
{
    local tokenized = split(string, separator);
    return tokenized.len();
}
function GetPlayer( target )
{
 local target1 = target.tostring();

 if ( IsNum( target ) )
 {
  target = target.tointeger();

  if ( FindPlayer( target) ) return FindPlayer( target );
  else return null;
 }
 else if ( FindPlayer( target ) ) return FindPlayer( target );
 else return null;
}
[/noae]