Skip to content
View in the app

A better way to browse. Learn more.

Learn more

wave-bell/addons/amxmodx/scripting/olds_wavebell.sma

olds_wavebell.sma
207 lines · 6.1 KB · Pawn (AMX Mod X)
Raw
/*
 * Wave Bell (olds.ro workshop card AMX-071)
 *
 * Zombie wave modes: a survivor says /assemble and every living survivor
 * sees a shared countdown to the next scheduled wave, with a bell at zero:
 *     Assemble! Next wave in 20 s
 * The plugin only reads the schedule: it never starts, delays or changes a
 * wave.
 *
 *   say /assemble   start the team countdown (living survivors)
 *
 * Adapter: wave cores have no common API, so the core, or a small bridge,
 * tells this plugin its schedule through two natives (library
 * "olds_wavebell", include/olds_wavebell.inc):
 *     olds_wavebell_set_next(Float:seconds)   the next wave starts in this many
 *                                             seconds; 0 or less: none scheduled
 *     olds_wavebell_set_active(bool:active)   a wave is running / has ended
 * A running countdown follows every new schedule at once (it jumps to the new
 * time), and is cancelled when the schedule is cleared, a wave becomes
 * active, or the round ends. Requests are refused while a wave is running or
 * when no wave is scheduled.
 *
 * Survivors: the counter-terrorist team (zombies are terrorists), as in the
 * classic zombie mods.
 *
 * Cvar: olds_wavebell_cd 30 (5-300), seconds between accepted requests.
 * Command: olds_wavebell_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  "Wave Bell"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

const TASK_COUNT = 7111
new const BELL[] = "buttons/bell1.wav"

new Float:g_nextWave                  // gametime of the next wave, 0.0 = none scheduled
new bool:g_waveActive
new bool:g_counting
new Float:g_nextRequest
new Float:g_nextUse[MAX_PLAYERS + 1]
new g_cooldown

public plugin_natives()
{
    register_library("olds_wavebell")
    register_native("olds_wavebell_set_next", "native_set_next")
    register_native("olds_wavebell_set_active", "native_set_active")
}

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

    bind_pcvar_num(create_cvar("olds_wavebell_cd", "30", FCVAR_NONE,
        "Seconds between accepted /assemble requests (5-300).", true, 5.0, true, 300.0), g_cooldown)
    AutoExecConfig(true, "olds_wavebell")

    register_clcmd("say /assemble", "cmd_assemble")
    register_clcmd("say_team /assemble", "cmd_assemble")
    register_concmd("olds_wavebell_status", "cmd_status", ADMIN_CFG, "- the wave schedule and the countdown")

    RegisterHookChain(RG_RoundEnd, "on_round_end_post", true)
    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
}

/* ---------- the schedule (from the core) ---------- */

public native_set_next(plugin, params)
{
    new Float:seconds = get_param_f(1)
    if (seconds <= 0.0)
    {
        g_nextWave = 0.0
        cancel()
    }
    else
        g_nextWave = get_gametime() + seconds
    return 1
}

public native_set_active(plugin, params)
{
    g_waveActive = get_param(1) != 0
    if (g_waveActive)
        cancel()
    return 1
}

/* ---------- /assemble ---------- */

bool:is_survivor(id)
{
    return is_user_alive(id) && TeamName:get_member(id, m_iTeam) == TEAM_CT
}

public cmd_assemble(id)
{
    if (!is_user_connected(id))
        return PLUGIN_HANDLED
    new Float:now = get_gametime()
    if (now < g_nextUse[id])
        return PLUGIN_HANDLED
    g_nextUse[id] = now + 1.0

    if (!is_survivor(id))
        reply(id, "WAVEBELL_SURVIVORS_ONLY")
    else if (g_waveActive)
        reply(id, "WAVEBELL_WAVE_RUNNING")
    else if (g_nextWave == 0.0 || g_nextWave <= now)
        reply(id, "WAVEBELL_NO_WAVE")
    else if (g_counting)
        reply(id, "WAVEBELL_ALREADY")
    else if (now < g_nextRequest)
        reply(id, "WAVEBELL_COOLDOWN", floatround(g_nextRequest - now, floatround_ceil))
    else
    {
        g_nextRequest = now + float(g_cooldown)
        g_counting = true
        new name[MAX_NAME_LENGTH]
        get_user_name(id, name, charsmax(name))
        for (new p = 1; p <= MaxClients; p++)
            if (is_survivor(p) && !is_user_bot(p))
                reply(p, "WAVEBELL_CALLED", name)
        task_count()
        set_task(1.0, "task_count", TASK_COUNT, _, _, "b")
    }
    return PLUGIN_HANDLED
}

/* ---------- the countdown ---------- */

public task_count()
{
    if (!g_counting)
        return
    if (g_waveActive || g_nextWave == 0.0)
    {
        cancel()
        return
    }
    new left = max(floatround(g_nextWave - get_gametime(), floatround_ceil), 0)
    set_dhudmessage(255, 120, 80, -1.0, 0.18, 0, 0.0, 1.05, 0.0, 0.0)
    for (new p = 1; p <= MaxClients; p++)
        if (is_survivor(p) && !is_user_bot(p))
            show_dhudmessage(p, "%L", p, "WAVEBELL_HUD", left)
    if (!left)
    {
        for (new p = 1; p <= MaxClients; p++)
            if (is_survivor(p) && !is_user_bot(p))
                rg_send_audio(p, BELL)
        cancel()
    }
}

cancel()
{
    g_counting = false
    remove_task(TASK_COUNT)
}

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

public on_restart_round_pre()
{
    cancel()
    return HC_CONTINUE
}

reply(id, const key[], any:...)
{
    new pattern[160], message[192]
    formatex(pattern, charsmax(pattern), "%L", id, key)
    vformat(message, charsmax(message), pattern, 3)
    client_print_color(id, print_team_default, "^4[Wave Bell]^1 %s", message)
}

public client_disconnected(id)
{
    g_nextUse[id] = 0.0
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    new Float:now = get_gametime()
    if (g_nextWave == 0.0)
        console_print(id, "[Wave Bell] no wave scheduled; wave %s", g_waveActive ? "running" : "not running")
    else
        console_print(id, "[Wave Bell] next wave in %.1f s; wave %s", floatmax(g_nextWave - now, 0.0),
            g_waveActive ? "running" : "not running")
    console_print(id, "[Wave Bell] countdown %s; next request in %d s", g_counting ? "on" : "off",
        max(floatround(g_nextRequest - now, floatround_ceil), 0))
    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.