Skip to content
View in the app

A better way to browse. Learn more.

Learn more

juggernaut-rage-meter/addons/amxmodx/scripting/olds_jrage.sma

olds_jrage.sma
378 lines · 11.3 KB · Pawn (AMX Mod X)
Raw
/*
 * Juggernaut Rage Meter (olds.ro) - Juggernaut add-on
 * 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. It is distributed WITHOUT ANY WARRANTY; see
 * <https://www.gnu.org/licenses/>.
 *
 * The juggernaut's rage meter (0-100) fills by damage taken / olds_jrage_div
 * (RG_CBasePlayer_TakeDamage post). With a full meter the stomp (console
 * command olds_stomp, or impulse 100 - the flashlight key) knocks every
 * enemy within olds_jrage_radius away and halves their speed for
 * olds_jrage_slow seconds, then empties the meter. A partial meter only
 * shows its percentage. The juggernaut sees the meter on the HUD; everyone
 * sees a bar above their head (TE_PLAYERATTACHMENT marker and a beam whose
 * length is the meter), refreshed twice a second.
 *
 * Who is the juggernaut: a core may say so with the native
 * olds_jrage_set_juggernaut(id) (include/olds_jrage.inc). Without that, with
 * olds_jrage_detect 1, it is the only player on the terrorist team while
 * counter-terrorists play (the Juggernaut Mode layout). A new juggernaut
 * starts with an empty meter.
 */
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>

#define PLUGIN  "Juggernaut Rage Meter"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

#define TASK_TICK  54600
#define TASK_SLOW  54610
#define REFRESH    0.5
#define STOMP_PUSH 520.0
#define STOMP_LIFT 260.0

new const RING_SPRITE[] = "sprites/shockwave.spr"
new const BAR_SPRITE[] = "sprites/laserbeam.spr"
new const STOMP_SOUND[] = "weapons/explode3.wav"

new g_cvDiv, g_cvRadius, g_cvSlow, g_cvDetect
new g_ring, g_bar, g_hud

new g_jugg                                   // the juggernaut now, 0 = none
new bool:g_byCore                            // named by a core through the native
new Float:g_rage                             // 0.0 - 100.0
new Float:g_slowUntil[MAX_PLAYERS + 1]

public plugin_natives()
{
    register_library("olds_jrage")
    register_native("olds_jrage_set_juggernaut", "native_set_juggernaut")
    register_native("olds_jrage_get", "native_get")
}

public native_set_juggernaut(plugin, params)
{
    new id = get_param(1)
    if (id < 0 || id > MaxClients || (id && !is_user_connected(id)))
    {
        log_error(AMX_ERR_NATIVE, "Invalid player %d", id)
        return 0
    }
    g_byCore = id != 0
    set_juggernaut(id)
    return 1
}

public native_get(plugin, params)
{
    return floatround(g_rage, floatround_floor)
}

public plugin_precache()
{
    g_ring = precache_model(RING_SPRITE)
    g_bar = precache_model(BAR_SPRITE)
    precache_sound(STOMP_SOUND)
}

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

    g_cvDiv = create_cvar("olds_jrage_div", "15", FCVAR_NONE, "Damage taken per rage point", true, 0.1, true, 1000.0)
    g_cvRadius = create_cvar("olds_jrage_radius", "220", FCVAR_NONE, "Stomp radius", true, 32.0, true, 2000.0)
    g_cvSlow = create_cvar("olds_jrage_slow", "1.5", FCVAR_NONE, "Seconds the stomped players are slowed", true, 0.0, true, 30.0)
    g_cvDetect = create_cvar("olds_jrage_detect", "1", FCVAR_NONE, "1 = the lone terrorist is the juggernaut when no core names one", true, 0.0, true, 1.0)
    AutoExecConfig(true, "olds_jrage")

    RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_post", true)
    RegisterHookChain(RG_CBasePlayer_ImpulseCommands, "on_impulse_pre", false)
    RegisterHookChain(RG_CBasePlayer_ResetMaxSpeed, "on_reset_maxspeed_post", true)
    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_post", true)

    register_clcmd("olds_stomp", "cmd_stomp")
    register_concmd("amx_jrage", "cmd_status", ADMIN_KICK, "- shows the juggernaut and the rage meter")

    g_hud = CreateHudSyncObj()
    set_task(REFRESH, "tick", TASK_TICK, _, _, "b")
}

public client_disconnected(id)
{
    remove_task(TASK_SLOW + id)
    g_slowUntil[id] = 0.0
    if (id == g_jugg)
    {
        g_byCore = false
        set_juggernaut(0)
    }
}

set_juggernaut(id)
{
    if (id == g_jugg)
        return
    g_jugg = id
    g_rage = 0.0
    if (id)
    {
        new name[32]
        get_user_name(id, name, charsmax(name))
        log_amx("New juggernaut %s: rage meter empty", name)
    }
}

/* The lone terrorist, when counter-terrorists play too. */
detect()
{
    if (g_byCore || !get_pcvar_num(g_cvDetect))
        return
    new t, cts, lone
    for (new id = 1; id <= MaxClients; id++)
    {
        if (!is_user_connected(id))
            continue
        new TeamName:team = TeamName:get_member(id, m_iTeam)
        if (team == TEAM_TERRORIST)
        {
            t++
            lone = id
        }
        else if (team == TEAM_CT)
            cts++
    }
    if (t == 1 && cts > 0)
        set_juggernaut(lone)
    else
        set_juggernaut(0)
}

public on_restart_round_post()
{
    // Cores pick their juggernaut at the round restart too: look a moment later.
    g_rage = 0.0
    if (!g_byCore)
        set_task(0.3, "detect_task")
}

public detect_task()
{
    detect()
}

public on_take_damage_post(victim, inflictor, attacker, Float:damage, bits)
{
    if (victim != g_jugg || !g_jugg || damage <= 0.0)
        return HC_CONTINUE
    g_rage = floatmin(100.0, g_rage + damage / get_pcvar_float(g_cvDiv))
    return HC_CONTINUE
}

public on_impulse_pre(id)
{
    if (id != g_jugg || get_entvar(id, var_impulse) != 100)
        return HC_CONTINUE
    set_entvar(id, var_impulse, 0)
    stomp(id)
    return HC_CONTINUE
}

public cmd_stomp(id)
{
    if (id == g_jugg)
        stomp(id)
    return PLUGIN_HANDLED
}

stomp(id)
{
    if (!is_user_alive(id))
        return
    if (g_rage < 100.0)
    {
        client_print(id, print_center, "%L", id, "JR_NOT_FULL", floatround(g_rage, floatround_floor))
        return
    }
    g_rage = 0.0
    new Float:origin[3], Float:spot[3], Float:dir[3]
    get_entvar(id, var_origin, origin)
    new Float:radius = get_pcvar_float(g_cvRadius), Float:slow = get_pcvar_float(g_cvSlow)
    new TeamName:mine = TeamName:get_member(id, m_iTeam), hit

    emit_sound(id, CHAN_WEAPON, STOMP_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
    write_byte(TE_BEAMCYLINDER)
    engfunc(EngFunc_WriteCoord, origin[0])
    engfunc(EngFunc_WriteCoord, origin[1])
    engfunc(EngFunc_WriteCoord, origin[2] - 30.0)
    engfunc(EngFunc_WriteCoord, origin[0])
    engfunc(EngFunc_WriteCoord, origin[1])
    engfunc(EngFunc_WriteCoord, origin[2] - 30.0 + radius)
    write_short(g_ring)
    write_byte(0)
    write_byte(0)
    write_byte(5)
    write_byte(30)
    write_byte(0)
    write_byte(255)
    write_byte(80)
    write_byte(30)
    write_byte(220)
    write_byte(0)
    message_end()

    for (new other = 1; other <= MaxClients; other++)
    {
        if (other == id || !is_user_alive(other) || TeamName:get_member(other, m_iTeam) == mine)
            continue
        get_entvar(other, var_origin, spot)
        new Float:d = get_distance_f(origin, spot)
        if (d > radius)
            continue
        new Float:flat = floatsqroot((spot[0] - origin[0]) * (spot[0] - origin[0]) + (spot[1] - origin[1]) * (spot[1] - origin[1]))
        if (flat > 1.0)
        {
            dir[0] = (spot[0] - origin[0]) / flat
            dir[1] = (spot[1] - origin[1]) / flat
        }
        else
        {
            dir[0] = 1.0
            dir[1] = 0.0
        }
        new Float:velocity[3]
        velocity[0] = dir[0] * STOMP_PUSH
        velocity[1] = dir[1] * STOMP_PUSH
        velocity[2] = STOMP_LIFT
        set_entvar(other, var_velocity, velocity)
        if (slow > 0.0)
        {
            g_slowUntil[other] = get_gametime() + slow
            rg_reset_maxspeed(other)
            remove_task(TASK_SLOW + other)
            set_task(slow, "end_slow", TASK_SLOW + other)
        }
        hit++
    }
    new name[32]
    get_user_name(id, name, charsmax(name))
    client_print(id, print_center, "%L", id, "JR_STOMP", hit)
    log_amx("%s stomps: %d enemies within %.0f pushed and slowed %.1f s", name, hit, radius, slow)
}

/* While slowed, every speed reset is halved (rg_set_user_maxspeed does not exist in ReAPI). */
public on_reset_maxspeed_post(id)
{
    if (g_slowUntil[id] <= get_gametime() || !is_user_alive(id))
        return HC_CONTINUE
    new Float:speed = Float:get_entvar(id, var_maxspeed)
    set_entvar(id, var_maxspeed, speed * 0.5)
    return HC_CONTINUE
}

public end_slow(task)
{
    new id = task - TASK_SLOW
    g_slowUntil[id] = 0.0
    if (is_user_alive(id))
        rg_reset_maxspeed(id)
}

public tick()
{
    detect()
    new id = g_jugg
    if (!id || !is_user_alive(id))
        return
    new percent = floatround(g_rage, floatround_floor)
    if (!is_user_bot(id))
    {
        if (percent >= 100)
            set_hudmessage(255, 40, 30, 0.02, 0.85, 0, 0.0, REFRESH + 0.2, 0.0, 0.0, -1)
        else
            set_hudmessage(255, 160, 40, 0.02, 0.85, 0, 0.0, REFRESH + 0.2, 0.0, 0.0, -1)
        if (percent >= 100)
            ShowSyncHudMsg(id, g_hud, "%L", id, "JR_HUD_FULL")
        else
            ShowSyncHudMsg(id, g_hud, "%L", id, "JR_HUD", percent)
    }
    overhead_bar(id, percent)
}

overhead_bar(id, percent)
{
    // The marker rides on the juggernaut's head.
    message_begin(MSG_ALL, SVC_TEMPENTITY)
    write_byte(TE_PLAYERATTACHMENT)
    write_byte(id)
    write_coord(48)
    write_short(g_bar)
    write_short(floatround(REFRESH * 10.0) + 1)
    message_end()

    if (percent <= 0)
        return
    // The bar: a beam across the head, its length the meter.
    new Float:origin[3], Float:angles[3], Float:right[3], Float:start[3], Float:stop[3]
    get_entvar(id, var_origin, origin)
    get_entvar(id, var_angles, angles)
    angles[0] = 0.0
    angle_vector(angles, ANGLEVECTOR_RIGHT, right)
    new Float:width = 40.0 * float(min(percent, 100)) / 100.0
    for (new i = 0; i < 3; i++)
    {
        start[i] = origin[i] - right[i] * 20.0
        stop[i] = start[i] + right[i] * width
    }
    start[2] += 56.0
    stop[2] += 56.0
    new red = 255, green = 200
    if (percent >= 100)
        green = 30
    else if (percent >= 50)
        green = 110
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
    write_byte(TE_BEAMPOINTS)
    engfunc(EngFunc_WriteCoord, start[0])
    engfunc(EngFunc_WriteCoord, start[1])
    engfunc(EngFunc_WriteCoord, start[2])
    engfunc(EngFunc_WriteCoord, stop[0])
    engfunc(EngFunc_WriteCoord, stop[1])
    engfunc(EngFunc_WriteCoord, stop[2])
    write_short(g_bar)
    write_byte(0)
    write_byte(0)
    write_byte(floatround(REFRESH * 10.0) + 1)
    write_byte(30)
    write_byte(0)
    write_byte(red)
    write_byte(green)
    write_byte(30)
    write_byte(220)
    write_byte(0)
    message_end()
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    new name[32]
    copy(name, charsmax(name), "none")
    if (g_jugg && is_user_connected(g_jugg))
        get_user_name(g_jugg, name, charsmax(name))
    new how[24]
    copy(how, charsmax(how), "detected")
    if (g_byCore)
        copy(how, charsmax(how), "named by the core")
    console_print(id, "[Rage] Juggernaut %s (#%d, %s), rage %.1f / 100.", name, g_jugg, how, g_rage)
    return PLUGIN_HANDLED
}

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.