/*
* Purchasable Long Jump Module (olds.ro workshop card LIB-0974)
*
* Long Jump: players buy a long jump module for the round. With it, the
* +ljump key throws them far forward from the ground, with a cooldown.
* say /longjump buy the module (olds_ljbuy_price)
* bind <key> +ljump the long jump key
*
* Cvars
* olds_ljbuy_price 4000 price
* olds_ljbuy_force 650 forward speed of the jump
* olds_ljbuy_cd 5 seconds between jumps
*
* amx_ljbuy_status (ADMIN_KICK) owners, jumps, cooldowns, money
*
* Money is taken with rg_add_account. FM_CmdStart applies the jump on a fresh
* +ljump press when the player stands on the ground (pev_velocity, with the
* stock player/pl_jump2.wav); in the air nothing happens; during the cooldown
* the seconds left are shown. The module goes at round start
* (RG_CSGameRules_RestartRound) and at death (RG_CBasePlayer_Killed).
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>
#define PLUGIN "Purchasable Long Jump Module"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
new const JUMP_SOUND[] = "player/pl_jump2.wav"
const Float:LIFT = 300.0
const Float:DENY_EVERY = 1.0
new g_price, Float:g_force, Float:g_cd
new bool:g_owned[MAX_PLAYERS + 1]
new bool:g_held[MAX_PLAYERS + 1]
new bool:g_wasHeld[MAX_PLAYERS + 1]
new Float:g_ready[MAX_PLAYERS + 1]
new Float:g_nextDeny[MAX_PLAYERS + 1]
new g_jumps[MAX_PLAYERS + 1]
public plugin_precache()
{
precache_sound(JUMP_SOUND)
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_ljbuy.txt")
bind_pcvar_num(create_cvar("olds_ljbuy_price", "4000", FCVAR_NONE,
"Price of the long jump module.", true, 0.0, true, 16000.0), g_price)
bind_pcvar_float(create_cvar("olds_ljbuy_force", "650", FCVAR_NONE,
"Forward speed of the long jump.", true, 100.0, true, 2000.0), g_force)
bind_pcvar_float(create_cvar("olds_ljbuy_cd", "5", FCVAR_NONE,
"Seconds between long jumps.", true, 0.0, true, 120.0), g_cd)
AutoExecConfig(true, "olds_ljbuy")
register_clcmd("say /longjump", "cmd_buy")
register_clcmd("say_team /longjump", "cmd_buy")
register_clcmd("+ljump", "cmd_down")
register_clcmd("-ljump", "cmd_up")
register_forward(FM_CmdStart, "on_cmd_start")
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
register_concmd("amx_ljbuy_status", "cmd_status", ADMIN_KICK, "- long jump module owners")
}
public client_disconnected(id)
{
reset(id)
}
reset(id)
{
g_owned[id] = false
g_held[id] = false
g_wasHeld[id] = false
g_ready[id] = 0.0
g_nextDeny[id] = 0.0
}
public on_restart_round_pre()
{
for (new id = 1; id <= MaxClients; id++)
{
reset(id)
g_jumps[id] = 0
}
}
public on_killed_post(victim)
{
if (1 <= victim <= MaxClients && g_owned[victim])
reset(victim)
}
/* ---------- buying ---------- */
public cmd_buy(id)
{
if (!is_user_alive(id))
{
client_print_color(id, print_team_default, "^4[LJ]^1 %L", id, "LJBUY_DEAD")
return PLUGIN_HANDLED
}
if (g_owned[id])
{
client_print_color(id, print_team_default, "^4[LJ]^1 %L", id, "LJBUY_OWNED")
return PLUGIN_HANDLED
}
new money = get_member(id, m_iAccount)
if (money < g_price)
{
client_print_color(id, print_team_default, "^4[LJ]^1 %L", id, "LJBUY_POOR", g_price, money)
return PLUGIN_HANDLED
}
rg_add_account(id, -g_price, AS_ADD)
g_owned[id] = true
g_ready[id] = 0.0
client_print_color(id, print_team_default, "^4[LJ]^1 %L", id, "LJBUY_BOUGHT", g_price, floatround(g_cd))
return PLUGIN_HANDLED
}
public cmd_down(id)
{
g_held[id] = true
return PLUGIN_HANDLED
}
public cmd_up(id)
{
g_held[id] = false
return PLUGIN_HANDLED
}
/* ---------- the jump ---------- */
public on_cmd_start(id, uc, seed)
{
if (!(1 <= id <= MaxClients))
return FMRES_IGNORED
new bool:pressed = g_held[id] && !g_wasHeld[id]
g_wasHeld[id] = g_held[id]
if (!pressed || !g_owned[id] || !is_user_alive(id))
return FMRES_IGNORED
new Float:now = get_gametime()
if (now < g_ready[id])
{
if (now >= g_nextDeny[id])
{
g_nextDeny[id] = now + DENY_EVERY
client_print_color(id, print_team_default, "^4[LJ]^1 %L", id, "LJBUY_WAIT", g_ready[id] - now)
}
return FMRES_IGNORED
}
if (!(pev(id, pev_flags) & FL_ONGROUND))
return FMRES_IGNORED
new Float:angles[3], Float:dir[3], Float:velocity[3]
get_uc(uc, UC_ViewAngles, angles)
angles[0] = 0.0
angle_vector(angles, ANGLEVECTOR_FORWARD, dir)
velocity[0] = dir[0] * g_force
velocity[1] = dir[1] * g_force
velocity[2] = LIFT
set_pev(id, pev_velocity, velocity)
emit_sound(id, CHAN_BODY, JUMP_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
g_ready[id] = now + g_cd
g_jumps[id]++
return FMRES_IGNORED
}
/* ---------- status ---------- */
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[LJ] price %d, force %.0f, cooldown %.1f s", g_price, g_force, g_cd)
new name[MAX_NAME_LENGTH], Float:velocity[3], Float:now = get_gametime()
for (new p = 1; p <= MaxClients; p++)
{
if (!is_user_connected(p))
continue
get_user_name(p, name, charsmax(name))
pev(p, pev_velocity, velocity)
console_print(id, "[LJ] %s: owned %d, alive %d, money %d, jumps %d, cooldown %.1f, speed %.0f, height speed %.0f",
name, g_owned[p], is_user_alive(p), get_member(p, m_iAccount), g_jumps[p], floatmax(0.0, g_ready[p] - now),
floatsqroot(velocity[0] * velocity[0] + velocity[1] * velocity[1]), velocity[2])
}
return PLUGIN_HANDLED
}