07.08.2013, 14:34
(
Последний раз редактировалось fiki574; 12.08.2013 в 13:10.
Причина: NEW VERSION - V1.1
)
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:
- Added "reason[]" parameter in "TimeBan" function
- Added "TimeBanEx" function
- Initial release
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;
}
"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;
}
"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;
}
"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;
}
__________________________________________________ _______________________________________________
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!