BigETI

Anti-C-Bug DE

Aug 28th, 2011
953
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Anti C-Bug System gemacht von BigETI©
  3.     Alle rechte gehören mir!
  4. */
  5.  
  6. //Includes
  7. #include <a_samp>
  8.  
  9. //Defines
  10. #define DRED                                0x991111FF
  11. #define PRESSED(%0)                         (newkeys&(%0))&&!(oldkeys&(%0))
  12. #define RELEASED(%0)                        (oldkeys&(%0))&&!(newkeys&(%0))
  13. #define CreateVarTimerEx(%0,%1)             %0 = SetTimerEx(%1)
  14. #define SafeKillTimer(%0);                  if(%0 != 0)\
  15.     {\
  16.     KillTimer(%0);\
  17.     %0 = 0;\
  18.     }
  19. #define Create1VarTimerEx(%0,%1)            if(%0 == 0) %0 = SetTimerEx(%1)
  20. #define ResetVar(%0)                        %0 = 0
  21. #define INVALID_WEAPON_SLOT_ID              -1
  22. #define UseBrackets                         if(negative != positive)
  23. #define SendClientMessageToAllF(%0,%1,%2);  UseBrackets\
  24.     {\
  25.     new formatstring[512];\
  26.     format(formatstring,sizeof(formatstring),%1,%2);\
  27.     SendClientMessageToAll(%0,formatstring);\
  28.     }
  29.    
  30. //News
  31. new kicktimer[MAX_PLAYERS], cbugtimer[MAX_PLAYERS], cbugcooldowntimer[MAX_PLAYERS], bool:negative = false, bool:positive = true;
  32.  
  33. //Forwards
  34. forward KickPlayer(playerid);
  35. forward CBugCoolDown(playerid);
  36. forward UnCheckPlayerCBug(playerid);
  37.  
  38. //Stocks
  39. stock ReturnPlayerName(playerid)
  40. {
  41.     new pname[MAX_PLAYER_NAME];
  42.     GetPlayerName(playerid, pname, sizeof(pname));
  43.     return pname;
  44. }
  45.  
  46. stock ResetPlayerTimers(playerid)
  47. {
  48.     SafeKillTimer(kicktimer[playerid]);
  49.     SafeKillTimer(cbugtimer[playerid]);
  50.     SafeKillTimer(cbugcooldowntimer[playerid]);
  51. }
  52.  
  53. stock GetPlayerWeaponSlot(playerid)
  54. {
  55.     new slot;
  56.     switch(GetPlayerWeapon(playerid))
  57.     {
  58.         case 0,1: slot = 0;
  59.         case 2..9: slot = 1;
  60.         case 22..24: slot = 2;
  61.         case 25..27: slot = 3;
  62.         case 28,29,32: slot = 4;
  63.         case 30,31: slot = 5;
  64.         case 33,34: slot = 6;
  65.         case 35..38: slot = 7;
  66.         case 16..18,39: slot = 8;
  67.         case 41..43: slot = 9;
  68.         case 10..15: slot = 10;
  69.         case 44..46: slot = 11;
  70.         case 40: slot = 12;
  71.         default: slot = INVALID_WEAPON_SLOT_ID;
  72.     }
  73.     return slot;
  74. }
  75.  
  76. stock GivePVarInt(playerid, varname[], int_value) SetPVarInt(playerid, varname, GetPVarInt(playerid, varname)+int_value);
  77.  
  78. public KickPlayer(playerid)
  79. {
  80.     ResetVar(kicktimer[playerid]);
  81.     Kick(playerid);
  82. }
  83.  
  84. public CBugCoolDown(playerid)
  85. {
  86.     ResetVar(cbugcooldowntimer[playerid]);
  87.     SetPVarInt(playerid, "CBugWarnings", 0);
  88. }
  89.  
  90. public UnCheckPlayerCBug(playerid)
  91. {
  92.     ResetVar(cbugtimer[playerid]);
  93.     SetPVarInt(playerid, "CBugCheck", 0);
  94. }
  95.  
  96. public OnFilterScriptInit()
  97. {
  98.     print("\n=============================");
  99.     print(" BigETI's Anti C-Bug System ©");
  100.     print("=============================\n");
  101.     return 1;
  102. }
  103.  
  104. public OnFilterScriptExit()
  105. {
  106.     for(new playerid = 0; playerid < MAX_PLAYERS; playerid++) if(IsPlayerConnected(playerid)) ResetPlayerTimers(playerid);
  107.     return 1;
  108. }
  109.  
  110. public OnPlayerDisconnect(playerid, reason)
  111. {
  112.     ResetPlayerTimers(playerid);
  113.     return 1;
  114. }
  115.  
  116. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  117. {
  118.     if(PRESSED(KEY_CROUCH))
  119.     {
  120.         if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
  121.         {
  122.             if(GetPVarInt(playerid, "CBugCheck") == 1 && (GetPlayerWeaponSlot(playerid) == 2 || GetPlayerWeaponSlot(playerid) == 3 || GetPlayerWeaponSlot(playerid) == 6))
  123.             {
  124.                 SafeKillTimer(cbugtimer[playerid]);
  125.                 SetPVarInt(playerid, "CBugCheck", 0);
  126.                 GivePVarInt(playerid, "CBugWarnings", 1);
  127.                 if(GetPVarInt(playerid, "CBugWarnings") == 4)
  128.                 {
  129.                     SendClientMessageToAllF(DRED, "%s(%d) wurde wegen c-bugging gekickt.", ReturnPlayerName(playerid), playerid);
  130.                     Create1VarTimerEx(kicktimer[playerid], "KickPlayer", 500, false, "d", playerid);
  131.                 }
  132.                 else if(GetPVarInt(playerid, "CBugWarnings") < 4)
  133.                 {
  134.                     SafeKillTimer(cbugcooldowntimer[playerid]);
  135.                     CreateVarTimerEx(cbugcooldowntimer[playerid], "CBugCoolDown", 10000, false, "d", playerid);
  136.                     SendClientMessage(playerid, DRED, "C-bugge nicht wieder, sonst wirst du gekickt!");
  137.                     //Hier kann man noch eine Nachricht für nur Admins einfügen.
  138.                     //Beispiel: SendClientMessageToAdminsF(DRED, "%s(%d) wurde beim c-buggen erwischt.", ReturnPlayerName(playerid), playerid);
  139.                 }
  140.             }
  141.         }
  142.     }
  143.     if(PRESSED(KEY_FIRE)) //Kann ausgeführt werden, während man die Feuer Taste gedrückt hält
  144.     {
  145.         if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
  146.         {
  147.             if(GetPlayerWeaponSlot(playerid) == 2 || GetPlayerWeaponSlot(playerid) == 3 || GetPlayerWeaponSlot(playerid) == 6)
  148.             {
  149.                 SafeKillTimer(cbugtimer[playerid]);
  150.                 SetPVarInt(playerid, "CBugCheck", 1);
  151.                 CreateVarTimerEx(cbugtimer[playerid], "UnCheckPlayerCBug", 300, false, "d", playerid);
  152.             }
  153.         }
  154.     }
  155.     if(RELEASED(KEY_FIRE)) //Kann ausgeführt werden, während man die Feuer Taste losgelassen hat.
  156.     {
  157.         SetPVarInt(playerid, "IsShooting", 0);
  158.         if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
  159.         {
  160.             if(GetPlayerWeaponSlot(playerid) == 2 || GetPlayerWeaponSlot(playerid) == 3 || GetPlayerWeaponSlot(playerid) == 6)
  161.             {
  162.                 SafeKillTimer(cbugtimer[playerid]);
  163.                 SetPVarInt(playerid, "CBugCheck", 1);
  164.                 CreateVarTimerEx(cbugtimer[playerid], "UnCheckPlayerCBug", 300, false, "d", playerid);
  165.             }
  166.         }
  167.     }
  168.     return 1;
  169. }
RAW Paste Data