Skip to content
View in the app

A better way to browse. Learn more.

Learn more

auto-bunny-hop-item/addons/amxmodx/scripting/olds_autobhop.sma

olds_autobhop.sma
275 lines · 7.2 KB · Pawn (AMX Mod X)
Raw
/*
 * Auto Bunny Hop Item (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/>.
 *
 * A Base Builder extra item: a human who owns it can hold jump to bunnyhop
 * automatically until death or the end of the round.
 */
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>

#define PLUGIN  "Auto Bunny Hop Item"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

/* ReBaseBuilder is optional: only for the build-phase rule. */
native rebb_is_building_phase()

new const BUY_SOUND[] = "items/gunpickup2.wav"

new g_cvCost, g_cvBuild, g_cvTeam
new g_fwCharge
new bool:g_has[MAX_PLAYERS + 1]
new g_hops[MAX_PLAYERS + 1]

public plugin_natives()
{
    register_library("olds_autobhop")
    register_native("olds_abh_buy", "native_buy")
    register_native("olds_abh_give", "native_give")
    register_native("olds_abh_take", "native_take")
    register_native("olds_abh_has", "native_has")
    set_native_filter("native_filter")
}

public native_filter(const name[], index, trap)
{
    if (!trap && equal(name, "rebb_is_building_phase"))
        return PLUGIN_HANDLED
    return PLUGIN_CONTINUE
}

public plugin_precache()
{
    precache_sound(BUY_SOUND)
}

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

    g_cvCost = create_cvar("olds_abh_cost", "8", FCVAR_NONE, "Points the item costs", true, 0.0, true, 100000.0)
    g_cvBuild = create_cvar("olds_abh_build", "0", FCVAR_NONE, "1 = the item works during the build phase too", true, 0.0, true, 1.0)
    g_cvTeam = create_cvar("olds_abh_team", "2", FCVAR_NONE, "Team of the builders (humans): 1 = T, 2 = CT", true, 1.0, true, 2.0)
    AutoExecConfig(true, "olds_autobhop")

    g_fwCharge = CreateMultiForward("olds_abh_charge", ET_STOP, FP_CELL, FP_CELL)

    register_clcmd("say /abh", "cmd_buy")
    register_clcmd("say_team /abh", "cmd_buy")
    register_clcmd("say /autobhop", "cmd_buy")
    register_concmd("amx_abh", "cmd_admin", ADMIN_KICK, "[player] - who owns the item, or one player's state")

    RegisterHookChain(RG_CBasePlayer_PreThink, "on_prethink_pre", false)
    RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
}

public plugin_end()
{
    DestroyForward(g_fwCharge)
}

public client_putinserver(id)
{
    g_has[id] = false
    g_hops[id] = 0
}

public client_disconnected(id)
{
    g_has[id] = false
    g_hops[id] = 0
}

/* ---------- owning ---------- */

bool:is_human(id)
{
    return is_user_alive(id) && _:get_member(id, m_iTeam) == get_pcvar_num(g_cvTeam)
}

bool:building()
{
    if (!LibraryExists("rebb_api", LibType_Library))
        return false
    return rebb_is_building_phase() != 0
}

buy(id)
{
    if (!is_human(id))
    {
        client_print_color(id, print_team_default, "%L", id, "ABH_HUMANS")
        return 0
    }
    if (g_has[id])
    {
        client_print_color(id, print_team_default, "%L", id, "ABH_ALREADY")
        return 0
    }
    new cost = get_pcvar_num(g_cvCost)
    if (cost > 0)
    {
        new result = PLUGIN_CONTINUE
        ExecuteForward(g_fwCharge, result, id, cost)
        if (result < PLUGIN_HANDLED)
        {
            client_print_color(id, print_team_default, "%L", id, "ABH_NO_POINTS", cost)
            return 0
        }
    }
    g_has[id] = true
    g_hops[id] = 0
    emit_sound(id, CHAN_ITEM, BUY_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    client_print_color(id, print_team_default, "%L", id, "ABH_BOUGHT", cost)
    return 1
}

drop_item(id, const reason[])
{
    if (!g_has[id])
        return 0
    g_has[id] = false
    if (reason[0] && is_user_connected(id))
        client_print_color(id, print_team_default, "%L", id, reason)
    return 1
}

public cmd_buy(id)
{
    if (is_user_connected(id))
        buy(id)
    return PLUGIN_HANDLED
}

public on_killed_post(victim, killer, gib)
{
    if (1 <= victim <= MaxClients)
        drop_item(victim, "ABH_LOST_DEATH")
    return HC_CONTINUE
}

public on_restart_round_pre()
{
    for (new id = 1; id <= MaxClients; id++)
        g_has[id] = false
    return HC_CONTINUE
}

/* ---------- the hop ---------- */

public on_prethink_pre(id)
{
    if (!g_has[id] || !is_user_alive(id))
        return HC_CONTINUE
    // Turned into a zombie: humans' extra items do not carry over.
    if (_:get_member(id, m_iTeam) != get_pcvar_num(g_cvTeam))
    {
        drop_item(id, "ABH_LOST_TEAM")
        return HC_CONTINUE
    }
    if (!(get_entvar(id, var_button) & IN_JUMP))
        return HC_CONTINUE
    // A ladder or water keeps its own movement; never pull a player off a ladder.
    if (get_entvar(id, var_movetype) == MOVETYPE_FLY || get_entvar(id, var_waterlevel) >= 2)
        return HC_CONTINUE
    if (!(get_entvar(id, var_flags) & FL_ONGROUND))
        return HC_CONTINUE
    if (get_pcvar_num(g_cvBuild) != 1 && building())
        return HC_CONTINUE
    // The engine only jumps on a fresh press: make the held key look fresh.
    new old = get_entvar(id, var_oldbuttons)
    if (old & IN_JUMP)
    {
        set_entvar(id, var_oldbuttons, old & ~IN_JUMP)
        g_hops[id]++
    }
    return HC_CONTINUE
}

/* ---------- admin ---------- */

public cmd_admin(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    new name[MAX_NAME_LENGTH]
    if (read_argc() >= 2)
    {
        new arg[32]
        read_argv(1, arg, charsmax(arg))
        new target = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
        if (!target)
            return PLUGIN_HANDLED
        get_user_name(target, name, charsmax(name))
        console_print(id, "%L", id, "ABH_STATE", name, g_has[target], g_hops[target], building())
        return PLUGIN_HANDLED
    }
    new owners
    for (new p = 1; p <= MaxClients; p++)
    {
        if (!g_has[p])
            continue
        get_user_name(p, name, charsmax(name))
        console_print(id, "  %s (%d hops)", name, g_hops[p])
        owners++
    }
    console_print(id, "%L", id, "ABH_OWNERS", owners)
    return PLUGIN_HANDLED
}

/* ---------- natives ---------- */

bool:valid_player(id, const native_name[])
{
    if (id < 1 || id > MaxClients || !is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "%s: invalid player %d", native_name, id)
        return false
    }
    return true
}

public native_buy(plugin, params)
{
    new id = get_param(1)
    if (!valid_player(id, "olds_abh_buy"))
        return 0
    return buy(id)
}

public native_give(plugin, params)
{
    new id = get_param(1)
    if (!valid_player(id, "olds_abh_give") || !is_human(id))
        return 0
    g_has[id] = true
    g_hops[id] = 0
    return 1
}

public native_take(plugin, params)
{
    new id = get_param(1)
    if (!valid_player(id, "olds_abh_take"))
        return 0
    return drop_item(id, "")
}

public native_has(plugin, params)
{
    new id = get_param(1)
    if (id < 1 || id > MaxClients || !g_has[id])
        return 0
    return 1
}

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.