Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.20 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <hamsandwich>
  4.  
  5. #define VERSION "BETA"
  6.  
  7. #if !defined client_disconnected
  8.     #define client_disconnected client_disconnect
  9. #endif
  10.  
  11. #if !defined MAX_PLAYERS
  12.     #define MAX_PLAYERS 32
  13. #endif
  14.  
  15. #if !defined PLATFORM_MAX_PATH
  16.     #define PLATFORM_MAX_PATH 256
  17. #endif
  18.  
  19. #define PLUGIN_ACCESS ADMIN_KICK
  20. #define CONSECUTIVE_WARNING_COUNT 50
  21.  
  22. #pragma semicolon 1
  23.  
  24. new const g_szPrefix[] = "Krasnodar";
  25.  
  26. enum _:g_iTypes
  27. {
  28.     JUMP_WAIT_JUMP,
  29.     DUCK_WAIT_DUCK
  30. };
  31.  
  32. new const g_iCommandTypes[g_iTypes] =
  33. {
  34.     IN_JUMP,
  35.     IN_DUCK
  36. };
  37.  
  38. new const g_sCommandStrings[g_iTypes][] =
  39. {
  40.     "JWJ",
  41.     "DWD"
  42. };
  43.  
  44. new bool:g_bAlive[MAX_PLAYERS + 1];
  45.  
  46. new g_iPreviousOldButtons[MAX_PLAYERS + 1];
  47. new g_iOldButtons[MAX_PLAYERS + 1];
  48. new g_iButtons[MAX_PLAYERS + 1];
  49.  
  50. new bool:g_bPrevCommandLastedOneFrame[MAX_PLAYERS + 1][g_iTypes];
  51. new g_iConsecutiveDelayedButtons[MAX_PLAYERS + 1][g_iTypes];
  52.  
  53. public plugin_init()
  54. {
  55.     register_plugin("Wait Detector", VERSION, "Reavap");
  56.    
  57.     RegisterHam(Ham_Spawn, "player", "fwdHamSpawn", 1);
  58.     RegisterHam(Ham_Killed, "player", "fwdHamKilled", 0);
  59.    
  60.     register_forward(FM_CmdStart, "fwdCmdStart");
  61. }
  62.  
  63. public client_disconnected(id)
  64. {
  65.     g_bAlive[id] = false;
  66.    
  67.     for (new iTypeIndex = 0; iTypeIndex < g_iTypes; iTypeIndex++)
  68.     {
  69.         resetStats(id, iTypeIndex);
  70.     }
  71. }
  72.  
  73. resetStats(const id, const iTypeIndex)
  74. {
  75.     g_iConsecutiveDelayedButtons[id][iTypeIndex] = 0;
  76.     g_bPrevCommandLastedOneFrame[id][iTypeIndex] = false;
  77. }
  78.  
  79. public fwdHamSpawn(id)
  80. {
  81.     if (is_user_alive(id))
  82.     {
  83.         g_iPreviousOldButtons[id] = 0;
  84.         g_iOldButtons[id] = 0;
  85.         g_iButtons[id] = 0;
  86.        
  87.         g_bAlive[id] = true;
  88.     }
  89.    
  90.     return HAM_IGNORED;
  91. }
  92.  
  93. public fwdHamKilled(iVictim, iAttacker, bShouldGib)
  94. {
  95.     g_bAlive[iVictim] = false;
  96.    
  97.     return HAM_IGNORED;
  98. }
  99.  
  100. public fwdCmdStart(id, uc_handle)
  101. {
  102.     if (g_bAlive[id])
  103.     {
  104.         g_iButtons[id] = get_uc(uc_handle, UC_Buttons);
  105.        
  106.         performCheck(id, JUMP_WAIT_JUMP);
  107.         performCheck(id, DUCK_WAIT_DUCK);
  108.        
  109.         g_iPreviousOldButtons[id] = g_iOldButtons[id];
  110.         g_iOldButtons[id] = g_iButtons[id];
  111.     }
  112.    
  113.     return FMRES_IGNORED;
  114. }
  115.  
  116. performCheck(const id, const iTypeIndex)
  117. {
  118.     new iCommandButton = g_iCommandTypes[iTypeIndex];
  119.     new bool:bPrevCommandLastedOneFrame = g_bPrevCommandLastedOneFrame[id][iTypeIndex];
  120.    
  121.     new iButtons = g_iButtons[id];
  122.     new iOldButtons = g_iOldButtons[id];
  123.     new iPreviousOldButtons = g_iPreviousOldButtons[id];
  124.    
  125.     new iButtonDifferences = iOldButtons ^ iButtons;
  126.     new iReleasedAndPressedButtons = (iButtonDifferences & iOldButtons & iPreviousOldButtons) | (iButtonDifferences &~ (iOldButtons | iPreviousOldButtons));
  127.    
  128.     if (bPrevCommandLastedOneFrame && iReleasedAndPressedButtons)
  129.     {
  130.         g_iConsecutiveDelayedButtons[id][iTypeIndex] += countSetBits(iReleasedAndPressedButtons);
  131.        
  132.         if (g_iConsecutiveDelayedButtons[id][iTypeIndex] >= CONSECUTIVE_WARNING_COUNT)
  133.         {
  134.             resetStats(id, iTypeIndex);
  135.             handleViolation(id, iTypeIndex);
  136.         }
  137.     }
  138.  
  139.     bPrevCommandLastedOneFrame = !(iPreviousOldButtons & iCommandButton) && (iOldButtons & iCommandButton) && !(iButtons & iCommandButton);
  140.     g_bPrevCommandLastedOneFrame[id][iTypeIndex] = bPrevCommandLastedOneFrame;
  141.    
  142.     if (bPrevCommandLastedOneFrame && iReleasedAndPressedButtons)
  143.     {
  144.         g_iConsecutiveDelayedButtons[id][iTypeIndex] = 0;
  145.     }
  146. }
  147.  
  148. handleViolation(const id, const iTypeIndex)
  149. {
  150.     server_cmd("amx_ban 0 #%d ^"%s Detected^"", get_user_userid(id), g_sCommandStrings[iTypeIndex]);
  151.    
  152.     static szAdminMessage[128], szPlayerName[32];
  153.    
  154.     get_user_name(id, szPlayerName, charsmax(szPlayerName));
  155.     formatex(szAdminMessage, charsmax(szAdminMessage), "[%s] Detected usage of %s on player %s", g_szPrefix, g_sCommandStrings[iTypeIndex], szPlayerName);
  156.    
  157.     static aPlayers[MAX_PLAYERS], iPlayerCount;
  158.     get_players(aPlayers, iPlayerCount, "ch");
  159.    
  160.     for (new i = 0; i < iPlayerCount; i++)
  161.     {
  162.         new playerId = aPlayers[i];
  163.        
  164.         if ((get_user_flags(playerId) & PLUGIN_ACCESS) && playerId != id)
  165.         {
  166.             client_print(playerId, print_chat, szAdminMessage);
  167.         }
  168.     }
  169. }
  170.  
  171. countSetBits(x)
  172. {
  173.     x = x - ((x >> 1) & 0x55555555);
  174.     x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  175.     x = (x + (x >> 4)) & 0x0F0F0F0F;
  176.     x = x + (x >> 8);
  177.     x = x + (x >> 16);
  178.     return x & 0x0000003F;
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement