Skip to content
View in the app

A better way to browse. Learn more.

Learn more

bunnyhop-speed-enabler/addons/amxmodx/scripting/olds_bhopspeed.sma

olds_bhopspeed.sma
173 lines · 5.7 KB · Pawn (AMX Mod X)
Raw
/*
 * Bunnyhop Speed Enabler (olds.ro)
 * Copyright (C) 2026 daemon (olds.ro)
 *
 * 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. It is distributed WITHOUT ANY WARRANTY; see
 * <https://www.gnu.org/licenses/>.
 *
 * Keeps bunnyhop momentum: a player who lands with jump held takes off again
 * with the horizontal speed they had in the air, up to an optional cap.
 */
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>

#define PLUGIN  "Bunnyhop Speed Enabler"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

#define DUCK_SHARE  0.333
#define FLAT_GROUND 0.98

new g_cvEnable, g_cvMax, g_cvSlowdown
new bool:g_optOut[MAX_PLAYERS + 1]
new bool:g_wasAir[MAX_PLAYERS + 1]
new Float:g_airVel[MAX_PLAYERS + 1][3]
new g_kept[MAX_PLAYERS + 1]

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_dictionary("olds_bhopspeed.txt")

    g_cvEnable = create_cvar("olds_bh_enable", "1", FCVAR_NONE, "1 = bunnyhops keep their speed", true, 0.0, true, 1.0)
    g_cvMax = create_cvar("olds_bh_maxspeed", "400", FCVAR_NONE, "Highest horizontal speed a hop keeps (0 = no cap)", true, 0.0, true, 4000.0)
    g_cvSlowdown = create_cvar("olds_bh_ground_slowdown", "0", FCVAR_NONE, "1 = keep the game's own slowdown after each jump", true, 0.0, true, 1.0)
    AutoExecConfig(true, "olds_bhopspeed")

    RegisterHookChain(RG_CBasePlayer_PreThink, "on_prethink_pre", false)
    RegisterHookChain(RG_CBasePlayer_Jump, "on_jump_pre", false)
    register_forward(FM_PlayerPostThink, "fw_postthink_post", 1)
    register_clcmd("say /bhop", "cmd_bhop")
    register_clcmd("say_team /bhop", "cmd_bhop")
    register_concmd("amx_bhopspeed", "cmd_status", ADMIN_KICK, "<player> - speed and kept hops")
}

public client_putinserver(id)
{
    g_optOut[id] = false
    g_wasAir[id] = false
    g_kept[id] = 0
}

bool:active(id)
{
    return get_pcvar_num(g_cvEnable) == 1 && !g_optOut[id] && is_user_alive(id)
}

/* After the physics: remember the last speed in the air. */
public fw_postthink_post(id)
{
    if (!is_user_alive(id))
        return FMRES_IGNORED
    if (get_entvar(id, var_flags) & FL_ONGROUND)
    {
        // g_wasAir stays set for the landing frame's PreThink and Jump.
        return FMRES_IGNORED
    }
    get_entvar(id, var_velocity, g_airVel[id])
    g_wasAir[id] = true
    return FMRES_IGNORED
}

public on_prethink_pre(id)
{
    if (!active(id))
        return HC_CONTINUE
    if (get_pcvar_num(g_cvSlowdown) != 1)
    {
        // The game's after-jump slowdown (pev_fuser2) is what eats the speed.
        set_entvar(id, var_fuser2, 0.0)
    }
    // Landed without jumping on: the next landing starts fresh.
    if ((get_entvar(id, var_flags) & FL_ONGROUND) && !(get_entvar(id, var_button) & IN_JUMP))
        g_wasAir[id] = false
    return HC_CONTINUE
}

/* Ramps (and surf slopes) keep their own velocity. */
bool:flat_ground(id)
{
    new Float:start[3], Float:end[3]
    get_entvar(id, var_origin, start)
    end = start
    end[2] -= 48.0
    new tr = create_tr2()
    engfunc(EngFunc_TraceHull, start, end, IGNORE_MONSTERS, HULL_HUMAN, id, tr)
    new Float:normal[3], Float:fraction
    get_tr2(tr, TR_flFraction, fraction)
    get_tr2(tr, TR_vecPlaneNormal, normal)
    free_tr2(tr)
    return fraction < 1.0 && normal[2] >= FLAT_GROUND
}

public on_jump_pre(id)
{
    if (!active(id) || !g_wasAir[id])
        return HC_CONTINUE
    g_wasAir[id] = false
    new flags = get_entvar(id, var_flags)
    if (!(flags & FL_ONGROUND) || !(get_entvar(id, var_button) & IN_JUMP))
        return HC_CONTINUE
    // Ladders, water and crouched landings keep their normal speed.
    if (get_entvar(id, var_movetype) != MOVETYPE_WALK || get_entvar(id, var_waterlevel) >= 2 || (flags & FL_DUCKING))
        return HC_CONTINUE
    if (!flat_ground(id))
        return HC_CONTINUE

    new Float:velocity[3]
    get_entvar(id, var_velocity, velocity)
    new Float:air = floatsqroot(g_airVel[id][0] * g_airVel[id][0] + g_airVel[id][1] * g_airVel[id][1])
    new Float:now = floatsqroot(velocity[0] * velocity[0] + velocity[1] * velocity[1])
    if (air <= now)
        return HC_CONTINUE
    new Float:cap = get_pcvar_float(g_cvMax)
    new Float:keep = air
    if (cap > 0.0 && keep > cap)
        keep = cap
    if (keep <= now)
        return HC_CONTINUE
    // The air direction, at the kept speed; vertical speed untouched.
    velocity[0] = g_airVel[id][0] / air * keep
    velocity[1] = g_airVel[id][1] / air * keep
    set_entvar(id, var_velocity, velocity)
    g_kept[id]++
    return HC_CONTINUE
}

public cmd_bhop(id)
{
    if (!is_user_connected(id))
        return PLUGIN_HANDLED
    if (get_pcvar_num(g_cvEnable) != 1)
    {
        client_print_color(id, print_team_default, "%L", id, "BH_SERVER_OFF")
        return PLUGIN_HANDLED
    }
    g_optOut[id] = !g_optOut[id]
    if (g_optOut[id])
        client_print_color(id, print_team_default, "%L", id, "BH_OFF")
    else
        client_print_color(id, print_team_default, "%L", id, "BH_ON", get_pcvar_num(g_cvMax))
    return PLUGIN_HANDLED
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 2))
        return PLUGIN_HANDLED
    new arg[32]
    read_argv(1, arg, charsmax(arg))
    new target = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
    if (!target)
        return PLUGIN_HANDLED
    new name[MAX_NAME_LENGTH], Float:v[3]
    get_user_name(target, name, charsmax(name))
    get_entvar(target, var_velocity, v)
    console_print(id, "%L", id, "BH_STATUS", name, floatround(floatsqroot(v[0] * v[0] + v[1] * v[1])), g_kept[target], !g_optOut[target])
    return PLUGIN_HANDLED
}

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.