OnScriptLoad
QuerySQL( db, "CREATE TABLE IF NOT EXISTS Bans ( Name VARCHAR(32), UniqueID VARCHAR(25), Admin TEXT, Reason TEXT )" );
OnPlayerJoin
if ( CheckBan( player ) == 1 )
{
Message"[#FFFFFF]" + player.Name + " Banned from this server.");
player.Kick();
}
Function's
function Ban( player, admin, reason )
{
QuerySQL( db, "INSERT INTO Bans ( Name, UniqueID, Admin, Reason ) VALUES ( '" + player.Name + "', '" + player.UniqueID + "', '" + admin.Name + "', '" + reason + "' )" );
Message( "** " + admin + " Banned " + player.Name + ", Reason: " + reason );
player.Kick();
}
function CheckBan( p )
{
local q = QuerySQL( db, "SELECT * FROM Bans WHERE UniqueID='" + p.UniqueID + "'" );
local uid = GetSQLColumnData( q, 1 );
if ( uid ) return 1;
else return 0;
}
function DelBan( admin, banned )
{
QuerySQL( db, "DELETE FROM Bans WHERE Name='" + banned + "'" );
Message( "** " + admin + " Unban player - [ " + banned + " ]" );
}
Commands
else if ( cmd == "ban" )
{
if ( status[ player.ID ].Level < 2 ) // Here you should put your function to take the level of the player.
{
MessagePlayer("[#FF0000]Permission Denied.", player );
return;
}
else if ( !text ) MessagePlayer( "[#FF0000][Syntax] - /" + cmd + " <nick> <Reason>", player );
else
{
local plr = GetPlayer( GetTok( text, " ", 1 ) );
if ( !plr ) MessagePlayer("[#FF0000] Unknown ID/Name.", player );
else
{
local reason = GetTok( text, " ", 2 NumTok( text, " " ) );
if ( reason == null ) reason = "None";
Ban( plr, player, reason );
}
}
}
Sorry for my english.
Explanations:
is a very easy to do script, but I posted to help someone who does not have a notion.
I did not put the unban command for lack of time.
To unban someone simply use it.
QuerySQL( db, "DELETE FROM Bans WHERE Name='FullName'" );
is very simple, hope you enjoy!
It would be better if we make different table for it like QuerySQL( db, "CREATE TABLE IF NOT EXISTS MBans ( Name VARCHAR(32), UniqueID VARCHAR(25), Admin TEXT, Reason TEXT )" );
MBans = Mac-Bans
Quote from: RATHORE on Jan 05, 2015, 11:27 AMIt would be better if we make different table for it like QuerySQL( db, "CREATE TABLE IF NOT EXISTS MBans ( Name VARCHAR(32), UniqueID VARCHAR(25), Admin TEXT, Reason TEXT )" );
MBans = Mac-Bans
but when it comes to ban does not refer to is ip or mac. ;D
There is no text limit in SQLite. So you can replace VARCHAR(32) with TEXT
Quote from: ysc3839 on Jan 10, 2015, 05:26 AMThere is no text limit in SQLite. So you can replace VARCHAR(32) with TEXT
i think there is when you make a column of length something like 10 you can,t insert more then 10 characters other wise query will be success full but it will not insert/update any thing on the databse.
Source : Experience.
ahhh when i type /ban nick and reason then it ban but when i rejoin it unbanned
reason?
Quote from: Squirrel Master on Feb 28, 2015, 09:48 AMahhh when i type /ban nick and reason then it ban but when i rejoin it unbanned
reason?
The reason is probably your stupidity. If you're even too stupid to get this simple script working you must question yourself if you're ever going to create a successful server. Probably not.
lol but i dont know
my database is not connected when i add query on script load it give me error on this line of scriptload
QuerySQL( db1, "CREATE TABLE IF NOT EXISTS Bans ( Name VARCHAR(32), UniqueID VARCHAR(25), Admin TEXT, Reason TEXT )" );
Because by default this is db not db1
And for god sake post screenshot of console error
Quote from: Beztone on Feb 28, 2015, 01:58 PMBecause by default this is db not db1
And for god sake post screenshot of console error
As I've mentioned before he doesn't post since he doesn't get errors, he is just spamming and increasing forum stats.
A simple UID ban WITHOUT database! :D
function ReadLine(File)
{
local text = "";
local line = [];
while (!File.eos())
{
local chr = File.readn('b');
if (chr == '\n')
{
line.append(text);
text = "";
}
else
{
text += chr.tochar();
}
}
return line;
}
function LoadBanList()
{
local File = file("uid.banlist","r");
banlist <- ReadLine(File);
File.close();
}
//onPlayerJoin
foreach(uid in banlist)
{
if (player.UniqueID == uid) Kick(player);
}
Quote from: ysc3839 on Feb 28, 2015, 02:34 PMA simple UID ban WITHOUT database! :D
<snip>
This does work. However SQLite would actually be more performant when starting the server and adding bans.
One note I will make is that the length of the unique ID is 40 characters and not 25. I'm not sure if SQLite enforces limits on VARCHAR fields anyway.
Quote from: MatheuS on Jan 05, 2015, 12:47 PMbut when it comes to ban does not refer to is ip or mac. ;D
We have a secret formula.
Quote from: stormeus on Feb 28, 2015, 06:42 PMOne note I will make is that the length of the unique ID is 40 characters and not 25.
its 39 tried this at onPlayerJoin
local id = player.UniqueID;
print(id.len());
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fs20.postimg.org%2Fk1rnejvgt%2Fscreenshot_69.png&hash=f659f18f2ccfb05a21c54e8aaaa8b8e9835dad07)
and you are right about varchar limit it does not matter.tried a simple test and u wr rit.
problem solve about scriptload but my database is not connecting when i ban someone it dont show any error on console but when i rejoin its unban then i goto my database to check there is no table of Bans
Quote from: stormeus on Feb 28, 2015, 06:42 PMQuote from: ysc3839 on Feb 28, 2015, 02:34 PMA simple UID ban WITHOUT database! :D
<snip>
This does work. However SQLite would actually be more performant when starting the server and adding bans.
One note I will make is that the length of the unique ID is 40 characters and not 25. I'm not sure if SQLite enforces limits on VARCHAR fields anyway.
Quote from: MatheuS on Jan 05, 2015, 12:47 PMbut when it comes to ban does not refer to is ip or mac. ;D
We have a secret formula.
In SQLite, the VARCHAR is same as TEXT. It's no length limit.