/tempban using dini in days
#1

So I want a tempban cmd for my server. /tempban <playerid> <days> <reason>
Could someone help me?


Really need it I'm not so pro so i can make it by myself
Код:
forward LoadPlayerData(playerid, name[], value[]);

enum pData
{
    pPassword,
    pAdmin,
    pMoney,
    pScore,
    pMute,
    pFrozen,
    pSpecating,
    pSkin,
    pWarn,
    pSpam,
    pDuty,
    VIP,
    pBan,
}
new P_Data[MAX_PLAYERS][pData];

public LoadPlayerData(playerid, name[], value[])
{
    INI_Int("Password", P_Data[playerid][pPassword]);
    INI_Int("Admin", P_Data[playerid][pAdmin]);
    INI_Int("Money", P_Data[playerid][pMoney]);
    INI_Int("Score", P_Data[playerid][pScore]);
    INI_Int("Skin", P_Data[playerid][pSkin]);
    INI_Int("Warn", P_Data[playerid][pWarn]);
    INI_Int("VIP", P_Data[playerid][VIP]);
    return 1;
}
stock GetName(playerid)
{
    new
        pName[MAX_PLAYER_NAME];

    GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
    return pName;
}

if(P_Data[playerid][pAdmin] < 1) return SCM(playerid, COLOR_RED, "You aren't an admin!");

//On my makeadmin command am i using this: (I want someting similiar to this but /tempban instead if you know that i mean... and the time: 1 day (24 hours) is 60 * 60 * 24 = 86400
YCMD:setadmin(playerid, params[], help)
{
        #pragma unused help
        if(P_Data[playerid][pAdmin] < 5 && !IsPlayerAdmin(playerid)) return SCM(playerid, COLOR_RED, "You need to be admin level 4/RCON to use this!");
        new
			string[128],pplayerid,level,pFile[35];
	    format(pFile, 35, Player_File, GetName(pplayerid));
        if(sscanf(params, "ui", pplayerid,level)) return SCM(playerid, COLOR_RED, "Usage: /setadmin [Player ID/Player Name] [Admin Level]");
        if(level > 5 || level <= 0) return SCM(playerid,COLOR_RED,"Max level is 5");
        if(pplayerid == IPI) return SCM(playerid, COLOR_RED, "Wrong playerid!");
        format(string,sizeof(string),""COL_RED"Admin "COL_WHITE"%s "COL_RED"has given you admin level"COL_WHITE" %d",GetName(playerid),level);
        SCM(pplayerid,-1,string);
        format(string,sizeof(string),""COL_RED"Player "COL_WHITE"%s "COL_RED"now have admin level"COL_WHITE" %d",GetName(pplayerid),level);
        SCM(playerid,-1,string);
    	new
    	INI:UserFile = INI_Open(pFile);
		INI_WriteInt(UserFile, "Admin", P_Data[pplayerid][pAdmin]);
		P_Data[pplayerid][pAdmin] = level;
  		INI_Close(UserFile);
        return 1;
}
The time:Here
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=187229
Reply
#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
#4

I still need more help I think I failed at the connect...

Here's my OnPlayerConnect.
Код:
public OnPlayerConnect(playerid)
{
  new dialog[128],string[150],stringconsole[150],ip[16],name[20],country[20];
  format(string, 35, Player_File, GetName(playerid));

    if(!INI_Exists(string))
    {
        format(dialog, sizeof(dialog),""COL_BLUE"Name "COL_WHITE"%s "COL_YELLOW"isn't registered\n\nPlease typepassword", GetName(playerid));
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,""COL_RED"Welcome on my server", dialog, "Register", "Exit");
    }
    else
    {
        format(dialog, sizeof(dialog),""COL_YELLOW"Name "COL_WHITE"%s "COL_YELLOW"is registered\n\nPlease login", GetName(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, ""COL_YELLOW"Welcome To Paradise City",dialog, "Login", "Exit");
 }
	SetPVarInt(playerid, "Join", 1);
	GetPlayerIp(playerid, ip, sizeof(ip));
	GetPlayerName(playerid,name,sizeof(name));
	GetPlayerCountry(playerid,country,sizeof(country));
	format(string, 150, "%s has Connected with ip: %s ", name, ip);	if(P_Data[playerid][pAdmin] < 1)
	format(stringconsole, 150, "[info]%s has Connected with ip: %s ", name, ip);	if(P_Data[playerid][pAdmin] < 1)
	printf(stringconsole);
	for(new i=0;i<MAX_PLAYERS;i++)
	{
 	if(P_Data[i][pAdmin] >= 1)
	 {
	SCM(i,COLOR_RED,string);
	 }
	}
  return 1;
}
Reply
#5

pawn Код:
public OnPlayerConnect(playerid)
{
  new dialog[128],string[150],stringconsole[150],ip[16],name[20],country[20];
  format(string, 35, Player_File, GetName(playerid));

    if(!INI_Exists(string))
    {
        format(dialog, sizeof(dialog),""COL_BLUE"Name "COL_WHITE"%s "COL_YELLOW"isn't registered\n\nPlease typepassword", GetName(playerid));
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,""COL_RED"Welcome on my server", dialog, "Register", "Exit");
    }
    else
    {
    //LOAD PLAYER DATA HERE maybe like   INI_ParseFile(string, "LoadPlayerData", .bExtra = true, .extra = playerid);
        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);
        }
        format(dialog, sizeof(dialog),""COL_YELLOW"Name "COL_WHITE"%s "COL_YELLOW"is registered\n\nPlease login", GetName(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, ""COL_YELLOW"Welcome To Paradise City",dialog, "Login", "Exit");
    }
    SetPVarInt(playerid, "Join", 1);
    GetPlayerIp(playerid, ip, sizeof(ip));
    GetPlayerName(playerid,name,sizeof(name));
    GetPlayerCountry(playerid,country,sizeof(country));
    format(string, 150, "%s has Connected with ip: %s ", name, ip); if(P_Data[playerid][pAdmin] < 1)
    format(stringconsole, 150, "[info]%s has Connected with ip: %s ", name, ip);    if(P_Data[playerid][pAdmin] < 1)
    printf(stringconsole);
    for(new i=0;i<MAX_PLAYERS;i++)
    {
    if(P_Data[i][pAdmin] >= 1)
     {
    SCM(i,COLOR_RED,string);
     }
    }
  return 1;
}
Reply
#6

Thank you!
It seems like it's working now! But if I get any problems so will I contact you via pm!

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)