Jochemd

TTD example

Oct 7th, 2012
4,452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.21 KB | None | 0 0
  1. #include <a_samp>
  2. #include <sscanf2>
  3. #include <zcmd>
  4. #include <TimestampToDate>
  5.  
  6. #define MAX_TIMEBANS 50
  7.  
  8. forward CheckTimebans();
  9.  
  10. enum tbans
  11. {
  12.     Used,
  13.     IP_Address[16],
  14.     UnbanTimestamp
  15. };
  16.  
  17. new Timebans[MAX_TIMEBANS][tbans];
  18.  
  19. stock GetFreeTimebanID()
  20. {
  21.     for(new i = 0; i < MAX_TIMEBANS; i ++)
  22.     {
  23.         if(!Timebans[i][Used]) return i;
  24.     }
  25.     return -1;
  26. }
  27.  
  28. public OnGameModeInit()
  29. {
  30.     AddPlayerClass(0,0.0,0.0,0.0,0.0,0,0,0,0,0,0);
  31.     SetTimer("CheckTimebans",50000,true); // We run it every 5 seconds, there is really no need to check it every second.
  32.     SetGameModeText("Jochem testing");
  33.     return 1;
  34. }
  35.  
  36. CMD:tban(playerid, params[])
  37. {
  38.     if(IsPlayerAdmin(playerid))
  39.     {
  40.         new target, days, reason[80];
  41.         if(!sscanf(params, "uds[80]", target, days, reason))
  42.         {
  43.             if(!IsPlayerAdmin(target))
  44.             {
  45.                 new string[128], name[2][MAX_PLAYER_NAME], date[6], IP[16], ts_unban = gettime() + (days * 86400), timeban_id = GetFreeTimebanID();
  46.                 if(timeban_id != -1)
  47.                 {
  48.                     GetPlayerName(playerid,name[0],MAX_PLAYER_NAME);
  49.                     GetPlayerName(target,name[1],MAX_PLAYER_NAME);
  50.                     GetPlayerIp(target,IP,16);
  51.                     format(string,sizeof(string),"Administrator %s (ID: %d) has banned %s (ID: %d) from the server (%d days).",name[0],playerid,name[1],target,days);
  52.                     for(new i = 0; i < MAX_PLAYERS; i ++)
  53.                     {
  54.                         if(i != target) SendClientMessage(i,-1,string);
  55.                     }
  56.                     TimestampToDate(ts_unban,date[0],date[1],date[2],date[3],date[4],date[5],2); // One day = 86400 seconds. Assume the server is running in London, or create your own script so the player can choose his timezone.
  57.                     SendClientMessage(target,-1,"- YOU HAVE BEEN BANNED FROM THE SERVER -");
  58.                     format(string,sizeof(string),"- Administrator: %s (ID: %d)",name[0],playerid);
  59.                     SendClientMessage(target,-1,string);
  60.                     format(string,sizeof(string),"- Reason: %s",reason);
  61.                     SendClientMessage(target,-1,string);
  62.                     format(string,sizeof(string),"- Date you will be unbanned: %02d/%02d/%02d %02d:%02d:%02d (%d days)",date[2],date[1],date[0],date[3],date[4],date[5],days);
  63.                     SendClientMessage(target,-1,string);
  64.                     SendClientMessage(target,-1,"- For more info, visit our forums: www.google.com");
  65.                     Timebans[timeban_id][Used] = 1;
  66.                     format(Timebans[timeban_id][IP_Address],16,"%s",IP);
  67.                     Timebans[timeban_id][UnbanTimestamp] = ts_unban;
  68.                     /*
  69.                         Write your own code here to store the ban info (MySQL would be great here?)
  70.                     */
  71.                     BanEx(target,reason);
  72.                     return 1;
  73.                 }
  74.                 else return SendClientMessage(playerid,-1,"Error: There are no free timeban IDs, increase MAX_TIMEBANS in the script.");
  75.             }
  76.             else return SendClientMessage(playerid,-1,"Error: That player is an administrator.");
  77.         }
  78.         else return SendClientMessage(playerid,-1,"Usage: /tban [ID / Part of name] [Days] [Reason]");
  79.     }
  80.     else return 0;
  81. }
  82.  
  83. public CheckTimebans()
  84. {
  85.     new time = gettime(),string[25];
  86.     for(new i = 0; i < MAX_TIMEBANS; i ++)
  87.     {
  88.         if(Timebans[i][Used])
  89.         {
  90.             if(Timebans[i][UnbanTimestamp] <= time)
  91.             {
  92.                 format(string,sizeof(string),"unbanip %s",Timebans[i][IP_Address]);
  93.                 SendRconCommand(string);
  94.                 printf("IP Address %s has been unbanned.",Timebans[i][IP_Address]);
  95.             }
  96.         }
  97.     }
  98.     return 1;
  99. }
  100.  
  101. main()
  102. {
  103. }
Advertisement
Add Comment
Please, Sign In to add comment