Promover servidor
csb-no-fall-damage / addons / amxmodx / scripting / csb_no_fall_damage.sma
72 lines 2.1 KiB Pawn Raw Permalink History
/*
 * CSB No Fall Damage
 * Copyright (C) 2026 counter-strike-boost.com
 *
 * Cancels or scales fall damage. It hooks Ham_TakeDamage and, when the damage
 * type carries the DMG_FALL bit, either blocks the damage entirely or multiplies
 * it by a cvar. Players holding an exempt admin flag can be left unaffected, and
 * a short sound plays on a blocked hard landing as feedback.
 *
 * 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 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 <https://www.gnu.org/licenses/> for details.
 */

#include <amxmodx>
#include <hamsandwich>
#include <fun>

new const PLUGIN[] = "CSB No Fall Damage"
new const VERSION[] = "1.0.0"
new const AUTHOR[]  = "counter-strike-boost.com"

/* GoldSrc damage bit for falling */
#if !defined DMG_FALL
    #define DMG_FALL (1<<5)
#endif

new g_pEnabled, g_pMult, g_pSound

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

    g_pEnabled = register_cvar("csb_nofall_enabled", "1")
    g_pMult    = register_cvar("csb_nofall_mult", "0.0")
    g_pSound   = register_cvar("csb_nofall_sound", "1")

    RegisterHam(Ham_TakeDamage, "player", "fwTakeDamage")
}

public plugin_precache()
{
    precache_sound("common/wpn_hudoff.wav")
}

public fwTakeDamage(victim, inflictor, attacker, Float:damage, damagebits)
{
    if (!get_pcvar_num(g_pEnabled))
        return HAM_IGNORED

    if (!(damagebits & DMG_FALL))
        return HAM_IGNORED

    if (!is_user_alive(victim))
        return HAM_IGNORED

    new Float:mult = get_pcvar_float(g_pMult)

    if (mult <= 0.0)
    {
        if (get_pcvar_num(g_pSound))
            emit_sound(victim, CHAN_ITEM, "common/wpn_hudoff.wav", 1.0, 0.8, 0, 100)

        return HAM_SUPERCEDE
    }

    SetHamParamFloat(4, damage * mult)
    return HAM_IGNORED
}