Vice Underdogs
Scripting => Script Showroom => Topic started by: MR SK on June 10, 2022, 11:38:17 am
-
Hi buddies, I've been taking a look in VC: MP community and I was unable to find the Temp Ban system, if I got some then it was old or not working properly so I decided to make my own Temp Ban System Here's the code:
Put these database detail on script load event
[noae]TempBans <- ConnectSQL("TempBans.db");
QuerySQL( TempBans, "CREATE TABLE IF NOT EXISTS TempBans( Name TEXT, UID TEXT, UID2 TEXT, IP FLOAT, Time NUMERIC, ExpireTime NUMERIC, TimeExpireRatio TEXT, Admin TEXT, Reason TEXT )" );
[/noae]
Don't forget to put this line on player join event
[noae]CheckTempBan(player);
[/noae]
Commands are here You just have to paste them on player command event
[noae]if(cmd == "tempban")
{
if(text)
{
local plr = GetPlayer(GetTok(text, " ", 1)), expire = GetTok(text, " ", 2), reason = GetTok( text, " ", 3, NumTok( text, " " ) );
if(plr)
{
if(expire)
{
if(reason)
{
local ban_expire = split(expire, ":");
if(NumTok(expire, ":") == 3)
{
if(IsNum(ban_expire[0]) && IsNum(ban_expire[1]) && IsNum(ban_expire[2]))
{
local calc = ((ban_expire[ 0 ].tointeger()*24*60*60) + (ban_expire[ 1 ].tointeger()*60*60) + (ban_expire[ 2 ].tointeger()*60));
QuerySQL( TempBans, "INSERT INTO TempBans( Name, UID, UID2, IP, Time, ExpireTime, TimeExpireRatio, Admin, Reason ) VALUES ('"+plr.Name+"', '"+plr.UniqueID +"', '"+plr.UniqueID2+"', '"+plr.IP.tofloat()+"', '"+time()+"', '"+calc+"', '"+expire+"', '"+player.Name+"', '"+reason+"')");
Message("[#FF0000][PRIOR BAN]: [#FFFFFF]"+plr.Name+" is banned for Reason: "+reason+", TimeLeft: " + GetBanRemainingTime(time().tointeger(), expire.tostring())+", Admin: "+player.Name+"");
plr.Kick();
}
else MessagePlayer("[#FF0000][ERROR]: You've entered wrong values in the time, make sure you have entered numbers only!",player);
}
else MessagePlayer("[#FF0000][ERROR]: Time Format must be DAYS:HOURS:MINUTES!",player);
}
else MessagePlayer("[#FF0000][ERROR]: You must specify a reason to ban requested player!",player);
}
else MessagePlayer("[#FF0000][ERROR]: Please type the duration of the ban for the requested player!",player);
}
else MessagePlayer("[#FF0000][ERROR]: Unknown player!",player);
}
else MessagePlayer("[#FFFF00]Syntax; /tempban <player/ID> <Days:Hours:Minutes> <Reason>",player);
}
else if(cmd == "untempban")
{
if(text)
{
local plrname = GetTok(text, " ", 1);
local q = QuerySQL(TempBans, "SELECT * FROM TempBans WHERE LOWER(Name)='"+plrname.tolower()+"'");
if(q)
{
QuerySQL(TempBans, "DELETE FROM TempBans WHERE LOWER(Name)='"+plrname.tolower()+"'" );
MessagePlayer("[#00FF00][SUCCESS]: [#FFFFFF]The user: "+GetSQLColumnData(q,0)+" has been unbanned!",player);
}
else MessagePlayer("[#FF0000][ERROR]: Can't found this nickname: "+plrname+" in database!",player);
}
else MessagePlayer("[#FFFF00]Syntax; /untempban <player full name>",player);
}
[/noae]
And in Last there are some important functions paste them to anywhere in your script
[noae]function CheckTempBan(player)
{
local q = QuerySQL( TempBans, "SELECT * FROM TempBans WHERE UID='"+escapeSQLString(player.UniqueID)+"' OR UID2='"+escapeSQLString(player.UniqueID2)+"'" );
if(q)
{
if((time() - GetSQLColumnData( q, 4 ).tointeger()) >= GetSQLColumnData( q, 5 ).tointeger())
{
QuerySQL(TempBans, "DELETE FROM TempBans WHERE LOWER(Name)='" + player.Name.tolower() + "'" );
}
else
{
Message("[#FF0000][PRIOR BAN]: [#FFFFFF]"+player.Name+" is banned for Reason: "+GetSQLColumnData(q, 8)+", TimeLeft: "+GetBanRemainingTime(GetSQLColumnData( q, 4 ).tointeger(), GetSQLColumnData( q, 6 ).tostring())+", Admin: "+GetSQLColumnData(q, 7)+"");
player.Kick();
}
FreeSQLQuery( q );
}
}
function GetBanRemainingTime( bantime, banratio )
{
local ban_current = time()-bantime;
local total_time = "";
local sp = split(banratio,":");
local ban_Days = 0, ban_Hours = 0, ban_Minutes = 0;
local ban_Day = sp[ 0 ].tointeger();
local ban_Hour = sp[ 1 ].tointeger();
local ban_Minute = sp[ 2 ].tointeger();
ban_Days = ban_current/86400;
ban_current = ban_current%86400;
ban_Hours = ban_current/3600;
ban_current = ban_current%3600;
ban_Minutes = ban_current/60;
ban_current = ban_current%60;
ban_Day -= ban_Days;
ban_Hour -= ban_Hours;
ban_Minute -= ban_Minutes;
local mints_to_hour = ban_Minute / 60;
ban_Minute = ban_Minute - (mints_to_hour * 60);
ban_Hour += mints_to_hour;
local hours_to_days = ban_Hour / 24;
ban_Hour = ban_Hour - (hours_to_days * 24);
ban_Day += hours_to_days;
local months = ban_Day / 31;
ban_Day = ban_Day - (months * 31);
local weeks = ban_Day / 7;
ban_Day = ban_Day - (weeks * 7);
local years = months / 12;
months = months - (years * 12);
if(years > 0) total_time += ", "+years+" Years";
if(months > 0){if(total_time != ""){total_time += ", "+months+" Months";}else{total_time += months+" Months";}}
if(weeks > 0){if(total_time != ""){total_time += ", "+weeks+" Weeks";}else{total_time += weeks+" Weeks";}}
if(ban_Day > 0){if(total_time != ""){total_time += ", "+ban_Day+" Days";}else{total_time += ban_Day+" Days";}}
if(ban_Hour > 0){if(total_time != ""){total_time += ", "+ban_Hour+" Hours";}else{total_time += ban_Hour+" Hours";}}
if(ban_Minute > 0){if(total_time != ""){total_time += ", "+ban_Minute+" Minutes";}else{total_time += ban_Minute+" Minutes";}}
return total_time;
}
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 GetPlayer( plr )
{
if ( plr )
{
if ( IsNum( plr ) )
{
plr = FindPlayer( plr.tointeger() );
if ( plr ) return plr;
else return false;
}
else
{
plr = FindPlayer( plr );
if ( plr ) return plr;
else return false;
}
}
else return false;
}
function NumTok(string, separator)
{
local tokenized = split(string, separator);
return tokenized.len();
}
[/noae]
The code is tested and works properly fine if you find any bug then forgive me :P and don't hesitate to reply to this post as it can save others time to kill the bug
NOTE: I've just used Rocky's Temp Ban Calculations :P and other stuff of ban system is made by me