Skip to content
View in the app

A better way to browse. Learn more.

Learn more

long-jump-enabler/addons/amxmodx/scripting/olds_lje.sma

olds_lje.sma
255 lines · 7.6 KB · Pawn (AMX Mod X)
Raw
/*
 * Long Jump Enabler (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/>.
 *
 * Gives everyone the long jump on a key: "+ljump" (register_clcmd) asks for one, and at the
 * start of the player's next move (FM_CmdStart) a player standing on the ground is thrown
 * forward along their view (560 u/s) and up (300 u/s). Pressing it in the air does nothing.
 * With olds_lje_auto 1 the key olds_lje_key is bound to +ljump when a player joins
 * (client_cmd "bind"); with 0 nothing is bound and the player is told how to bind it. Either
 * way the message is shown once per connection. olds_lje_reset 1 sends "unbind" on leave.
 * olds_lje_gravity scales the player's gravity during the jump only.
 *
 * Note: newer Steam clients may ignore bind commands from servers (cl_filterstuffcmd); the
 * join message then tells the player the command to type.
 *
 * Cvars: olds_lje_auto 1, olds_lje_key "v", olds_lje_gravity 1.0 (0.2-2), olds_lje_reset 0
 */

#include <amxmodx>
#include <fakemeta>

#pragma semicolon 0

#define PLUGIN  "Long Jump Enabler"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

#define JUMP_FORWARD 560.0
#define JUMP_UP      300.0
#define COOLDOWN     0.5
#define TASK_NOTE    8800
#define TASK_FALLBACK 8840
#define TASK_LAND    8880

new const JUMP_SOUND[] = "player/pl_jump2.wav"

new g_auto
new g_key[16]
new Float:g_gravity
new g_reset

new bool:g_want[MAX_PLAYERS + 1]
new bool:g_inJump[MAX_PLAYERS + 1]
new Float:g_oldGravity[MAX_PLAYERS + 1]
new Float:g_takeoff[MAX_PLAYERS + 1][3]
new Float:g_nextJump[MAX_PLAYERS + 1]
new g_boundKey[MAX_PLAYERS + 1][16]
new Float:g_lastDistance[MAX_PLAYERS + 1]

public plugin_precache()
{
    precache_sound(JUMP_SOUND)
}

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

    bind_pcvar_num(create_cvar("olds_lje_auto", "1", FCVAR_NONE,
        "1 = bind olds_lje_key to +ljump when a player joins", true, 0.0, true, 1.0), g_auto)
    bind_pcvar_string(create_cvar("olds_lje_key", "v", FCVAR_NONE,
        "Key bound to +ljump (letters, digits, or a key name such as mouse4)"), g_key, charsmax(g_key))
    bind_pcvar_float(create_cvar("olds_lje_gravity", "1.0", FCVAR_NONE,
        "Gravity during a long jump (1 = normal)", true, 0.2, true, 2.0), g_gravity)
    bind_pcvar_num(create_cvar("olds_lje_reset", "0", FCVAR_NONE,
        "1 = unbind the key when the player leaves", true, 0.0, true, 1.0), g_reset)

    register_clcmd("+ljump", "cmd_ljump_down")
    register_clcmd("-ljump", "cmd_ljump_up")
    register_forward(FM_CmdStart, "fw_cmdstart")
    set_task(0.1, "task_land", TASK_LAND, _, _, "b")

    register_dictionary("olds_lje.txt")
    AutoExecConfig(true, "olds_lje")
}

/* Only plain key names: letters, digits and a few safe names; never anything with spaces,
 * quotes or ; that could run another command on the client. */
bool:safe_key(const key[])
{
    new len = strlen(key)
    if (len < 1 || len > 10)
        return false
    for (new i = 0; i < len; i++)
    {
        if (!isalnum(key[i]))
            return false
    }
    return true
}

public client_putinserver(id)
{
    g_want[id] = false
    g_inJump[id] = false
    g_nextJump[id] = 0.0
    g_lastDistance[id] = 0.0
    g_boundKey[id][0] = EOS
    if (is_user_bot(id) || is_user_hltv(id))
        return
    if (g_auto && safe_key(g_key))
    {
        client_cmd(id, "bind %s +ljump", g_key)
        copy(g_boundKey[id], charsmax(g_boundKey[]), g_key)
    }
    else if (g_auto)
        log_amx("olds_lje_key ^"%s^" is not a plain key name: nothing was bound", g_key)
    set_task(4.0, "task_note", TASK_NOTE + id)
}

public task_note(taskid)
{
    new id = taskid - TASK_NOTE
    if (!is_user_connected(id))
        return
    if (g_boundKey[id][0])
        client_print_color(id, print_team_default, "%L", id, "LJE_BOUND", g_boundKey[id], g_boundKey[id])
    else
        client_print_color(id, print_team_default, "%L", id, "LJE_HOWTO")
}

public client_disconnected(id)
{
    remove_task(TASK_NOTE + id)
    remove_task(TASK_FALLBACK + id)
    if (g_reset && g_boundKey[id][0] && is_user_connected(id))
        client_cmd(id, "unbind %s", g_boundKey[id])
    end_jump(id)
    g_boundKey[id][0] = EOS
    g_want[id] = false
}

public cmd_ljump_down(id)
{
    if (!is_user_alive(id))
        return PLUGIN_HANDLED
    g_want[id] = true
    /* Players move every frame; this is only for clients that send no moves (bots). */
    remove_task(TASK_FALLBACK + id)
    set_task(0.1, "task_fallback", TASK_FALLBACK + id)
    return PLUGIN_HANDLED
}

public cmd_ljump_up(id)
{
    return PLUGIN_HANDLED
}

public fw_cmdstart(id, uc, seed)
{
    if (g_want[id])
        try_jump(id)
    return FMRES_IGNORED
}

public task_fallback(taskid)
{
    new id = taskid - TASK_FALLBACK
    if (g_want[id])
        try_jump(id)
}

try_jump(id)
{
    g_want[id] = false
    remove_task(TASK_FALLBACK + id)
    if (!is_user_alive(id) || g_inJump[id])
        return
    /* On the ground only: a press in the air does nothing. */
    if (!(pev(id, pev_flags) & FL_ONGROUND) || pev(id, pev_waterlevel) >= 2)
        return
    new Float:now = get_gametime()
    if (now < g_nextJump[id])
        return
    g_nextJump[id] = now + COOLDOWN

    new Float:angles[3], Float:forward_[3], Float:vel[3]
    pev(id, pev_v_angle, angles)
    angles[0] = 0.0
    angles[2] = 0.0
    engfunc(EngFunc_MakeVectors, angles)
    global_get(glb_v_forward, forward_)
    vel[0] = forward_[0] * JUMP_FORWARD
    vel[1] = forward_[1] * JUMP_FORWARD
    vel[2] = JUMP_UP
    set_pev(id, pev_velocity, vel)
    set_pev(id, pev_flags, pev(id, pev_flags) & ~FL_ONGROUND)

    new Float:gravity
    pev(id, pev_gravity, gravity)
    g_oldGravity[id] = gravity
    if (g_gravity != 1.0)
        set_pev(id, pev_gravity, gravity * floatclamp(g_gravity, 0.2, 2.0))
    pev(id, pev_origin, g_takeoff[id])
    g_inJump[id] = true
    emit_sound(id, CHAN_BODY, JUMP_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
}

end_jump(id)
{
    if (!g_inJump[id])
        return
    g_inJump[id] = false
    if (is_user_alive(id))
        set_pev(id, pev_gravity, g_oldGravity[id])
}

public task_land()
{
    new Float:now = get_gametime()
    for (new id = 1; id <= MaxClients; id++)
    {
        if (!g_inJump[id])
            continue
        if (!is_user_alive(id))
        {
            end_jump(id)
            continue
        }
        /* Give the jump a moment to leave the ground before looking for the landing. */
        if (now < g_nextJump[id] - COOLDOWN + 0.15)
            continue
        if (pev(id, pev_flags) & FL_ONGROUND || pev(id, pev_waterlevel) >= 2)
        {
            new Float:origin[3]
            pev(id, pev_origin, origin)
            origin[2] = g_takeoff[id][2]
            g_lastDistance[id] = get_distance_f(origin, g_takeoff[id])
            end_jump(id)
        }
    }
}

public plugin_natives()
{
    register_library("olds_lje")
    register_native("olds_lje_last_distance", "native_last_distance")
}

/* Float:olds_lje_last_distance(id): horizontal length of the player's last long jump. */
public Float:native_last_distance(plugin, params)
{
    new id = get_param(1)
    if (id < 1 || id > MaxClients)
        return 0.0
    return g_lastDistance[id]
}

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.