Advertisement
Guest User

Ban system by KABOOM aka Norman

a guest
Apr 4th, 2012
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.90 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. ///////////////////////////////--- Ban system ---///////////////////////////////
  3. /////////////////////////--- © by KABOOM aka Norman ---/////////////////////////
  4. ////////////////////////////////////////////////////////////////////////////////
  5. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  6. #include <a_samp>
  7. #include <dini>
  8.  
  9. #define violet 0x9600FFFF
  10. #define hellblau 0x00E1FFFF
  11. #define rot 0xFF0A00FF
  12.  
  13. public OnFilterScriptInit()
  14. {
  15.     print("\n-------------------------------------");
  16.     print("*** Ban system by KABOOM aka Norman ***");
  17.     print("-------------------------------------\n");
  18.     return 1;
  19. }
  20.  
  21. public OnFilterScriptExit()
  22. {
  23.     return 1;
  24. }
  25.  
  26. public OnPlayerConnect(playerid)
  27. {
  28.     new banFormat[128],pname[MAX_PLAYER_NAME];
  29.     GetPlayerName(playerid,pname,sizeof(pname));
  30.     format(banFormat,sizeof(banFormat),"Bans/%s.txt",pname);
  31.     if(dini_Exists(banFormat))
  32.     {
  33.         SendClientMessage(playerid, rot, "DU BIST GEBANNT VON DIESEM SERVER!");
  34.         Kick(playerid);
  35.     }
  36.     else
  37.     {
  38.         //Das passiert wenn der Spieler nicht gebannt ist...
  39.     }
  40.     return 1;
  41. }
  42.  
  43. public OnPlayerCommandText(playerid, cmdtext[])
  44. {
  45.     dcmd(ban,3,cmdtext);
  46.     dcmd(unban,5,cmdtext);
  47.     return 0;
  48. }
  49. dcmd_ban(playerid, params[])
  50. {
  51.     new pID, sGrund[128],pname[MAX_PLAYER_NAME],aname[MAX_PLAYER_NAME],banFormat[128],
  52.         Year, Month, Day, Hour, Minute, Second,
  53.         timestring[128], datestring[128], string[128], string2[128], string3[128];
  54.     GetPlayerName(pID,pname,sizeof(pname));
  55.     format(banFormat,sizeof(banFormat),"Bans/%s.txt",pname);
  56.     if(IsPlayerAdmin(playerid)) {
  57.         return SendClientMessage(playerid,rot,"Du bist kein Admin");
  58.     }
  59.     if(sscanf(params, "us",pID,sGrund)) {
  60.         return SendClientMessage(playerid,rot,"Benutze: '/ban [Spieler ID] [Grund]'");
  61.     }
  62.     if(pID == INVALID_PLAYER_ID) {
  63.         SendClientMessage(playerid, rot, "Ungültige ID!");
  64.     }
  65.     if(dini_Exists(banFormat))
  66.     {
  67.         SendClientMessage(playerid,rot,"Dieser Spieler ist schon gebannt!");
  68.     }
  69.     else
  70.     {
  71.         getdate(Year, Month, Day);
  72.         gettime(Hour, Minute, Second);
  73.         format(timestring,sizeof(timestring),"%02d:%02d:%02d",Hour, Minute, Second);
  74.         format(datestring,sizeof(datestring),"%02d/%02d/%d",Day,Month,Year);
  75.         GetPlayerName(playerid,aname,sizeof(aname));
  76.         dini_Create(banFormat);
  77.         dini_Set(banFormat, "Date",datestring);
  78.         dini_Set(banFormat, "Time",timestring);
  79.         dini_Set(banFormat, "Reason",sGrund);
  80.         dini_Set(banFormat, "Admin",aname);
  81.         format(string,sizeof(string),"Du hast %s gebannt! (Grund: %s)",pname,sGrund);
  82.         SendClientMessage(playerid,hellblau,string);
  83.         format(string2,sizeof(string2),"Du wurdest von Admin %s gebannt! (Grund: %s)",aname,sGrund);
  84.         SendClientMessage(playerid,violet,string2);
  85.         Kick(pID);
  86.         format(string3,sizeof(string3),"%s wurde von Admin %s gebannt! (Grund: %s)",pname,aname,sGrund);
  87.         SendClientMessageToAll(violet,string3);
  88.     }
  89.     return 1;
  90. }
  91. dcmd_unban(playerid, params[])
  92. {
  93.     new banFormat[128], name[MAX_PLAYER_NAME],aname[MAX_PLAYER_NAME],
  94.         string[128],string2[128];
  95.     if(IsPlayerAdmin(playerid)) {
  96.         return SendClientMessage(playerid,rot,"Du bist kein Admin");
  97.     }
  98.     if(sscanf(params, "s",name)) {
  99.         return SendClientMessage(playerid,rot,"Benutze: '/unban [Spielername]'");
  100.     }
  101.     format(banFormat,sizeof(banFormat),"Bans/%s.txt",name);
  102.     if(fexist(banFormat))
  103.     {
  104.         dini_Remove(banFormat);
  105.         GetPlayerName(playerid,aname,sizeof(aname));
  106.         format(string,sizeof(string),"Du hast %s entbannt!",name);
  107.         format(string2,sizeof(string2),"Admin %s hat %s entbannt!", aname, name);
  108.         SendClientMessage(playerid, hellblau, string);
  109.         SendClientMessageToAll(violet,string2);
  110.     }
  111.     else
  112.     {
  113.         SendClientMessage(playerid, rot, "Dieser Spieler ist nicht gebannt!");
  114.     }
  115.     return 1;
  116. }
  117.  
  118. //=========================================================================================================================//
  119. //=================================================== SCANF CODE ==========================================================//
  120. //=========================================================================================================================//
  121. stock sscanf(string[], format[], {Float,_}:...)
  122. {
  123.     #if defined isnull
  124.         if (isnull(string))
  125.     #else
  126.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  127.     #endif
  128.         {
  129.             return format[0];
  130.         }
  131.     #pragma tabsize 4
  132.     new
  133.         formatPos = 0,
  134.         stringPos = 0,
  135.         paramPos = 2,
  136.         paramCount = numargs(),
  137.         delim = ' ';
  138.     while (string[stringPos] && string[stringPos] <= ' ')
  139.     {
  140.         stringPos++;
  141.     }
  142.     while (paramPos < paramCount && string[stringPos])
  143.     {
  144.         switch (format[formatPos++])
  145.         {
  146.             case '\0':
  147.             {
  148.                 return 0;
  149.             }
  150.             case 'i', 'd':
  151.             {
  152.                 new
  153.                     neg = 1,
  154.                     num = 0,
  155.                     ch = string[stringPos];
  156.                 if (ch == '-')
  157.                 {
  158.                     neg = -1;
  159.                     ch = string[++stringPos];
  160.                 }
  161.                 do
  162.                 {
  163.                     stringPos++;
  164.                     if ('0' <= ch <= '9')
  165.                     {
  166.                         num = (num * 10) + (ch - '0');
  167.                     }
  168.                     else
  169.                     {
  170.                         return -1;
  171.                     }
  172.                 }
  173.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  174.                 setarg(paramPos, 0, num * neg);
  175.             }
  176.             case 'h', 'x':
  177.             {
  178.                 new
  179.                     num = 0,
  180.                     ch = string[stringPos];
  181.                 do
  182.                 {
  183.                     stringPos++;
  184.                     switch (ch)
  185.                     {
  186.                         case 'x', 'X':
  187.                         {
  188.                             num = 0;
  189.                             continue;
  190.                         }
  191.                         case '0' .. '9':
  192.                         {
  193.                             num = (num << 4) | (ch - '0');
  194.                         }
  195.                         case 'a' .. 'f':
  196.                         {
  197.                             num = (num << 4) | (ch - ('a' - 10));
  198.                         }
  199.                         case 'A' .. 'F':
  200.                         {
  201.                             num = (num << 4) | (ch - ('A' - 10));
  202.                         }
  203.                         default:
  204.                         {
  205.                             return -1;
  206.                         }
  207.                     }
  208.                 }
  209.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  210.                 setarg(paramPos, 0, num);
  211.             }
  212.             case 'c':
  213.             {
  214.                 setarg(paramPos, 0, string[stringPos++]);
  215.             }
  216.             case 'f':
  217.             {
  218.  
  219.                 new changestr[16], changepos = 0, strpos = stringPos;
  220.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  221.                 {
  222.                     changestr[changepos++] = string[strpos++];
  223.                     }
  224.                 changestr[changepos] = '\0';
  225.                 setarg(paramPos,0,_:floatstr(changestr));
  226.             }
  227.             case 'p':
  228.             {
  229.                 delim = format[formatPos++];
  230.                 continue;
  231.             }
  232.             case '\'':
  233.             {
  234.                 new
  235.                     end = formatPos - 1,
  236.                     ch;
  237.                 while ((ch = format[++end]) && ch != '\'') {}
  238.                 if (!ch)
  239.                 {
  240.                     return -1;
  241.                 }
  242.                 format[end] = '\0';
  243.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  244.                 {
  245.                     if (format[end + 1])
  246.                     {
  247.                         return -1;
  248.                     }
  249.                     return 0;
  250.                 }
  251.                 format[end] = '\'';
  252.                 stringPos = ch + (end - formatPos);
  253.                 formatPos = end + 1;
  254.             }
  255.             case 'u':
  256.             {
  257.                 new
  258.                     end = stringPos - 1,
  259.                     id = 0,
  260.                     bool:num = true,
  261.                     ch;
  262.                 while ((ch = string[++end]) && ch != delim)
  263.                 {
  264.                     if (num)
  265.                     {
  266.                         if ('0' <= ch <= '9')
  267.                         {
  268.                             id = (id * 10) + (ch - '0');
  269.                         }
  270.                         else
  271.                         {
  272.                             num = false;
  273.                         }
  274.                     }
  275.                 }
  276.                 if (num && IsPlayerConnected(id))
  277.                 {
  278.                     setarg(paramPos, 0, id);
  279.                 }
  280.                 else
  281.                 {
  282.                     #if !defined foreach
  283.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  284.                         #define __SSCANF_FOREACH__
  285.                     #endif
  286.                     string[end] = '\0';
  287.                     num = false;
  288.                     new
  289.                         name[MAX_PLAYER_NAME];
  290.                     id = end - stringPos;
  291.                     foreach (Player, playerid)
  292.                     {
  293.                         GetPlayerName(playerid, name, sizeof (name));
  294.                         if (!strcmp(name, string[stringPos], true, id))
  295.                         {
  296.                             setarg(paramPos, 0, playerid);
  297.                             num = true;
  298.                             break;
  299.                         }
  300.                     }
  301.                     if (!num)
  302.                     {
  303.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  304.                     }
  305.                     string[end] = ch;
  306.                     #if defined __SSCANF_FOREACH__
  307.                         #undef foreach
  308.                         #undef __SSCANF_FOREACH__
  309.                     #endif
  310.                 }
  311.                 stringPos = end;
  312.             }
  313.             case 's', 'z':
  314.             {
  315.                 new
  316.                     i = 0,
  317.                     ch;
  318.                 if (format[formatPos])
  319.                 {
  320.                     while ((ch = string[stringPos++]) && ch != delim)
  321.                     {
  322.                         setarg(paramPos, i++, ch);
  323.                     }
  324.                     if (!i)
  325.                     {
  326.                         return -1;
  327.                     }
  328.                 }
  329.                 else
  330.                 {
  331.                     while ((ch = string[stringPos++]))
  332.                     {
  333.                         setarg(paramPos, i++, ch);
  334.                     }
  335.                 }
  336.                 stringPos--;
  337.                 setarg(paramPos, i, '\0');
  338.             }
  339.             default:
  340.             {
  341.                 continue;
  342.             }
  343.         }
  344.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  345.         {
  346.             stringPos++;
  347.         }
  348.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  349.         {
  350.             stringPos++;
  351.         }
  352.         paramPos++;
  353.     }
  354.     do
  355.     {
  356.         if ((delim = format[formatPos++]) > ' ')
  357.         {
  358.             if (delim == '\'')
  359.             {
  360.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  361.             }
  362.             else if (delim != 'z')
  363.             {
  364.                 return delim;
  365.             }
  366.         }
  367.     }
  368.     while (delim > ' ');
  369.     return 0;
  370. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement