Skip to content
View in the app

A better way to browse. Learn more.

Learn more

juggernaut-mode/addons/amxmodx/scripting/olds_juggernaut.sma

olds_juggernaut.sma
331 lines · 11.8 KB · Pawn (AMX Mod X)
Raw
/*
 * Juggernaut Mode (olds.ro workshop card LIB-0916)
 *
 * One player each round becomes a heavily armoured juggernaut (terrorist)
 * with an M249 and extra ammo; everyone else (counter-terrorists, 80 HP)
 * works together to kill him before the time runs out.
 *
 *   - Pick: at every round restart, at random among the players on a team,
 *     not the last juggernaut when someone else can be. Two players at
 *     least; with fewer the round plays normally.
 *   - Juggernaut: olds_jugg_hp health, olds_jugg_armor kevlar and helmet,
 *     only the M249 (with olds_jugg_ammo spare rounds) and the knife, no
 *     buying or picking up, top speed olds_jugg_speed, also in the air (his
 *     horizontal speed is held to it after every move, so jumps do not
 *     gain speed).
 *   - Juggernaut killed: the hunters win (the killer is named).
 *   - Time up (olds_jugg_time seconds after freeze time) with him alive:
 *     the juggernaut wins; the hunters still alive are announced.
 *   - Juggernaut leaves mid-round: olds_jugg_leave 0 ends the round as a
 *     draw, 1 makes a random living hunter the new juggernaut at once.
 *
 * Files: the model models/player/jugg/jugg.mdl and the sound
 * sound/olds/jugg/spawn.wav are used when the server has them (players
 * then download them); otherwise the stock CT model "gign" with a red glow
 * and the stock ambience/siren.wav. Player models in Counter-Strike must
 * sit in models/player/<name>/<name>.mdl, so that is the model's path.
 *
 * Cvars: olds_jugg_hp 1500, olds_jugg_armor 300, olds_jugg_speed 200,
 * olds_jugg_time 120, olds_jugg_ammo 400, olds_jugg_others_hp 80, olds_jugg_leave 0.
 * Command: olds_jugg_status (ADMIN_CFG).
 *
 * Copyright (C) 2026 daemon (olds.ro)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <reapi>

#define PLUGIN  "Juggernaut Mode"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

const TASK_TIMER = 9161

new const CUSTOM_MODEL[] = "jugg"                       // models/player/jugg/jugg.mdl
new const FALLBACK_MODEL[] = "gign"
new const CUSTOM_SOUND[] = "olds/jugg/spawn.wav"
new const FALLBACK_SOUND[] = "ambience/siren.wav"

new g_jugg                                  // 0 = none this round
new g_lastJugg                              // user id of the last juggernaut
new Float:g_huntStart                       // 0 = freeze time
new bool:g_roundOver
new bool:g_hasModel
new g_sound[32]

new g_hp
new g_armor
new Float:g_speed
new g_time
new g_ammo
new g_othersHp
new g_leave

public plugin_precache()
{
    // A missing file would stop the server at precache: check first.
    g_hasModel = bool:file_exists(fmt("models/player/%s/%s.mdl", CUSTOM_MODEL, CUSTOM_MODEL))
    if (g_hasModel)
        precache_model(fmt("models/player/%s/%s.mdl", CUSTOM_MODEL, CUSTOM_MODEL))
    copy(g_sound, charsmax(g_sound), FALLBACK_SOUND)
    if (file_exists(fmt("sound/%s", CUSTOM_SOUND)))
        copy(g_sound, charsmax(g_sound), CUSTOM_SOUND)
    precache_sound(g_sound)
}

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

    bind_pcvar_num(create_cvar("olds_jugg_hp", "1500", FCVAR_NONE, "Juggernaut health (100-10000).", true, 100.0, true, 10000.0), g_hp)
    bind_pcvar_num(create_cvar("olds_jugg_armor", "300", FCVAR_NONE, "Juggernaut armour (0-999).", true, 0.0, true, 999.0), g_armor)
    bind_pcvar_float(create_cvar("olds_jugg_speed", "200", FCVAR_NONE, "Juggernaut top speed (100-320).", true, 100.0, true, 320.0), g_speed)
    bind_pcvar_num(create_cvar("olds_jugg_time", "120", FCVAR_NONE,
        "Seconds the hunters have after freeze time (10-600).", true, 10.0, true, 600.0), g_time)
    bind_pcvar_num(create_cvar("olds_jugg_ammo", "400", FCVAR_NONE, "Juggernaut spare M249 rounds (100-1000).", true, 100.0, true, 1000.0), g_ammo)
    bind_pcvar_num(create_cvar("olds_jugg_others_hp", "80", FCVAR_NONE, "Hunters' health (1-100).", true, 1.0, true, 100.0), g_othersHp)
    bind_pcvar_num(create_cvar("olds_jugg_leave", "0", FCVAR_NONE,
        "Juggernaut leaves mid-round: 0 = draw, 1 = a new juggernaut at once.", true, 0.0, true, 1.0), g_leave)
    AutoExecConfig(true, "olds_juggernaut")

    register_concmd("olds_jugg_status", "cmd_status", ADMIN_CFG, "- the juggernaut and the hunters")

    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
    RegisterHookChain(RG_CSGameRules_OnRoundFreezeEnd, "on_freeze_end_post", true)
    RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
    RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
    RegisterHookChain(RG_CBasePlayer_ResetMaxSpeed, "on_reset_maxspeed_post", true)
    RegisterHookChain(RG_CBasePlayer_PostThink, "on_post_think_post", true)
    RegisterHookChain(RG_CBasePlayer_HasRestrictItem, "on_restrict_item_pre", false)
    RegisterHookChain(RG_RoundEnd, "on_round_end_post", true)
    set_task(1.0, "task_timer", TASK_TIMER, _, _, "b")
}

/* ---------- the pick ---------- */

public on_restart_round_pre()
{
    g_jugg = 0
    g_huntStart = 0.0
    g_roundOver = false

    new players[MAX_PLAYERS], count, playing[MAX_PLAYERS], total
    get_players_ex(players, count, GetPlayers_ExcludeHLTV)
    for (new i = 0; i < count; i++)
    {
        new TeamName:team = TeamName:get_member(players[i], m_iTeam)
        if (team == TEAM_TERRORIST || team == TEAM_CT)
            playing[total++] = players[i]
    }
    if (total < 2)
        return HC_CONTINUE

    // Not the same juggernaut twice in a row.
    new choices[MAX_PLAYERS], options
    for (new i = 0; i < total; i++)
        if (get_user_userid(playing[i]) != g_lastJugg)
            choices[options++] = playing[i]
    g_jugg = options ? choices[random(options)] : playing[random(total)]
    g_lastJugg = get_user_userid(g_jugg)

    for (new i = 0; i < total; i++)
    {
        new id = playing[i], TeamName:team = (id == g_jugg) ? TEAM_TERRORIST : TEAM_CT
        if (TeamName:get_member(id, m_iTeam) != team)
            rg_set_user_team(id, team)
    }
    return HC_CONTINUE
}

public on_spawn_post(id)
{
    if (!is_user_alive(id))
        return HC_CONTINUE
    if (id == g_jugg)
        make_juggernaut(id)
    else if (g_jugg)
    {
        set_user_health(id, g_othersHp)
        set_entvar(id, var_renderfx, kRenderFxNone)
    }
    return HC_CONTINUE
}

make_juggernaut(id)
{
    rg_remove_all_items(id)
    rg_give_item(id, "weapon_knife")
    rg_give_item(id, "weapon_m249")
    rg_set_user_bpammo(id, WEAPON_M249, g_ammo)
    set_user_health(id, g_hp)
    rg_set_user_armor(id, g_armor, ARMOR_VESTHELM)
    set_entvar(id, var_maxspeed, g_speed)
    if (g_hasModel)
        rg_set_user_model(id, CUSTOM_MODEL)
    else
    {
        rg_set_user_model(id, FALLBACK_MODEL)
        set_entvar(id, var_renderfx, kRenderFxGlowShell)
        set_entvar(id, var_rendercolor, Float:{ 200.0, 30.0, 30.0 })
        set_entvar(id, var_renderamt, 12.0)
    }
    emit_sound(id, CHAN_STATIC, g_sound, VOL_NORM, ATTN_NONE, 0, PITCH_NORM)
    new name[MAX_NAME_LENGTH]
    get_user_name(id, name, charsmax(name))
    tell_all("JUGG_PICKED", name, g_hp, g_armor, g_time)
}

/* ---------- speed ---------- */

public on_reset_maxspeed_post(id)
{
    if (id == g_jugg && is_user_alive(id))
        set_entvar(id, var_maxspeed, g_speed)
    return HC_CONTINUE
}

/* After every move: no faster than olds_jugg_speed across the ground, jumping included. */
public on_post_think_post(id)
{
    if (id != g_jugg || !is_user_alive(id))
        return HC_CONTINUE
    new Float:velocity[3]
    get_entvar(id, var_velocity, velocity)
    new Float:flat = floatsqroot(velocity[0] * velocity[0] + velocity[1] * velocity[1])
    if (flat > g_speed)
    {
        new Float:scale = g_speed / flat
        velocity[0] *= scale
        velocity[1] *= scale
        set_entvar(id, var_velocity, velocity)
    }
    return HC_CONTINUE
}

/* The juggernaut keeps his M249: no buying or picking up. */
public on_restrict_item_pre(id, ItemID:item, ItemRestType:type)
{
    if (id == g_jugg && type != ITEM_TYPE_EQUIPPED)
    {
        SetHookChainReturn(ATYPE_BOOL, true)
        return HC_SUPERCEDE
    }
    return HC_CONTINUE
}

/* ---------- the round ---------- */

public on_freeze_end_post()
{
    g_huntStart = get_gametime()
    return HC_CONTINUE
}

public on_killed_post(victim, attacker, gib)
{
    if (victim != g_jugg || g_roundOver)
        return HC_CONTINUE
    new name[MAX_NAME_LENGTH]
    if (1 <= attacker <= MaxClients && attacker != victim && is_user_connected(attacker))
        get_user_name(attacker, name, charsmax(name))
    else
        copy(name, charsmax(name), "the world")
    finish(WINSTATUS_CTS, ROUND_CTS_WIN, "JUGG_DOWN", name)
    return HC_CONTINUE
}

public task_timer()
{
    if (!g_jugg || g_roundOver || g_huntStart == 0.0 || !is_user_alive(g_jugg))
        return
    if (get_gametime() - g_huntStart < float(g_time))
        return
    new survivors = get_playersnum_ex(GetPlayers_ExcludeDead | GetPlayers_MatchTeam, "CT")
    new name[MAX_NAME_LENGTH]
    get_user_name(g_jugg, name, charsmax(name))
    finish(WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "JUGG_SURVIVED", name, survivors)
}

public client_disconnected(id)
{
    if (id != g_jugg)
        return
    g_jugg = 0
    if (g_roundOver)
        return
    if (g_leave)
    {
        new players[MAX_PLAYERS], count
        get_players_ex(players, count, GetPlayers_ExcludeDead | GetPlayers_MatchTeam, "CT")
        // The leaver still counts here; skip them.
        new choices[MAX_PLAYERS], options
        for (new i = 0; i < count; i++)
            if (players[i] != id)
                choices[options++] = players[i]
        if (options >= 2)
        {
            g_jugg = choices[random(options)]
            g_lastJugg = get_user_userid(g_jugg)
            rg_set_user_team(g_jugg, TEAM_TERRORIST)
            make_juggernaut(g_jugg)
            return
        }
    }
    finish(WINSTATUS_DRAW, ROUND_END_DRAW, "JUGG_LEFT", "", 0)
}

finish(WinStatus:status, ScenarioEventEndRound:event, const key[], const name[], number = 0)
{
    g_roundOver = true
    tell_all(key, name, number)
    switch (status)
    {
        case WINSTATUS_CTS: rg_round_end(5.0, status, event, "The hunters win!", "default", true)
        case WINSTATUS_TERRORISTS: rg_round_end(5.0, status, event, "The juggernaut wins!", "default", true)
        default: rg_round_end(5.0, status, event, "Round draw", "default", true)
    }
}

public on_round_end_post(WinStatus:status, ScenarioEventEndRound:event, Float:delay)
{
    g_roundOver = true
    return HC_CONTINUE
}

/* ---------- messages ---------- */

tell_all(const key[], const name[] = "", a = 0, b = 0, c = 0)
{
    /* %L fills the translated text from the arguments that follow it. */
    for (new id = 1; id <= MaxClients; id++)
    {
        if (!is_user_connected(id) || is_user_bot(id))
            continue
        client_print_color(id, print_team_default, "^4[Juggernaut]^1 %L", id, key, name, a, b, c)
    }
    server_print("[Juggernaut] %L", LANG_SERVER, key, name, a, b, c)
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    new name[MAX_NAME_LENGTH] = "-"
    if (g_jugg && is_user_connected(g_jugg))
        get_user_name(g_jugg, name, charsmax(name))
    console_print(id, "[Juggernaut] juggernaut %s; %s; hunt %d/%d s; model %s; leave rule %s", name,
        g_roundOver ? "round over" : "round live", g_huntStart > 0.0 ? floatround(get_gametime() - g_huntStart) : 0, g_time,
        g_hasModel ? CUSTOM_MODEL : FALLBACK_MODEL, g_leave ? "new pick" : "draw")
    for (new p = 1; p <= MaxClients; p++)
    {
        if (!is_user_connected(p) || !is_user_alive(p))
            continue
        get_user_name(p, name, charsmax(name))
        console_print(id, "[Juggernaut]   %s: %s, health %d, armour %d, max speed %.0f", name,
            p == g_jugg ? "juggernaut" : "hunter", get_user_health(p), get_user_armor(p), Float:get_entvar(p, var_maxspeed))
    }
    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.