Promoveaza serverul
csb-gravity-per-team / addons / amxmodx / scripting / csb_team_gravity.sma
97 lines 2.5 KiB Pawn Raw Permalink History
/*
 * CSB Team Gravity
 * Copyright (C) 2026 counter-strike-boost.com
 *
 * Applies a per-team gravity multiplier with set_user_gravity on every spawn,
 * used by mods like Furien or Hide'n'Seek where one side should jump higher or
 * fall slower than the other. The values are cvars (1.0 = normal), and when the
 * plugin is disabled every player's gravity is reset to normal.
 *
 * 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 <fun>

new const PLUGIN[] = "CSB Team Gravity"
new const VERSION[] = "1.0.0"
new const AUTHOR[]  = "counter-strike-boost.com"

new g_pEnabled, g_pT, g_pCT

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

    g_pEnabled = register_cvar("csb_grav_enabled", "1")
    g_pT       = register_cvar("csb_grav_t", "1.0")
    g_pCT      = register_cvar("csb_grav_ct", "1.0")

    /* ResetHUD fires on every (re)spawn */
    register_event("ResetHUD", "onSpawn", "b")

    register_clcmd("say /gravity", "cmdInfo")
    register_clcmd("say_team /gravity", "cmdInfo")
}

public onSpawn(id)
{
    if (!is_user_alive(id))
        return

    /* small delay so team is fully assigned before we read it */
    set_task(0.1, "taskApply", id)
}

public taskApply(id)
{
    if (is_user_alive(id))
        applyGravity(id)
}

applyGravity(id)
{
    if (!get_pcvar_num(g_pEnabled))
    {
        set_user_gravity(id, 1.0)
        return
    }

    new Float:g = 1.0
    new team = get_user_team(id)

    if (team == 1)
        g = get_pcvar_float(g_pT)
    else if (team == 2)
        g = get_pcvar_float(g_pCT)

    if (g <= 0.0)
        g = 1.0

    set_user_gravity(id, g)
}

public cmdInfo(id)
{
    if (!get_pcvar_num(g_pEnabled))
    {
        client_print(id, print_chat, "[CSB] Team gravity is disabled (normal for everyone).")
        return PLUGIN_HANDLED
    }

    new Float:mine = 1.0
    new team = get_user_team(id)

    if (team == 1)
        mine = get_pcvar_float(g_pT)
    else if (team == 2)
        mine = get_pcvar_float(g_pCT)

    client_print(id, print_chat, "[CSB] Your gravity multiplier: %.2f (1.00 = normal).", mine)
    return PLUGIN_HANDLED
}