Promote server
csb-lo3 / addons / amxmodx / scripting / csb_lo3.sma
129 lines 3.2 KiB Pawn Raw Permalink History
/*
 * CSB LO3
 * Copyright (C) 2026 counter-strike-boost.com
 *
 * amx_lo3 runs three sv_restartround restarts with a configurable delay and an
 * on-screen countdown, then flashes LIVE! LIVE! LIVE! with a sound when the
 * match goes live. amx_lo1 does the same with a single restart. The restart
 * itself resets score and money via the engine.
 *
 * 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 in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See <https://www.gnu.org/licenses/> for details.
 */

#include <amxmodx>
#include <amxmisc>

new const PLUGIN[] = "CSB LO3"
new const VERSION[] = "1.0.0"
new const AUTHOR[]  = "counter-strike-boost.com"

new g_pEnabled, g_pDelay
new g_iLeft, g_iTotal
new g_iSync

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)

    g_pEnabled = register_cvar("csb_lo3_enabled", "1")
    g_pDelay   = register_cvar("csb_lo3_delay", "3.0")

    register_concmd("amx_lo3", "cmdLo3", ADMIN_BAN, "- 3 restarts then go LIVE")
    register_concmd("amx_lo1", "cmdLo1", ADMIN_BAN, "- 1 restart then go LIVE")

    g_iSync = CreateHudSyncObj()
}

public cmdLo3(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED

    beginLive(id, 3)
    return PLUGIN_HANDLED
}

public cmdLo1(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED

    beginLive(id, 1)
    return PLUGIN_HANDLED
}

beginLive(id, count)
{
    if (!get_pcvar_num(g_pEnabled))
    {
        console_print(id, "[CSB LO3] Plugin is disabled.")
        return
    }

    if (g_iLeft > 0)
    {
        console_print(id, "[CSB LO3] A restart sequence is already running.")
        return
    }

    new name[32]
    if (id)
        get_user_name(id, name, charsmax(name))
    else
        copy(name, charsmax(name), "Console")

    client_print(0, print_chat, "[CSB LO3] %s started the LIVE sequence (%d restart(s)).", name, count)

    g_iTotal = count
    g_iLeft  = count
    doRestart()
}

doRestart()
{
    if (g_iLeft <= 0)
    {
        goLive()
        return
    }

    new done = g_iTotal - g_iLeft + 1

    /* classic knife-round style restart; resets score and money */
    server_cmd("sv_restartround 1")

    set_hudmessage(255, 160, 0, -1.0, 0.35, 0, 0.0, 3.0, 0.0, 0.0, -1)
    ShowSyncHudMsg(0, g_iSync, "RESTART %d / %d", done, g_iTotal)
    client_print(0, print_chat, "[CSB LO3] Restart %d of %d...", done, g_iTotal)

    g_iLeft--

    new Float:delay = get_pcvar_float(g_pDelay)
    if (delay < 1.0)
        delay = 1.0

    set_task(delay, "taskNext")
}

public taskNext()
{
    doRestart()
}

goLive()
{
    g_iLeft  = 0
    g_iTotal = 0

    set_hudmessage(0, 255, 0, -1.0, 0.30, 2, 0.5, 4.0, 0.1, 0.1, -1)
    ShowSyncHudMsg(0, g_iSync, "LIVE! LIVE! LIVE!")
    client_print(0, print_chat, "[CSB LO3] ^x04LIVE LIVE LIVE^x01 - good luck, have fun!")

    /* audible go signal */
    client_cmd(0, "spk fvox/beep")
}