Skip to content
View in the app

A better way to browse. Learn more.

Learn more

snowball-rally/addons/amxmodx/scripting/olds_rally.sma

olds_rally.sma
185 lines · 5.6 KB · Pawn (AMX Mod X)
Raw
/*
 * Snowball Rally (olds.ro workshop card AMX-102)
 *
 * Snow Wars: each team builds a "rally" when consecutive snowball hits on
 * enemies come from different teammates in turn. A, B and C landing hits one
 * after another make a rally of 3; A hitting again right after C makes 4.
 * The team sees the rally grow on a DHUD line, and at round end each team is
 * told its longest rally of the round in team chat.
 *
 * Rules: a hit extends the team's rally when its thrower is not the one who
 * landed the team's previous hit; the same thrower twice in a row starts a
 * new rally at 1. A hit on a teammate neither extends nor breaks it. One
 * snowball counts once, even if it splashes several enemies. The round end
 * closes every rally.
 *
 * Adapter: Snow Wars cores have no common API, so the core, or a small
 * bridge, reports each confirmed hit through one native (library
 * "olds_rally", include/olds_rally.inc):
 *     olds_rally_hit(thrower, victim, snowball)   snowball = the projectile's
 *                                                  entity index (or any id
 *                                                  unique to that throw)
 *
 * Cvar: olds_rally_minchain 3 (2-20), the shortest rally reported.
 * Command: olds_rally_status (ADMIN_CFG).
 *
 * Copyright (C) 2026 daemon (olds.ro)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include <amxmodx>
#include <amxmisc>
#include <reapi>

#define PLUGIN  "Snowball Rally"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

const TEAMS = 2
const TASK_WATCH = 1011
const Float:SAME_THROW = 1.0          // one snowball's contacts arrive within this time

new g_chain[TEAMS]
new g_lastThrower[TEAMS]
new g_best[TEAMS]
new g_lastBall
new Float:g_lastBallTime
new bool:g_roundLive
new g_minChain

public plugin_natives()
{
    register_library("olds_rally")
    register_native("olds_rally_hit", "native_hit")
}

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

    bind_pcvar_num(create_cvar("olds_rally_minchain", "3", FCVAR_NONE,
        "Shortest rally reported to the team at round end (2-20).", true, 2.0, true, 20.0), g_minChain)
    AutoExecConfig(true, "olds_rally")

    register_concmd("olds_rally_status", "cmd_status", ADMIN_CFG, "- both teams' rallies this round")

    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
    RegisterHookChain(RG_RoundEnd, "on_round_end_post", true)
    set_task(1.0, "task_watch_round_end", TASK_WATCH, _, _, "b")
}

team_slot(id)
{
    switch (TeamName:get_member(id, m_iTeam))
    {
        case TEAM_TERRORIST: return 0
        case TEAM_CT: return 1
    }
    return -1
}

/* ---------- hits from the core ---------- */

public native_hit(plugin, params)
{
    new thrower = get_param(1), victim = get_param(2), ball = get_param(3)
    if (!g_roundLive || !(1 <= thrower <= MaxClients) || !(1 <= victim <= MaxClients) || thrower == victim)
        return 0
    if (!is_user_connected(thrower) || !is_user_connected(victim))
        return 0
    new t = team_slot(thrower)
    if (t < 0 || team_slot(victim) == t)
        return 0                     // a teammate: no extension, no break

    // A splash: the same snowball touching another enemy counts once.
    new Float:now = get_gametime()
    if (ball && ball == g_lastBall && now - g_lastBallTime < SAME_THROW)
        return 0
    g_lastBall = ball
    g_lastBallTime = now

    if (g_chain[t] && g_lastThrower[t] != thrower)
        g_chain[t]++
    else
        g_chain[t] = 1
    g_lastThrower[t] = thrower
    if (g_chain[t] > g_best[t])
        g_best[t] = g_chain[t]
    if (g_chain[t] >= 2)
        show_chain(t)
    return 1
}

show_chain(t)
{
    set_dhudmessage(t ? 90 : 255, 160, t ? 255 : 90, -1.0, 0.24, 0, 0.0, 1.5, 0.1, 0.3)
    for (new p = 1; p <= MaxClients; p++)
        if (is_user_connected(p) && !is_user_bot(p) && team_slot(p) == t)
            show_dhudmessage(p, "%L", p, "RALLY_HUD", g_chain[t])
}

/* ---------- rounds ---------- */

public on_restart_round_pre()
{
    for (new t = 0; t < TEAMS; t++)
    {
        g_chain[t] = 0
        g_lastThrower[t] = 0
        g_best[t] = 0
    }
    g_lastBall = 0
    g_roundLive = true
    return HC_CONTINUE
}

public on_round_end_post(WinStatus:status, ScenarioEventEndRound:event, Float:delay)
{
    if (event != ROUND_GAME_COMMENCE && event != ROUND_GAME_RESTART && get_member_game(m_bRoundTerminating))
        finish_round()
    return HC_CONTINUE
}

/* A round closed by rg_round_end() from another plugin skips RG_RoundEnd. */
public task_watch_round_end()
{
    if (g_roundLive && get_member_game(m_bRoundTerminating))
        finish_round()
}

finish_round()
{
    if (!g_roundLive)
        return
    g_roundLive = false
    for (new p = 1; p <= MaxClients; p++)
    {
        if (!is_user_connected(p) || is_user_bot(p))
            continue
        new t = team_slot(p)
        if (t >= 0 && g_best[t] >= g_minChain)
            client_print_color(p, print_team_default, "^4[Rally]^1 %L", p, "RALLY_BEST", g_best[t])
    }
    for (new t = 0; t < TEAMS; t++)
    {
        g_chain[t] = 0
        g_lastThrower[t] = 0
    }
}

public client_disconnected(id)
{
    // A thrower leaving does not break the rally; the next teammate still extends it.
    for (new t = 0; t < TEAMS; t++)
        if (g_lastThrower[t] == id)
            g_lastThrower[t] = -1
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    console_print(id, "[Rally] round %s; T rally %d (best %d); CT rally %d (best %d); reported from %d",
        g_roundLive ? "live" : "over", g_chain[0], g_best[0], g_chain[1], g_best[1], g_minChain)
    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.