SA-MP Forums Archive
[Include] fban.inc -> Easily ban players for certain amount of time - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] fban.inc -> Easily ban players for certain amount of time (/showthread.php?tid=456796)



fban.inc -> Easily ban players for certain amount of time - fiki574 - 07.08.2013

fban.inc v1.1

Updated on 12.8.2013 | 15:30
INTRODUCTION:
Hello. After long time of inactivity and un-wilingness + lack of interest, I eventually decided to release this neat include. With this include, you can either ban player temporarily or permanently, depending on you. I'm gonna explain each function from include, and what it does. As a side note - I haven't made ban checking, that's what you have to do on your own (under OnPlayerConnect, for example).

__________________________________________________ __________________________________________________

FUNCTIONS:
pawn Код:
native InitBanDatabase(dbname[]);
native TimeBan(playerid, reason[], bantype = BAN_TYPE_PERMANENT, hours = 0, minutes = 0, seconds = 0);
native TimeBanEx(name[], bantype = BAN_TYPE_PERMANENT, hours = 0, minutes = 0, seconds = 0);
native IsPlayerBanned(playerid);
native IsPlayerBannedEx(name[]);
native GetPlayerBanTime(playerid, &year, &month, &day, &hour, &min, &sec);
native GetPlayerBanTimeEx(name[], &year, &month, &day, &hour, &min, &sec);
native UnbanPlayer(playerid);
native UnbanPlayerEx(name[]);
__________________________________________________ _______________________________________________

CHANGELOG:

Version 1.1: Version 1.0:__________________________________________________ _______________________________________________

EXPLANATION:

First, also pretty much most important function, is "InitBanDatabase". Since this include uses another include named "BUD" made by Slice (look down for link to original thread), you have to specify your database name. Example:
pawn Код:
public OnFilterScriptInit()
{
    InitBanDatabase("bans.db");
    return 1;
}
This function will create "bans.db" database in "scriptfiles" folder which is later used in pretty much whole ban system.


"TimeBan" function is the actual ban function. There are few ways you can use it as there are also optional parameters in there. Example:
pawn Код:
COMMAND:timeban(playerid,params[])
{
     new pid, reason[50];
     if(!sscanf(params, "rs[50]",  pid, reason))
     {
          TimeBan(pid, reason, BAN_TYPE_TEMP_NORMAL, 48);
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /timeban <playerid> <reason>");
     return 1;
}
This will ban a player for 48 hours / 2 days. However, if you just use first parameter, which is "playerid", it will ban player permanently. Next...


"TimeBanEx" does exactly same thing as non-"ex" function, it just has "name[]" parameter, instead of "playerid" parameter.


"IsPlayerBanned" checks if player exists in ban database. If yes, function returns 1, if not function returns 0. Simple as that.


"IsPlayerBannedEx" does exactly same thing as non-"ex" function, it just has "name[]" parameter, instead of "playerid" parameter. Example:
pawn Код:
COMMAND:isbanned(playerid,params[])
{
     new name[32];
     if(!sscanf(params, "s[32]",  name))
     {
          if(IsPlayerBannedEx(name) == 1) SendClientMessage(playerid, -1, "Player is permanently banned.");
          else if(IsPlayerBannedEx(name) == 2) SendClientMessage(playerid, -1, "Player is temporarily banned.");
          else if(IsPlayerBannedEx(name) == 0) SendClientMessage(playerid, -1, "Player is not banned.");
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /isbanned <name>");
     return 1;
}

"GetPlayerBanTime" returns time and date when player will have their ban removed. Though, there's no auto-ban removal, another thing you have to do on your own (again, you can do that under OnPlayerConnect and simply unban player).


"GetPlayerBanTimeEx" does exactly same thing as non-"ex" function, it just has "name[]" parameter, instead of "playerid" parameter. Example:
pawn Код:
COMMAND:checkban(playerid,params[])
{
     new name[32];
     if(!sscanf(params, "s[32]",  name))
     {
          new y, mo, d, h, mi, s;
          GetPlayerBanTime(playerid, y, mo, d, h, mi, s);
          new str[100];
          format(str, sizeof(str), "%s's ban expires on: %d.%d.%d | %d:%d:%d", name, d, mo, y, h, mi, s);
          SendClientMessage(playerid, -1, str);
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /checkban <name>");
     return 1;
}
Simple, eh?


"UnbanPlayer" function removes player from ban database and allows him to play.


"UnbanPlayerEx" does exactly same thing as non-"ex" function, it just has "name[]" parameter, instead of "playerid" parameter. Example:
pawn Код:
COMMAND:unban(playerid,params[])
{
     new name[32];
     if(!sscanf(params, "s[32]",  name))
     {
          UnbanPlayerEx(name);
          SendClientMessage(playerid, -1, "Player is unbanned.");
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /unban<name>");
     return 1;
}
Also, again a note - all function already have some checks inside themselves, so there's no need to check e.g. if player is in database. Include does it all.

__________________________________________________ _______________________________________________

CREDITS:

fiki574 - creating this include
Slice - BUD (Blazing User Database) (click here)
Zeex - ZCDM command processor used in my examples (click here)

__________________________________________________ _______________________________________________

BUGS:

Haven't found any, though there's I think an exploit. If you type large amount of hours, months and days won't be properly calculated and it may happen that months will have >= 32 days. :O

Also, report if you find any bugs!

__________________________________________________ _______________________________________________

DOWNLOAD:

Pastebin (v1.1) (current, recommended)

No mirrors, please!
__________________________________________________ _______________________________________________

Regards,
Fiki!


Re: fban.inc -> Easily ban players for certain amount of time - Anak - 07.08.2013

nice, i will test it on my server.


Re: fban.inc -> Easily ban players for certain amount of time - PT - 07.08.2013

Good i like!


Re: fban.inc -> Easily ban players for certain amount of time - SsHady - 07.08.2013

Great Job D
Seem's a bit complicated but Nice
+1


Re: fban.inc -> Easily ban players for certain amount of time - fiki574 - 07.08.2013

Quote:
Originally Posted by Anak
Посмотреть сообщение
nice, i will test it on my server.
Thanks. Let me know the results

Quote:
Originally Posted by PT
Посмотреть сообщение
Good i like!
Thank you.

Quote:
Originally Posted by SsHady
Посмотреть сообщение
Great Job D
Seem's a bit complicated but Nice
+1
Thanks. It may seem, but math does it's job.


NOTE: Small fix has been made, check out pastebin.


Re: fban.inc -> Easily ban players for certain amount of time - Jochemd - 07.08.2013

I have a suggestion: use timestamps. It's way easier and it might even be WAY less work if you use the TimestampToDate include


Re: fban.inc -> Easily ban players for certain amount of time - fiki574 - 07.08.2013

Quote:
Originally Posted by Jochemd
Посмотреть сообщение
I have a suggestion: use timestamps. It's way easier and it might even be WAY less work if you use the TimestampToDate include
Well, yes, but I wanted to do it like this, hard way (or is it hard way?).


Re: fban.inc -> Easily ban players for certain amount of time - Tamer - 07.08.2013

Just on time, what can I say? I was planning to do a very complicated ban system with MYSQL databses but with this I don't need it at all.

Thanks a lot, I will integrate my script to this soon.

If possible, make functions to allow us ban players which are not online, so: TimeBanEx([name]...)

Add reason parameter to the ban function. Also please add IP bans.


Re: fban.inc -> Easily ban players for certain amount of time - fiki574 - 07.08.2013

Quote:
Originally Posted by Tamer T
Посмотреть сообщение
Just on time, what can I say? I was planning to do a very complicated ban system with MYSQL databses but with this I don't need it at all.

Thanks a lot, I will integrate my script to this soon.

If possible, make functions to allow us ban players which are not online, so: TimeBanEx([name]...)

Add reason parameter to the ban function. Also please add IP bans.
I plan on adding such features in future versions, of course.

And thank you


Re: fban.inc -> Easily ban players for certain amount of time - Jochemd - 07.08.2013

Quote:
Originally Posted by fiki574
Посмотреть сообщение
Well, yes, but I wanted to do it like this, hard way (or is it hard way?).
Yeah this is the hard way. Well not hard but it could be easier


Re: fban.inc -> Easily ban players for certain amount of time - fiki574 - 12.08.2013

Update!

Please redownload new version 1.1


Re: fban.inc -> Easily ban players for certain amount of time - dEcooR - 12.08.2013

nice one


Re: fban.inc -> Easily ban players for certain amount of time - fiki574 - 12.08.2013

Quote:
Originally Posted by dEcooR
Посмотреть сообщение
nice one
Thanks


Re: fban.inc -> Easily ban players for certain amount of time - Tamer - 12.08.2013

Thanks for the update.


Re: fban.inc -> Easily ban players for certain amount of time - fiki574 - 13.08.2013

Quote:
Originally Posted by Tamer T
Посмотреть сообщение
Thanks for the update.
No problem


Re: fban.inc -> Easily ban players for certain amount of time - xiaoyang - 26.07.2015

How to write a custom time Ban cmd.