/tempban using dini in days
#3

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)
    So, your new enum will be like this :
    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.
    pawn Код:
    new id,reason[50],time;
        if(sscanf(params,"us[50]I(-1)",id,reason,time)) return SendClientMessage(playerid,-1,"Usage : /ban (id) (reason) (time)");
    To store the time, when he was banned we simply do
    pawn Код:
    P_Data[id][B_Time] = gettime();
    And, to save time till he is banned
    pawn Код:
    P_Data[id][B_Till] = time * 86400;
    So, full command looks like this :
    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
    pawn Код:
    new time = gettime();
    Check if, Current Time - Banned Time is Less than he was banned till , or if he is permanently banned
    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;
    }
Reply


Messages In This Thread
/tempban using dini in days - by mrsamp - 29.07.2012, 08:37
Re: /tempban using dini in days - by doreto - 29.07.2012, 08:51
Re: /tempban using dini in days - by [MM]RoXoR[FS] - 29.07.2012, 09:37
Re: /tempban using dini in days - by mrsamp - 29.07.2012, 13:02
Re: /tempban using dini in days - by [MM]RoXoR[FS] - 29.07.2012, 14:20
Re: /tempban using dini in days - by mrsamp - 29.07.2012, 16:24

Forum Jump:


Users browsing this thread: 1 Guest(s)