Skip to content
View in the app

A better way to browse. Learn more.

Learn more

bunnyhop-block-unstuck/addons/amxmodx/scripting/olds_bhopfix.sma

olds_bhopfix.sma
245 lines · 7.3 KB · Pawn (AMX Mod X)
Raw
/*
 * Bunnyhop Block Unstuck (olds.ro)
 * 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: <https://www.gnu.org/licenses/>.
 *
 * Hide and Seek: players sometimes stick on bunnyhop blocks (func_door). In FM_PlayerPreThink
 * a player standing (FL_ONGROUND) on a listed block with zero speed for olds_bhopfix_ticks
 * ticks in a row is nudged upward by olds_bhopfix_push units (set_pev pev_origin, traced
 * with the player's own hull so a ducked player is never pushed into a ceiling) and the
 * velocity is reset. The blocks are listed per map in configs/bhop/<mapname>.ini by brush
 * model (*12) or targetname. Without the file nothing is listed and nothing happens.
 *
 * Cvars: olds_bhopfix_ticks 8, olds_bhopfix_push 4.0
 * Admin: amx_bhopfix_status (ADMIN_KICK)
 */

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

#pragma semicolon 0

#define PLUGIN  "Bunnyhop Block Unstuck"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

#define MAX_BLOCKS 256
#define MAX_ENTS   2048

enum
{
    BLOCK_UNKNOWN = 0,
    BLOCK_LISTED,
    BLOCK_OTHER
}

new g_ticks
new Float:g_push

new Array:g_models
new Array:g_names
new g_blockState[MAX_ENTS + 1]
new g_stuck[MAX_PLAYERS + 1]
new Float:g_lastLog[MAX_PLAYERS + 1]
new g_nudges
new g_listed

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)

    bind_pcvar_num(create_cvar("olds_bhopfix_ticks", "8", FCVAR_NONE,
        "Ticks without movement on a listed block before the nudge", true, 2.0, true, 100.0), g_ticks)
    bind_pcvar_float(create_cvar("olds_bhopfix_push", "4.0", FCVAR_NONE,
        "Units a stuck player is nudged upward", true, 1.0, true, 32.0), g_push)
    AutoExecConfig(true, "olds_bhopfix")

    register_concmd("amx_bhopfix_status", "cmd_status", ADMIN_KICK, "- shows the listed blocks and the nudges")

    g_models = ArrayCreate(16)
    g_names = ArrayCreate(32)
    register_forward(FM_PlayerPreThink, "on_prethink")
}

public plugin_cfg()
{
    load_blocks()
}

public plugin_end()
{
    ArrayDestroy(g_models)
    ArrayDestroy(g_names)
}

load_blocks()
{
    new map[32], path[160]
    get_mapname(map, charsmax(map))
    get_configsdir(path, charsmax(path))
    format(path, charsmax(path), "%s/bhop/%s.ini", path, map)
    new file = fopen(path, "rt")
    if (!file)
    {
        log_amx("No block list for %s (%s): no blocks are watched", map, path)
        return
    }
    new line[96], key[16], value[64], number
    while (fgets(file, line, charsmax(line)))
    {
        number++
        trim(line)
        if (!line[0] || line[0] == ';' || (line[0] == '/' && line[1] == '/'))
            continue
        if (ArraySize(g_models) + ArraySize(g_names) >= MAX_BLOCKS)
        {
            log_amx("%s: more than %d blocks, the rest are ignored", path, MAX_BLOCKS)
            break
        }
        if (line[0] == '*')
        {
            if (strlen(line) > 1 && is_str_num(line[1]))
                ArrayPushString(g_models, line)
            else
                log_amx("%s line %d: bad brush model ^"%s^", skipped", path, number, line)
            continue
        }
        parse(line, key, charsmax(key), value, charsmax(value))
        if (equali(key, "targetname") && value[0])
            ArrayPushString(g_names, value)
        else
            log_amx("%s line %d: expected *<number> or targetname <name>, skipped", path, number)
    }
    fclose(file)
    log_amx("Block list for %s: %d models, %d targetnames", map, ArraySize(g_models), ArraySize(g_names))
}

/* Whether an entity is a listed bhop block; worked out once per entity. */
bool:is_listed_block(ent)
{
    if (ent <= MaxClients || ent > MAX_ENTS || !pev_valid(ent))
        return false
    if (g_blockState[ent] != BLOCK_UNKNOWN)
        return g_blockState[ent] == BLOCK_LISTED
    g_blockState[ent] = BLOCK_OTHER
    new cls[16]
    pev(ent, pev_classname, cls, charsmax(cls))
    if (!equal(cls, "func_door"))
        return false
    new text[64], item[64]
    pev(ent, pev_model, text, charsmax(text))
    for (new i = 0, n = ArraySize(g_models); i < n; i++)
    {
        ArrayGetString(g_models, i, item, charsmax(item))
        if (equal(text, item))
        {
            g_blockState[ent] = BLOCK_LISTED
            g_listed++
            return true
        }
    }
    pev(ent, pev_targetname, text, charsmax(text))
    if (text[0])
    {
        for (new i = 0, n = ArraySize(g_names); i < n; i++)
        {
            ArrayGetString(g_names, i, item, charsmax(item))
            if (equal(text, item))
            {
                g_blockState[ent] = BLOCK_LISTED
                g_listed++
                return true
            }
        }
    }
    return false
}

public on_prethink(id)
{
    if (!is_user_alive(id))
    {
        g_stuck[id] = 0
        return FMRES_IGNORED
    }
    new flags = pev(id, pev_flags)
    if (!(flags & FL_ONGROUND))
    {
        g_stuck[id] = 0
        return FMRES_IGNORED
    }
    new Float:vel[3]
    pev(id, pev_velocity, vel)
    if (vector_length(vel) >= 1.0)
    {
        g_stuck[id] = 0
        return FMRES_IGNORED
    }
    if (!is_listed_block(pev(id, pev_groundentity)))
    {
        g_stuck[id] = 0
        return FMRES_IGNORED
    }
    if (++g_stuck[id] < g_ticks)
        return FMRES_IGNORED
    g_stuck[id] = 0
    nudge(id, flags)
    return FMRES_IGNORED
}

nudge(id, flags)
{
    new Float:start[3], Float:stop[3]
    pev(id, pev_origin, start)
    stop[0] = start[0]
    stop[1] = start[1]
    stop[2] = start[2] + floatclamp(g_push, 1.0, 32.0)
    /* Trace with the player's own hull: ducked players use the small hull. */
    new hull = (flags & FL_DUCKING) ? HULL_HEAD : HULL_HUMAN
    new trace = create_tr2()
    engfunc(EngFunc_TraceHull, start, stop, IGNORE_MONSTERS, hull, id, trace)
    new Float:fraction
    get_tr2(trace, TR_flFraction, fraction)
    new solid = get_tr2(trace, TR_StartSolid)
    free_tr2(trace)
    new Float:zero[3]
    set_pev(id, pev_velocity, zero)
    if (solid || fraction <= 0.0)
        return
    new Float:moved = (stop[2] - start[2]) * fraction
    stop[2] = start[2] + moved
    set_pev(id, pev_origin, stop)
    set_pev(id, pev_flags, flags & ~FL_ONGROUND)
    g_nudges++
    new Float:now = get_gametime()
    if (now - g_lastLog[id] >= 1.0)
    {
        g_lastLog[id] = now
        new name[MAX_NAME_LENGTH]
        get_user_name(id, name, charsmax(name))
        log_amx("Nudged %s up %.1f units off bhop block %d", name, moved, pev(id, pev_groundentity))
    }
}

public client_disconnected(id)
{
    g_stuck[id] = 0
    g_lastLog[id] = 0.0
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    console_print(id, "Bhop unstuck: %d models and %d targetnames listed, %d block entities matched, %d nudges, ticks %d, push %.1f",
        ArraySize(g_models), ArraySize(g_names), g_listed, g_nudges, g_ticks, g_push)
    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.