/*
* Bunnyhop Script Detector (olds.ro) - counts the frames between landing and
* the next jump press; a long run of hops pressed on the landing frame or the
* one after it (0 or 1 frame) matches a bunnyhop script, and admins are told.
*
* Copyright (C) 2026 daemon (olds.ro), written by daemon's plugin agent
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. You should have received a copy of the GNU General Public
* License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#define PLUGIN "Bunnyhop Script Detector"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define PERFECT_FRAMES 1 // a press 0 or 1 frame after landing is "perfect"
#define CHAIN_FRAMES 10 // on the ground longer than this without jumping ends the chain
new bool:g_ground[MAX_PLAYERS + 1]
new bool:g_waiting[MAX_PLAYERS + 1] // landed, the next jump press is being timed
new g_frames[MAX_PLAYERS + 1] // frames on the ground since landing
new g_streak[MAX_PLAYERS + 1]
new g_hops[MAX_PLAYERS + 1] // timed hops, for the status
new g_perfect[MAX_PLAYERS + 1]
new g_suspicions[MAX_PLAYERS + 1]
new g_alerts[MAX_PLAYERS + 1]
new Float:g_lastAlert[MAX_PLAYERS + 1]
new bool:g_kicking[MAX_PLAYERS + 1]
new g_cvarStreak, g_cvarAction, g_cvarCooldown
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
g_cvarStreak = create_cvar("olds_bd_streak", "12", FCVAR_NONE, "Perfect hops in a row that raise a suspicion", true, 4.0, true, 100.0)
g_cvarAction = create_cvar("olds_bd_action", "0", FCVAR_NONE, "0 = alert admins, 1 = also kick the player", true, 0.0, true, 1.0)
g_cvarCooldown = create_cvar("olds_bd_cooldown", "60", FCVAR_NONE, "Seconds before the same player can raise another alert", true, 0.0, true, 3600.0)
AutoExecConfig(true, "olds_bhopdetect")
register_concmd("olds_bd_status", "cmd_status", ADMIN_BAN, "- hop timing and suspicions per player")
register_forward(FM_PlayerPreThink, "on_pre_think")
}
public client_putinserver(id)
{
reset_player(id)
}
public client_disconnected(id)
{
reset_player(id)
}
reset_player(id)
{
g_ground[id] = true
g_waiting[id] = false
g_frames[id] = 0
g_streak[id] = 0
g_hops[id] = 0
g_perfect[id] = 0
g_suspicions[id] = 0
g_alerts[id] = 0
g_lastAlert[id] = -99999.0
g_kicking[id] = false
}
public on_pre_think(id)
{
if (!is_user_alive(id) || g_kicking[id])
return FMRES_IGNORED
// Ladders and water make their own jump timing: they do not count and end the chain.
if (pev(id, pev_movetype) == MOVETYPE_FLY || pev(id, pev_waterlevel) >= 2)
{
g_streak[id] = 0
g_waiting[id] = false
g_ground[id] = false
return FMRES_IGNORED
}
new bool:ground = (pev(id, pev_flags) & FL_ONGROUND) != 0
if (ground && !g_ground[id])
{
g_waiting[id] = true // landed: start timing
g_frames[id] = 0
}
g_ground[id] = ground
if (!g_waiting[id])
return FMRES_IGNORED
if (!ground)
{
g_waiting[id] = false // left the ground without a press (a drop)
g_streak[id] = 0
return FMRES_IGNORED
}
new bool:pressed = (pev(id, pev_button) & IN_JUMP) && !(pev(id, pev_oldbuttons) & IN_JUMP)
if (pressed)
{
g_waiting[id] = false
hop(id, g_frames[id])
return FMRES_IGNORED
}
if (++g_frames[id] > CHAIN_FRAMES)
{
g_waiting[id] = false // stood still: the chain is over
g_streak[id] = 0
}
return FMRES_IGNORED
}
hop(id, frames)
{
g_hops[id]++
if (frames > PERFECT_FRAMES)
{
g_streak[id] = 0
return
}
g_perfect[id]++
if (++g_streak[id] < get_pcvar_num(g_cvarStreak))
return
g_streak[id] = 0
suspicion(id)
}
suspicion(id)
{
g_suspicions[id]++
new name[32], authid[35], ip[24]
get_user_name(id, name, charsmax(name))
get_user_authid(id, authid, charsmax(authid))
get_user_ip(id, ip, charsmax(ip), 1)
new streak = get_pcvar_num(g_cvarStreak)
log_amx("[BhopDetect] %s <%s> <%s>: %d perfect hops in a row (suspicion %d)", name, authid, ip, streak, g_suspicions[id])
new Float:now = get_gametime()
if (now - g_lastAlert[id] >= get_pcvar_float(g_cvarCooldown))
{
g_lastAlert[id] = now
g_alerts[id]++
new players[MAX_PLAYERS], count
get_players(players, count, "ch")
for (new i = 0; i < count; i++)
{
if (get_user_flags(players[i]) & ADMIN_BAN)
client_print(players[i], print_chat, "[BhopDetect] %s: %d perfect hops in a row, looks like a bhop script (suspicion %d).", name, streak, g_suspicions[id])
}
}
if (get_pcvar_num(g_cvarAction) == 1)
{
g_kicking[id] = true
log_amx("[BhopDetect] %s <%s> kicked: bunnyhop script suspected (%d perfect hops in a row).", name, authid, streak)
server_cmd("kick #%d ^"Bunnyhop script suspected: %d perfect hops in a row^"", get_user_userid(id), streak)
}
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[BhopDetect] streak %d, action %d, cooldown %d s", get_pcvar_num(g_cvarStreak), get_pcvar_num(g_cvarAction), get_pcvar_num(g_cvarCooldown))
new name[32]
for (new player = 1; player <= MaxClients; player++)
{
if (!is_user_connected(player))
continue
get_user_name(player, name, charsmax(name))
console_print(id, " %s: %d hops timed, %d perfect, streak %d, %d suspicion(s), %d alert(s)", name,
g_hops[player], g_perfect[player], g_streak[player], g_suspicions[player], g_alerts[player])
}
return PLUGIN_HANDLED
}