/*
* Long Jump Bunny Hop Combo (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. It is distributed WITHOUT ANY WARRANTY; see
* <https://www.gnu.org/licenses/>.
*
* A long jump on the ground: duck and press jump, or the +ljump command
* (hold it to keep long-jumping on every landing). It sets the horizontal
* speed to olds_lj_force along the view and a vertical push of 300, with the
* stock player/pl_jump1.wav; the landing plays it again, lower.
* - One long jump every olds_lj_cooldown seconds...
* - ...except a chain: a long jump within olds_lj_window seconds of landing
* from a long jump keeps the horizontal speed and adds the force to it,
* never above olds_lj_cap.
* - Not on a ladder, in noclip or in water, not dead: then nothing happens
* and the normal jump (if any) is left alone.
* Damage (trigger_hurt, falls) is never touched.
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>
#define PLUGIN "Long Jump Bunny Hop Combo"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define VERTICAL_PUSH 300.0
new const SND_JUMP[] = "player/pl_jump1.wav"
new g_cvEnable, g_cvForce, g_cvCooldown, g_cvWindow, g_cvCap
new bool:g_hold[MAX_PLAYERS + 1] // +ljump is held
new bool:g_launch[MAX_PLAYERS + 1] // duck+jump seen in PreThink: apply after the move
new bool:g_launchChain[MAX_PLAYERS + 1]
new bool:g_air[MAX_PLAYERS + 1] // flying from a long jump
new Float:g_landAt[MAX_PLAYERS + 1] // landing time of the last long jump, 0 = none to chain
new Float:g_ready[MAX_PLAYERS + 1] // the cooldown ends
new g_jumps[MAX_PLAYERS + 1], g_chains[MAX_PLAYERS + 1]
new Float:g_lastSpeed[MAX_PLAYERS + 1]
public plugin_precache()
{
precache_sound(SND_JUMP)
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_ljcombo.txt")
g_cvEnable = create_cvar("olds_lj_enable", "1", FCVAR_NONE, "1 = long jumps on", true, 0.0, true, 1.0)
g_cvForce = create_cvar("olds_lj_force", "560", FCVAR_NONE, "Horizontal speed a long jump gives", true, 0.0, true, 2000.0)
g_cvCooldown = create_cvar("olds_lj_cooldown", "1.5", FCVAR_NONE, "Seconds between long jumps that are not chained", true, 0.0, true, 30.0)
g_cvWindow = create_cvar("olds_lj_window", "0.2", FCVAR_NONE, "Seconds after a long-jump landing in which the next one chains", true, 0.0, true, 2.0)
g_cvCap = create_cvar("olds_lj_cap", "750", FCVAR_NONE, "Highest horizontal speed of a chain", true, 100.0, true, 3000.0)
AutoExecConfig(true, "olds_ljcombo")
RegisterHookChain(RG_CBasePlayer_PreThink, "on_prethink_pre", false)
RegisterHookChain(RG_CBasePlayer_PostThink, "on_postthink_pre", false)
RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
register_clcmd("+ljump", "cmd_hold")
register_clcmd("-ljump", "cmd_release")
register_concmd("amx_lj_status", "cmd_status", ADMIN_KICK, "- long jumps per player")
}
public client_putinserver(id)
{
g_hold[id] = false
reset_flight(id)
g_ready[id] = 0.0
g_jumps[id] = 0
g_chains[id] = 0
g_lastSpeed[id] = 0.0
}
reset_flight(id)
{
g_launch[id] = false
g_air[id] = false
g_landAt[id] = 0.0
}
public on_spawn_post(id)
{
reset_flight(id)
}
public on_killed_post(victim, attacker, gib)
{
// Nothing carries over a death (a trigger_hurt in mid-flight included).
reset_flight(victim)
g_hold[victim] = false
}
/* 0 = no long jump now; 1 = a fresh one; 2 = a chained one. */
lj_kind(id)
{
if (!get_pcvar_num(g_cvEnable) || !is_user_alive(id))
return 0
new movetype = get_entvar(id, var_movetype)
if (movetype == MOVETYPE_FLY || movetype == MOVETYPE_NOCLIP || get_entvar(id, var_waterlevel) >= 2)
return 0
new Float:now = get_gametime()
if (g_landAt[id] > 0.0 && now - g_landAt[id] <= get_pcvar_float(g_cvWindow))
return 2
if (now < g_ready[id])
return 0
return 1
}
apply_lj(id, bool:chain)
{
if (!is_user_alive(id))
return
new Float:angles[3], Float:velocity[3]
get_entvar(id, var_v_angle, angles)
get_entvar(id, var_velocity, velocity)
new Float:force = get_pcvar_float(g_cvForce)
new Float:vx = force * floatcos(angles[1], degrees), Float:vy = force * floatsin(angles[1], degrees)
if (chain)
{
vx += velocity[0]
vy += velocity[1]
}
new Float:speed = floatsqroot(vx * vx + vy * vy)
new Float:cap = get_pcvar_float(g_cvCap)
if (speed > cap)
{
vx = vx / speed * cap
vy = vy / speed * cap
speed = cap
}
velocity[0] = vx
velocity[1] = vy
velocity[2] = VERTICAL_PUSH
set_entvar(id, var_velocity, velocity)
set_entvar(id, var_flags, get_entvar(id, var_flags) & ~FL_ONGROUND)
new Float:now = get_gametime()
g_air[id] = true
g_landAt[id] = 0.0
g_ready[id] = now + get_pcvar_float(g_cvCooldown)
g_jumps[id]++
if (chain)
g_chains[id]++
g_lastSpeed[id] = speed
emit_sound(id, CHAN_BODY, SND_JUMP, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
}
public on_prethink_pre(id)
{
if (!is_user_alive(id))
return HC_CONTINUE
new bool:ground = (get_entvar(id, var_flags) & FL_ONGROUND) != 0
if (!ground)
return HC_CONTINUE
if (g_air[id])
{
// Landed from a long jump: the chain window opens.
g_air[id] = false
g_landAt[id] = get_gametime()
emit_sound(id, CHAN_BODY, SND_JUMP, 0.8, ATTN_NORM, 0, 80)
}
new buttons = get_entvar(id, var_button), old = get_entvar(id, var_oldbuttons)
if ((buttons & IN_DUCK) && (buttons & IN_JUMP) && !(old & IN_JUMP))
{
new kind = lj_kind(id)
if (kind)
{
// The game's own jump runs first; the long jump replaces its speed in PostThink.
g_launch[id] = true
g_launchChain[id] = kind == 2
}
}
else if (g_hold[id])
{
new kind = lj_kind(id)
if (kind)
apply_lj(id, kind == 2)
}
return HC_CONTINUE
}
public on_postthink_pre(id)
{
if (!g_launch[id])
return HC_CONTINUE
g_launch[id] = false
apply_lj(id, g_launchChain[id])
return HC_CONTINUE
}
public cmd_hold(id)
{
g_hold[id] = true
if (is_user_alive(id) && (get_entvar(id, var_flags) & FL_ONGROUND))
{
new kind = lj_kind(id)
if (kind)
apply_lj(id, kind == 2)
else if (get_pcvar_num(g_cvEnable) && get_gametime() < g_ready[id])
client_print(id, print_center, "%L", id, "LJ_COOLDOWN")
}
return PLUGIN_HANDLED
}
public cmd_release(id)
{
g_hold[id] = false
return PLUGIN_HANDLED
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new name[32]
for (new i = 1; i <= MaxClients; i++)
{
if (!is_user_connected(i))
continue
get_user_name(i, name, charsmax(name))
console_print(id, "[LJ] %s: %d long jumps, %d chained, last speed %.0f", name, g_jumps[i], g_chains[i], g_lastSpeed[i])
}
return PLUGIN_HANDLED
}