/*
* Jump Distance Stats (olds.ro) - long jump practice: after each jump the
* jumper (and anyone spectating them) sees the jump type and the distance.
*
* 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 "Jump Distance Stats"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define HULL_WIDTH 32.0 // distance is measured edge to edge, like other jump stats
#define BHOP_WINDOW 0.15 // ground time below this before a jump makes it a bunny hop
#define STANDING_PRE 50.0 // pre-speed below this is a standing jump
#define SAME_HEIGHT 0.5 // landing feet within this of take-off feet
#define OBS_CHASE_LOCKED 1
#define OBS_CHASE_FREE 2
#define OBS_IN_EYE 4
enum
{
JUMP_STANDING,
JUMP_LONG,
JUMP_DUCK,
JUMP_BHOP
}
new const JUMP_NAME[][] = { "Standing Long Jump", "Long Jump", "Duck Jump", "Bunny Hop" }
new bool:g_on[MAX_PLAYERS + 1]
new bool:g_inAir[MAX_PLAYERS + 1]
new bool:g_valid[MAX_PLAYERS + 1]
new bool:g_jumped[MAX_PLAYERS + 1] // left the ground going up (not a drop)
new Float:g_groundOrigin[MAX_PLAYERS + 1][3]
new Float:g_groundSpeed[MAX_PLAYERS + 1]
new bool:g_groundDuck[MAX_PLAYERS + 1]
new Float:g_groundSince[MAX_PLAYERS + 1] // when the player last touched down
new Float:g_takeoff[MAX_PLAYERS + 1][3]
new Float:g_takeoffFeet[MAX_PLAYERS + 1]
new Float:g_pre[MAX_PLAYERS + 1]
new Float:g_max[MAX_PLAYERS + 1]
new g_type[MAX_PLAYERS + 1]
new Float:g_lastOrigin[MAX_PLAYERS + 1][3]
new Float:g_lastTime[MAX_PLAYERS + 1]
new g_result[MAX_PLAYERS + 1][96] // last jump, for olds_js_status
new g_cvarMin, g_cvarHud, g_cvarColor
new g_hud
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
g_cvarMin = create_cvar("olds_js_min", "200", FCVAR_NONE, "Shortest jump (units) that is shown", true, 0.0, true, 1000.0)
g_cvarHud = create_cvar("olds_js_hud", "1", FCVAR_NONE, "1 = also show the jump as a HUD line", true, 0.0, true, 1.0)
g_cvarColor = create_cvar("olds_js_color", "1", FCVAR_NONE, "1 = coloured chat, 0 = plain chat", true, 0.0, true, 1.0)
AutoExecConfig(true, "olds_jumpstats")
register_clcmd("say /js", "cmd_toggle")
register_clcmd("say_team /js", "cmd_toggle")
register_concmd("olds_js_status", "cmd_status", ADMIN_CFG, "- last jump of every player")
register_forward(FM_PlayerPreThink, "on_pre_think")
g_hud = CreateHudSyncObj()
}
public client_putinserver(id)
{
g_on[id] = true
g_inAir[id] = false
g_valid[id] = false
g_result[id][0] = EOS
}
public client_disconnected(id)
{
g_on[id] = false
g_inAir[id] = false
}
public cmd_toggle(id)
{
g_on[id] = !g_on[id]
if (g_on[id])
client_print(id, print_chat, "[JS] Jump stats on.")
else
client_print(id, print_chat, "[JS] Jump stats off (only for you). Type /js to turn them on.")
return PLUGIN_HANDLED
}
/* ---------- tracking ---------- */
public on_pre_think(id)
{
if (!is_user_alive(id))
{
g_inAir[id] = false
return FMRES_IGNORED
}
new flags = pev(id, pev_flags)
new Float:origin[3], Float:velocity[3], Float:now = get_gametime()
pev(id, pev_origin, origin)
pev(id, pev_velocity, velocity)
new Float:speed = floatsqroot(velocity[0] * velocity[0] + velocity[1] * velocity[1])
new bool:ground = (flags & FL_ONGROUND) != 0
if (!g_inAir[id])
{
if (ground)
{
g_groundOrigin[id] = origin
g_groundSpeed[id] = speed
g_groundDuck[id] = (flags & FL_DUCKING) != 0
}
else
take_off(id, velocity[2], now)
}
else
{
// A teleport, ladder, water or noclip spoils the jump.
new Float:dt = now - g_lastTime[id]
new Float:moved = get_distance_f(origin, g_lastOrigin[id])
new Float:limit = (speed + floatabs(velocity[2])) * floatmax(dt, 0.001) * 2.0 + 64.0
if (moved > limit || pev(id, pev_movetype) != MOVETYPE_WALK || pev(id, pev_waterlevel) >= 2)
g_valid[id] = false
if (speed > g_max[id])
g_max[id] = speed
if (ground)
land(id, origin, flags, now)
}
g_lastOrigin[id] = origin
g_lastTime[id] = now
return FMRES_IGNORED
}
take_off(id, Float:upward, Float:now)
{
g_inAir[id] = true
g_jumped[id] = upward > 0.0
g_valid[id] = g_jumped[id] && pev(id, pev_movetype) == MOVETYPE_WALK && pev(id, pev_waterlevel) < 2
g_takeoff[id] = g_groundOrigin[id]
g_takeoffFeet[id] = feet_z(g_groundOrigin[id][2], g_groundDuck[id])
g_pre[id] = g_groundSpeed[id]
g_max[id] = g_groundSpeed[id]
if (now - g_groundSince[id] < BHOP_WINDOW)
g_type[id] = JUMP_BHOP
else if (g_pre[id] < STANDING_PRE)
g_type[id] = JUMP_STANDING
else if (g_groundDuck[id])
g_type[id] = JUMP_DUCK
else
g_type[id] = JUMP_LONG
}
Float:feet_z(Float:z, bool:ducked)
{
return ducked ? z - 18.0 : z - 36.0
}
land(id, const Float:origin[3], flags, Float:now)
{
g_inAir[id] = false
g_groundSince[id] = now
g_groundOrigin[id] = origin
g_groundDuck[id] = (flags & FL_DUCKING) != 0
if (!g_jumped[id])
return // a drop off a ledge, not a jump
new Float:dx = origin[0] - g_takeoff[id][0], Float:dy = origin[1] - g_takeoff[id][1]
new Float:distance = floatsqroot(dx * dx + dy * dy) + HULL_WIDTH
new Float:dz = feet_z(origin[2], g_groundDuck[id]) - g_takeoffFeet[id]
if (!g_valid[id])
{
formatex(g_result[id], charsmax(g_result[]), "not counted: teleport, ladder, water or noclip (%.2f units)", distance)
return
}
if (floatabs(dz) > SAME_HEIGHT)
{
if (dz > 0.0)
formatex(g_result[id], charsmax(g_result[]), "not counted: landed %.0f units higher (%.2f units)", dz, distance)
else
formatex(g_result[id], charsmax(g_result[]), "not counted: landed %.0f units lower (%.2f units)", -dz, distance)
return
}
if (distance < get_pcvar_float(g_cvarMin))
{
formatex(g_result[id], charsmax(g_result[]), "%s %.2f units: below olds_js_min, not shown", JUMP_NAME[g_type[id]], distance)
return
}
new viewers = show_jump(id, distance)
formatex(g_result[id], charsmax(g_result[]), "%s %.2f units (pre %.0f, max %.0f), shown to %d",
JUMP_NAME[g_type[id]], distance, g_pre[id], g_max[id], viewers)
}
/* ---------- output ---------- */
show_jump(id, Float:distance)
{
new name[32], viewers
get_user_name(id, name, charsmax(name))
new bool:color = get_pcvar_num(g_cvarColor) != 0
new bool:hud = get_pcvar_num(g_cvarHud) != 0
if (hud)
set_hudmessage(255, 200, 60, -1.0, 0.70, 0, 0.0, 2.5, 0.05, 0.3, -1)
for (new viewer = 1; viewer <= MaxClients; viewer++)
{
if (!g_on[viewer] || !is_user_connected(viewer) || !watches(viewer, id))
continue
viewers++
if (color)
{
if (viewer == id)
client_print_color(viewer, id, "^4[JS]^1 %s: ^3%.2f^1 units (pre %.0f, max %.0f)", JUMP_NAME[g_type[id]], distance, g_pre[id], g_max[id])
else
client_print_color(viewer, id, "^4[JS]^3 %s^1 - %s: ^3%.2f^1 units (pre %.0f, max %.0f)", name, JUMP_NAME[g_type[id]], distance, g_pre[id], g_max[id])
}
else
{
if (viewer == id)
client_print(viewer, print_chat, "[JS] %s: %.2f units (pre %.0f, max %.0f)", JUMP_NAME[g_type[id]], distance, g_pre[id], g_max[id])
else
client_print(viewer, print_chat, "[JS] %s - %s: %.2f units (pre %.0f, max %.0f)", name, JUMP_NAME[g_type[id]], distance, g_pre[id], g_max[id])
}
if (hud)
ShowSyncHudMsg(viewer, g_hud, "%s^n%.2f units", JUMP_NAME[g_type[id]], distance)
}
return viewers
}
bool:watches(viewer, jumper)
{
if (viewer == jumper)
return true
if (is_user_alive(viewer))
return false
new mode = pev(viewer, pev_iuser1)
return (mode == OBS_CHASE_LOCKED || mode == OBS_CHASE_FREE || mode == OBS_IN_EYE) && pev(viewer, pev_iuser2) == jumper
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[JS] olds_js_min %.0f, olds_js_hud %d, olds_js_color %d", get_pcvar_float(g_cvarMin), get_pcvar_num(g_cvarHud), get_pcvar_num(g_cvarColor))
new name[32]
for (new player = 1; player <= MaxClients; player++)
{
if (!is_user_connected(player))
continue
get_user_name(player, name, charsmax(name))
new state_text[4], last[96]
if (g_on[player])
copy(state_text, charsmax(state_text), "on")
else
copy(state_text, charsmax(state_text), "off")
if (g_result[player][0])
copy(last, charsmax(last), g_result[player])
else
copy(last, charsmax(last), "no jump yet")
console_print(id, " %s (%s): %s", name, state_text, last)
}
return PLUGIN_HANDLED
}