Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <fakemeta>
- #include <hamsandwich>
- #define VERSION "BETA"
- #if !defined client_disconnected
- #define client_disconnected client_disconnect
- #endif
- #if !defined MAX_PLAYERS
- #define MAX_PLAYERS 32
- #endif
- #if !defined PLATFORM_MAX_PATH
- #define PLATFORM_MAX_PATH 256
- #endif
- #define PLUGIN_ACCESS ADMIN_KICK
- #define CONSECUTIVE_WARNING_COUNT 50
- #pragma semicolon 1
- new const g_szPrefix[] = "Krasnodar";
- enum _:g_iTypes
- {
- JUMP_WAIT_JUMP,
- DUCK_WAIT_DUCK
- };
- new const g_iCommandTypes[g_iTypes] =
- {
- IN_JUMP,
- IN_DUCK
- };
- new const g_sCommandStrings[g_iTypes][] =
- {
- "JWJ",
- "DWD"
- };
- new bool:g_bAlive[MAX_PLAYERS + 1];
- new g_iPreviousOldButtons[MAX_PLAYERS + 1];
- new g_iOldButtons[MAX_PLAYERS + 1];
- new g_iButtons[MAX_PLAYERS + 1];
- new bool:g_bPrevCommandLastedOneFrame[MAX_PLAYERS + 1][g_iTypes];
- new g_iConsecutiveDelayedButtons[MAX_PLAYERS + 1][g_iTypes];
- public plugin_init()
- {
- register_plugin("Wait Detector", VERSION, "Reavap");
- RegisterHam(Ham_Spawn, "player", "fwdHamSpawn", 1);
- RegisterHam(Ham_Killed, "player", "fwdHamKilled", 0);
- register_forward(FM_CmdStart, "fwdCmdStart");
- }
- public client_disconnected(id)
- {
- g_bAlive[id] = false;
- for (new iTypeIndex = 0; iTypeIndex < g_iTypes; iTypeIndex++)
- {
- resetStats(id, iTypeIndex);
- }
- }
- resetStats(const id, const iTypeIndex)
- {
- g_iConsecutiveDelayedButtons[id][iTypeIndex] = 0;
- g_bPrevCommandLastedOneFrame[id][iTypeIndex] = false;
- }
- public fwdHamSpawn(id)
- {
- if (is_user_alive(id))
- {
- g_iPreviousOldButtons[id] = 0;
- g_iOldButtons[id] = 0;
- g_iButtons[id] = 0;
- g_bAlive[id] = true;
- }
- return HAM_IGNORED;
- }
- public fwdHamKilled(iVictim, iAttacker, bShouldGib)
- {
- g_bAlive[iVictim] = false;
- return HAM_IGNORED;
- }
- public fwdCmdStart(id, uc_handle)
- {
- if (g_bAlive[id])
- {
- g_iButtons[id] = get_uc(uc_handle, UC_Buttons);
- performCheck(id, JUMP_WAIT_JUMP);
- performCheck(id, DUCK_WAIT_DUCK);
- g_iPreviousOldButtons[id] = g_iOldButtons[id];
- g_iOldButtons[id] = g_iButtons[id];
- }
- return FMRES_IGNORED;
- }
- performCheck(const id, const iTypeIndex)
- {
- new iCommandButton = g_iCommandTypes[iTypeIndex];
- new bool:bPrevCommandLastedOneFrame = g_bPrevCommandLastedOneFrame[id][iTypeIndex];
- new iButtons = g_iButtons[id];
- new iOldButtons = g_iOldButtons[id];
- new iPreviousOldButtons = g_iPreviousOldButtons[id];
- new iButtonDifferences = iOldButtons ^ iButtons;
- new iReleasedAndPressedButtons = (iButtonDifferences & iOldButtons & iPreviousOldButtons) | (iButtonDifferences &~ (iOldButtons | iPreviousOldButtons));
- if (bPrevCommandLastedOneFrame && iReleasedAndPressedButtons)
- {
- g_iConsecutiveDelayedButtons[id][iTypeIndex] += countSetBits(iReleasedAndPressedButtons);
- if (g_iConsecutiveDelayedButtons[id][iTypeIndex] >= CONSECUTIVE_WARNING_COUNT)
- {
- resetStats(id, iTypeIndex);
- handleViolation(id, iTypeIndex);
- }
- }
- bPrevCommandLastedOneFrame = !(iPreviousOldButtons & iCommandButton) && (iOldButtons & iCommandButton) && !(iButtons & iCommandButton);
- g_bPrevCommandLastedOneFrame[id][iTypeIndex] = bPrevCommandLastedOneFrame;
- if (bPrevCommandLastedOneFrame && iReleasedAndPressedButtons)
- {
- g_iConsecutiveDelayedButtons[id][iTypeIndex] = 0;
- }
- }
- handleViolation(const id, const iTypeIndex)
- {
- server_cmd("amx_ban 0 #%d ^"%s Detected^"", get_user_userid(id), g_sCommandStrings[iTypeIndex]);
- static szAdminMessage[128], szPlayerName[32];
- get_user_name(id, szPlayerName, charsmax(szPlayerName));
- formatex(szAdminMessage, charsmax(szAdminMessage), "[%s] Detected usage of %s on player %s", g_szPrefix, g_sCommandStrings[iTypeIndex], szPlayerName);
- static aPlayers[MAX_PLAYERS], iPlayerCount;
- get_players(aPlayers, iPlayerCount, "ch");
- for (new i = 0; i < iPlayerCount; i++)
- {
- new playerId = aPlayers[i];
- if ((get_user_flags(playerId) & PLUGIN_ACCESS) && playerId != id)
- {
- client_print(playerId, print_chat, szAdminMessage);
- }
- }
- }
- countSetBits(x)
- {
- x = x - ((x >> 1) & 0x55555555);
- x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
- x = (x + (x >> 4)) & 0x0F0F0F0F;
- x = x + (x >> 8);
- x = x + (x >> 16);
- return x & 0x0000003F;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement