Skip to content
View in the app

A better way to browse. Learn more.

Learn more

juggernaut-armor-plates/addons/amxmodx/scripting/olds_plates.sma

olds_plates.sma
284 lines · 8.4 KB · Pawn (AMX Mod X)
Raw
/*
 * Juggernaut Armor Plates (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 wears three plates: head, chest (chest, stomach and arms)
 * and legs, each with its own durability. A hit on a zone whose plate holds
 * does olds_plate_reduce percent less damage, and the plate loses what it
 * stopped; a plate with less left than that stops only what it has left.
 * At 0 the plate breaks: every player is told ("Head plate destroyed"), the
 * stock debris/metal3.wav plays at the juggernaut and that zone takes full
 * damage. Blast damage (HE grenades) has no zone: what the plates stop is
 * split evenly across the plates still standing. Other damage (falls, the
 * world) is not touched.
 *
 * The zone comes from RG_CBasePlayer_TraceAttack (the trace's hitgroup), the
 * damage is changed in RG_CBasePlayer_TakeDamage. Hunters aiming at the
 * juggernaut see the three plate values on the HUD (every 0.5 s).
 * Plates are reset at every round restart and when the juggernaut changes.
 *
 * The juggernaut: named by a core with olds_plates_set_juggernaut(id)
 * (include/olds_plates.inc), or else the only player on the terrorist team
 * while counter-terrorists play.
 *
 * Cvars: olds_plate_head 300, olds_plate_chest 800, olds_plate_legs 500,
 * olds_plate_reduce 70. Command: amx_plates (ADMIN_KICK) prints the plates.
 */
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>

#define PLUGIN  "Juggernaut Armor Plates"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

#define TASK_TICK  44780
#define ZONES      3
#define ZONE_NONE  -1
#define ZONE_HEAD  0
#define ZONE_CHEST 1
#define ZONE_LEGS  2

new const BREAK_SOUND[] = "debris/metal3.wav"
new const ZONE_KEYS[ZONES][] = { "PLATE_HEAD", "PLATE_CHEST", "PLATE_LEGS" }

new g_cvMax[ZONES], g_cvReduce
new g_hud

new g_jugg
new bool:g_byCore
new Float:g_plate[ZONES]
new Float:g_plateMax[ZONES]
new g_zone = ZONE_NONE
new Float:g_zoneTime

public plugin_natives()
{
    register_library("olds_plates")
    register_native("olds_plates_set_juggernaut", "native_set_juggernaut")
}

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 plugin_precache()
{
    precache_sound(BREAK_SOUND)
}

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

    g_cvMax[ZONE_HEAD] = create_cvar("olds_plate_head", "300", FCVAR_NONE, "Head plate durability", true, 0.0, true, 100000.0)
    g_cvMax[ZONE_CHEST] = create_cvar("olds_plate_chest", "800", FCVAR_NONE, "Chest plate durability (chest, stomach, arms)", true, 0.0, true, 100000.0)
    g_cvMax[ZONE_LEGS] = create_cvar("olds_plate_legs", "500", FCVAR_NONE, "Leg plate durability", true, 0.0, true, 100000.0)
    g_cvReduce = create_cvar("olds_plate_reduce", "70", FCVAR_NONE, "Percent of damage a standing plate stops", true, 0.0, true, 100.0)
    AutoExecConfig(true, "olds_plates")

    RegisterHookChain(RG_CBasePlayer_TraceAttack, "on_trace_attack_pre", false)
    RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_pre", false)
    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_post", true)
    register_concmd("amx_plates", "cmd_plates", ADMIN_KICK, "- shows the juggernaut's armor plates")

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

public client_disconnected(id)
{
    if (id == g_jugg)
    {
        g_byCore = false
        set_juggernaut(0)
    }
}

reset_plates()
{
    for (new z = 0; z < ZONES; z++)
    {
        g_plateMax[z] = get_pcvar_float(g_cvMax[z])
        g_plate[z] = g_plateMax[z]
    }
    g_zone = ZONE_NONE
}

set_juggernaut(id)
{
    if (id == g_jugg)
        return
    g_jugg = id
    reset_plates()
}

public on_restart_round_post()
{
    reset_plates()
    if (!g_byCore)
        g_jugg = 0
}

/* The lone terrorist, when counter-terrorists play too (unless a core names one). */
find_juggernaut()
{
    if (g_byCore)
        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++
    }
    set_juggernaut((t == 1 && cts > 0) ? lone : 0)
}

zone_of(hitgroup)
{
    switch (hitgroup)
    {
        case HIT_HEAD: return ZONE_HEAD
        case HIT_CHEST, HIT_STOMACH, HIT_LEFTARM, HIT_RIGHTARM: return ZONE_CHEST
        case HIT_LEFTLEG, HIT_RIGHTLEG: return ZONE_LEGS
    }
    return ZONE_NONE
}

public on_trace_attack_pre(victim, attacker, Float:damage, Float:dir[3], tr, bits)
{
    if (!g_jugg || victim != g_jugg)
        return HC_CONTINUE
    g_zone = zone_of(get_tr2(tr, TR_iHitgroup))
    g_zoneTime = get_gametime()
    return HC_CONTINUE
}

/* The plate stops up to amount (no more than it has left); returns what it stopped. */
Float:wear(zone, Float:amount)
{
    new Float:taken = floatmin(amount, g_plate[zone])
    g_plate[zone] -= taken
    if (g_plate[zone] <= 0.0)
    {
        g_plate[zone] = 0.0
        plate_broken(zone)
    }
    return taken
}

plate_broken(zone)
{
    if (is_user_connected(g_jugg))
        emit_sound(g_jugg, CHAN_ITEM, BREAK_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    new name[16]
    for (new id = 1; id <= MaxClients; id++)
    {
        if (!is_user_connected(id) || is_user_bot(id))
            continue
        formatex(name, charsmax(name), "%L", id, ZONE_KEYS[zone])
        client_print(id, print_chat, "%L", id, "PLATE_BROKEN", name)
    }
    formatex(name, charsmax(name), "%L", LANG_SERVER, ZONE_KEYS[zone])
    server_print("[Plates] %L", LANG_SERVER, "PLATE_BROKEN", name)
}

public on_take_damage_pre(victim, inflictor, attacker, Float:damage, bits)
{
    if (!g_jugg || victim != g_jugg || damage <= 0.0)
        return HC_CONTINUE
    new zone = g_zone
    new bool:fresh = (g_zoneTime == get_gametime())
    g_zone = ZONE_NONE

    new Float:stop = damage * get_pcvar_float(g_cvReduce) / 100.0
    new Float:absorbed
    if (bits & DMG_BLAST)
    {
        new standing
        for (new z = 0; z < ZONES; z++)
            if (g_plate[z] > 0.0)
                standing++
        if (!standing)
            return HC_CONTINUE
        new Float:share = stop / float(standing)
        for (new z = 0; z < ZONES; z++)
            if (g_plate[z] > 0.0)
                absorbed += wear(z, share)
    }
    else if (fresh && zone != ZONE_NONE && g_plate[zone] > 0.0)
        absorbed = wear(zone, stop)

    if (absorbed > 0.0)
        SetHookChainArg(4, ATYPE_FLOAT, damage - absorbed)
    return HC_CONTINUE
}

public tick()
{
    find_juggernaut()
    if (!g_jugg || !is_user_alive(g_jugg))
        return
    new team = get_member(g_jugg, m_iTeam)
    new target, body, line[96]
    for (new id = 1; id <= MaxClients; id++)
    {
        if (id == g_jugg || !is_user_alive(id) || is_user_bot(id) || get_member(id, m_iTeam) == team)
            continue
        get_user_aiming(id, target, body)
        if (target != g_jugg)
            continue
        plates_line(id, line, charsmax(line))
        set_hudmessage(200, 200, 255, -1.0, 0.62, 0, 0.0, 0.6, 0.0, 0.1, -1)
        ShowSyncHudMsg(id, g_hud, "%s", line)
    }
}

plates_line(id, line[], len)
{
    formatex(line, len, "%L", id, "PLATE_HUD",
        floatround(g_plate[ZONE_HEAD], floatround_ceil),
        floatround(g_plate[ZONE_CHEST], floatround_ceil),
        floatround(g_plate[ZONE_LEGS], floatround_ceil))
}

public cmd_plates(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    if (!g_jugg)
    {
        console_print(id, "%L", id, "PLATE_NOJUGG")
        return PLUGIN_HANDLED
    }
    new line[96]
    plates_line(id, line, charsmax(line))
    console_print(id, "%n: %s", g_jugg, line)
    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.