SA-MP Forums Archive
Need help with tempban system - 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: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Need help with tempban system (/showthread.php?tid=607161)



Need help with tempban system - 1fret - 15.05.2016

ok im trying to make a tempban and when ever i type /tempban [playerid][time][reason], it kicks the player but the player can still reconnect as if they werent ban using the same name and ip.

pawn Код:
if(IsPlayerAdmin(playerid) || pInfo[playerid][aAdmin] >= 1)
    {
       new id, reason[50];
       new year,month,day,hour,minuite,second,Hours,BanTime,d,h,m,Temp;
       if(sscanf(params, "uis[50]", id, Hours, reason)) return SendClientMessage(playerid, red, "Usage: /tempban <Player ID> <Hours> <Reason>");
       {
          getdate(year, month, day);
          gettime(hour,minuite,second);
          BanTime = gettime() + (Hours*60*60);
          if(pInfo[id][Logged] == 1)
          {
              format(UserPath(playerid), 100, PATH, GetName(id));
              new INI:ACCOUNT = INI_Open(UserPath(playerid));
              INI_WriteInt(ACCOUNT, "TempBan", BanTime);
              INI_Close(ACCOUNT);
          }
          Temp = BanTime - gettime();
          format(astring,sizeof(astring),"%s has been Temporarily Banned by An Administrator ,for %s  | Reason: %s <Date: %d/%d/%d> <Time: %d:%d>",GetName(id),ConvertTime(Temp,m,h,d),reason,day,month,year,hour,minuite);
          SendClientMessageToAll(red,astring);
          Temp = BanTime - gettime();
          format(anstring,sizeof(anstring),"{37C8C8}Administrator %s has Temp banned you for %s REASON |: \"%s\"\n\n", GetName(playerid),ConvertTime(Temp,m,h,d),reason);
          ShowPlayerDialog(id,DIATEMPBAN,DIALOG_STYLE_MSGBOX,"You are Temporarily BANNED",anstring,"OK","");
          format(astring,sizeof(astring),"[TEMP BAN] %s has Temporarily banned %s for %s | reason: ",GetName(playerid),GetName(id),ConvertTime(BanTime,m,h,d),reason);
          WriteToLog(astring,"Bans");
          CommandToAdmins(playerid,"tempban");
          return SetTimerEx("KickPlayer",100,false,"d", id);
        }
    }
    else return ShowMessage(playerid, red, 1);
}



Re: Need help with tempban system - oMa37 - 15.05.2016

You have to check if the player is banned, in OnPlayerConnect.


Re: Need help with tempban system - 1fret - 15.05.2016

Quote:
Originally Posted by oMa37
Посмотреть сообщение
You have to check if the player is banned, in OnPlayerConnect.
Already have that:
pawn Код:
format(UserPath(playerid), 100,PATH, GetName(playerid));
        INI_ParseFile(UserPath(playerid), "Playerinfor", .bExtra = true, .extra = playerid);
   if(pInfo[playerid][TempBan] >= gettime())
    {
        new minu, hour ,day, sec = pInfo[playerid][TempBan] - gettime();
        format(astring, sizeof(astring), "You are temporarily banned more %s",ConvertTime(sec,minu,hour,day));
        ShowPlayerDialog(playerid, DIATEMPBAN, DIALOG_STYLE_MSGBOX," {FB0404}You are temp baned", astring, "Ok", "");
        SetTimerEx("KickPlayer",100,false,"d", playerid);
        format(astring, sizeof(astring),"\"%s\" has been automatically kick | reason: 'Player is Temporarily banned'", GetName(playerid));
        SendToAdmins(orange,astring);
    }
    else if(pInfo[playerid][TempBan] > 0)
    {
        new year,month,day;
        getdate(year,month,day);
        SendClientMessage(playerid,green,"Your tempbanned period has been expired! welcome back");
        format(astring,sizeof(astring),"[EXPIRED on %d/%d/%d]",year,month,day);
        format(UserPath(playerid), 100, PATH, GetName(playerid));
        new INI:ACCOUNT = INI_Open(UserPath(playerid));
        INI_WriteString(ACCOUNT, "TempBan", astring);
        INI_Close(ACCOUNT);
        pInfo[playerid][TempBan] = 0;
    }
     
forward Playerinfor(playerid,name[],value[]);
public Playerinfor(playerid, name[], value[])
{
    INI_Int("Banned", pInfo[playerid][Banned]);
    INI_Int("TempBan", pInfo[playerid][TempBan]);
    return 1;
}



Re: Need help with tempban system - oMa37 - 15.05.2016

What is this?
PHP код:
INI_WriteInt(ACCOUNT"TempBan"BanTime); 
It must be:
PHP код:
INI_WriteInt(ACCOUNT"TempBan"pInfo[playerid][TempBan]); 



Re: Need help with tempban system - 1fret - 15.05.2016

Quote:
Originally Posted by oMa37
Посмотреть сообщение
What is this?
PHP код:
INI_WriteInt(ACCOUNT"TempBan"BanTime); 
It must be:
PHP код:
INI_WriteInt(ACCOUNT"TempBan"pInfo[playerid][TempBan]); 
sorry but that didnt change anything the player can still connect to the server after the tempban


Re: Need help with tempban system - oMa37 - 15.05.2016

Try using fexist
PHP код:
if(fexist(UserPath(playerid))) 



Re: Need help with tempban system - 1fret - 15.05.2016

sorry man nothing is working could you link me a good tutorial or a good admin system with it so i can use it as a guide to making mine work


Re: Need help with tempban system - oMa37 - 15.05.2016

Try this
https://sampforum.blast.hk/showthread.php?tid=503631


Re: Need help with tempban system - BornHuman - 15.05.2016

How I would do it is creating a new directory with files of the names of banned players, containing their unban date inside the file. That way, when a player tries to login you can check that directory for their name, and if it exists then you can get the time they are unbanned. If it is after that time, they can login and you can set appropriate variables in their main file as well as deleting the file from the bans.