Skip to content
View in the app

A better way to browse. Learn more.

Learn more

multi-jump-ability/addons/amxmodx/scripting/olds_multijump.sma

olds_multijump.sma
189 lines · 5.3 KB · Pawn (AMX Mod X)
Raw
/*
 * Multi-Jump Ability (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/>.
 *
 * Extra jumps in the air, for everybody (or players with a flag) or as a rune
 * ability handed out with the olds_mj_give native.
 */
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN  "Multi-Jump Ability"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

#define MAX_JUMPS 10
#define NO_RUNE   -1

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

new g_cvMax, g_cvHeight, g_cvDecay, g_cvFlag
new g_used[MAX_PLAYERS + 1]
new g_rune[MAX_PLAYERS + 1]
new g_total[MAX_PLAYERS + 1]

public plugin_natives()
{
    register_library("olds_multijump")
    register_native("olds_mj_give", "native_give")
    register_native("olds_mj_get", "native_get")
}

public plugin_precache()
{
    precache_sound(JUMP_SOUND)
}

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

    g_cvMax = create_cvar("olds_mj_max", "2", FCVAR_NONE, "Extra air jumps per airtime", true, 0.0, true, float(MAX_JUMPS))
    g_cvHeight = create_cvar("olds_mj_height", "268", FCVAR_NONE, "Upward speed of the first extra jump", true, 50.0, true, 1000.0)
    g_cvDecay = create_cvar("olds_mj_decay", "0.9", FCVAR_NONE, "Each further extra jump gets this share of the one before", true, 0.1, true, 1.0)
    g_cvFlag = create_cvar("olds_mj_flag", "", FCVAR_NONE, "Admin flag needed for multi-jump (empty = everybody)")
    AutoExecConfig(true, "olds_multijump")

    register_forward(FM_PlayerPreThink, "fw_prethink")
    RegisterHam(Ham_Spawn, "player", "fw_spawn_post", 1)
    RegisterHam(Ham_Killed, "player", "fw_killed_post", 1)
    register_concmd("amx_multijump", "cmd_state", ADMIN_SLAY, "<player> - shows a player's multi-jump state")
}

public client_putinserver(id)
{
    g_used[id] = 0
    g_rune[id] = NO_RUNE
    g_total[id] = 0
}

public client_disconnected(id)
{
    g_used[id] = 0
    g_rune[id] = NO_RUNE
    g_total[id] = 0
}

public fw_spawn_post(id)
{
    if (is_user_alive(id))
        g_used[id] = 0
    return HAM_IGNORED
}

public fw_killed_post(victim, attacker, shouldgib)
{
    if (victim >= 1 && victim <= MaxClients)
    {
        g_used[victim] = 0
        g_rune[victim] = NO_RUNE
    }
    return HAM_IGNORED
}

allowed_jumps(id)
{
    if (g_rune[id] != NO_RUNE)
        return g_rune[id]
    new flag[24]
    get_pcvar_string(g_cvFlag, flag, charsmax(flag))
    trim(flag)
    if (flag[0] && !(get_user_flags(id) & read_flags(flag)))
        return 0
    return clamp(get_pcvar_num(g_cvMax), 0, MAX_JUMPS)
}

public fw_prethink(id)
{
    if (!is_user_alive(id))
        return FMRES_IGNORED

    // Ground, a ladder or deep water start a new airtime.
    if ((pev(id, pev_flags) & FL_ONGROUND) || pev(id, pev_movetype) == MOVETYPE_FLY || pev(id, pev_waterlevel) >= 2)
    {
        g_used[id] = 0
        return FMRES_IGNORED
    }

    // A fresh press only: held jump is not pressed again.
    if (!(pev(id, pev_button) & IN_JUMP) || (pev(id, pev_oldbuttons) & IN_JUMP))
        return FMRES_IGNORED

    if (g_used[id] >= allowed_jumps(id))
        return FMRES_IGNORED

    new Float:power = get_pcvar_float(g_cvHeight)
    new Float:decay = floatclamp(get_pcvar_float(g_cvDecay), 0.1, 1.0)
    for (new i = 0; i < g_used[id]; i++)
        power *= decay

    new Float:velocity[3]
    pev(id, pev_velocity, velocity)
    velocity[2] = power
    set_pev(id, pev_velocity, velocity)
    // The upward kick cancels the fall so far: no fall damage carried over.
    set_ent_data_float(id, "CBasePlayer", "m_flFallVelocity", 0.0)
    emit_sound(id, CHAN_BODY, JUMP_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    g_used[id]++
    g_total[id]++
    return FMRES_IGNORED
}

public cmd_state(id, level, cid)
{
    if (!cmd_access(id, level, cid, 2))
        return PLUGIN_HANDLED
    new arg[32]
    read_argv(1, arg, charsmax(arg))
    new target = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
    if (!target)
        return PLUGIN_HANDLED
    new name[32]
    get_user_name(target, name, charsmax(name))
    console_print(id, "%L", id, "MJ_STATE", name, allowed_jumps(target), g_used[target], g_rune[target], g_total[target])
    return PLUGIN_HANDLED
}

public native_give(plugin, params)
{
    if (params < 2)
        return 0
    new id = get_param(1)
    new jumps = get_param(2)
    if (id < 1 || id > MaxClients || !is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "olds_mj_give: invalid player %d", id)
        return 0
    }
    if (jumps < NO_RUNE || jumps > MAX_JUMPS)
    {
        log_error(AMX_ERR_NATIVE, "olds_mj_give: jumps %d out of range (-1..%d)", jumps, MAX_JUMPS)
        return 0
    }
    g_rune[id] = jumps
    if (jumps > 0)
        client_print_color(id, print_team_default, "%L", id, "MJ_GOT", jumps)
    return 1
}

public native_get(plugin, params)
{
    if (params < 1)
        return 0
    new id = get_param(1)
    if (id < 1 || id > MaxClients || !is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "olds_mj_get: invalid player %d", id)
        return 0
    }
    return allowed_jumps(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.