29.07.2012, 09:37
I will give you a tutorial on making a temp ban.
- First, we need some variable's
- B_Time ( This ill store the unix time , when the player was banned)
- B_Till ( This will store the time till player is banned)
pawn Код:enum pData
{
pPassword,
pAdmin,
pMoney,
pScore,
pMute,
pFrozen,
pSpecating,
pSkin,
pWarn,
pSpam,
pDuty,
VIP,
//Our new variables
B_Time,
B_Till,
//pBan we wont need this now.
} - Command To Ban
I am using ZCMD for this.
Variables needed :- id (targetid) : Stores the targetid
- reason : Reason for Ban
- time(OPTIONAL) : Time till whihc he is banned.
If admin do not enter any time, he is banned permanently.
To store the time, when he was banned we simply dopawn Код:new id,reason[50],time;
if(sscanf(params,"us[50]I(-1)",id,reason,time)) return SendClientMessage(playerid,-1,"Usage : /ban (id) (reason) (time)");
And, to save time till he is bannedpawn Код:P_Data[id][B_Time] = gettime();
So, full command looks like this :pawn Код:P_Data[id][B_Till] = time * 86400;
pawn Код:CMD:ban(playerid,params[])
{
if(P_Data[playerid][pAdmin[ < 4 && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid,-1,"Invalid rigts :( ");
new id,reason[50],time;
if(sscanf(params,"us[50]I(-1)",id,reason,time)) return SendClientMessage(playerid,-1,"Usage : /ban (id) (reason) (time)");
P_Data[id][B_Time] = gettime();
P_Data[id][B_Till] = time * 86400;
//And messages etc
Kick(id);
return 1;
} - Checking if ban time is over
When player Connects, check if he is registered or not.
Now, we need current unix time
Check if, Current Time - Banned Time is Less than he was banned till , or if he is permanently bannedpawn Код:new time = gettime();
Kick Him
pawn Код:if((time - P_Data[playerid][B_Time]) < P_Data[playerid][B_Till] || P_Data[playerid][B_Till] == -1)
{
SendClientMessage(playerid,-1,"You are banned");
Kick(playerid);
}pawn Код:public OnPlayerConnect(playerid)
{
if(fexist(UserPath(playerid)))
{
//Load his data
new time = gettime();
if((time - P_Data[playerid][B_Time]) < P_Data[playerid][B_Till] || P_Data[playerid][B_Till] == -1)
{
SendClientMessage(playerid,-1,"You are banned");
Kick(playerid);
}
//Your commmands
}
else
{
//Your commands
}
return 1;
} - Saving on disconnecting
I used y_ini, convert it into dini
pawn Код:public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"B_Time",P_Data[playerid][B_Time]);
INI_WriteInt(File,"B_Till",P_Data[playerid][B_Till]);
INI_Close(File);
return 1;
}

