[Plugin] Round Restart Command v1.0.0 (amx_restartround, amx_restartgame)v1.0.0Counter-Strike 1.6Plugin
plugin-round-restart-command-v1-0-0-amx/olds_restart.sma
/*
* Round Restart Command (olds.ro workshop card LIB-1885)
*
* Admins restart the current round, or the whole game, from the console:
* at once, or after a countdown that every player sees in the centre of the
* screen and hears as a spoken count (the stock fvox voice of the game, so
* nothing is downloaded).
*
* Console commands (admins with the ADMIN_MAP flag, and the server console):
* amx_restartround [seconds] When the countdown reaches 0 the round ends
* as a draw and the next one starts after
* mp_round_restart_delay. Money, scores and
* weapons are kept.
* amx_restartgame [seconds] When the countdown reaches 0 the game
* restarts (sv_restart 1): scores and money
* go back to the start values.
* Without seconds, or with 0, the restart happens at once. Running either
* command while a countdown is running cancels that countdown. A round
* restart that is still counting when the round ends by itself is dropped,
* because that round is already over.
*
* Cvars (saved with their descriptions in configs/plugins/olds_restart.cfg
* the first time the plugin starts):
* olds_rr_maxdelay 10 Longest countdown in seconds (1 - 60). A longer
* request is cut to this and the admin is told.
* olds_rr_log 1 1 = write who restarted or cancelled to the AMXX log.
*
* Requires AMX Mod X 1.9 or newer. amx_restartround needs ReGameDLL_CS,
* whose endround server command ends a round without resetting money (the
* stock game can only restart the whole game); on a server without
* ReGameDLL that command says so and does nothing. ReAPI is not used.
*
* Copyright (C) 2026 alexit (olds.ro workshop)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* 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.
*
* This program 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 the GNU General Public License for
* more details: <https://www.gnu.org/licenses/>.
*/
#include <amxmodx>
#include <amxmisc>
#pragma semicolon 1
new const PLUGIN_NAME[] = "Round Restart Command";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
const TASK_COUNTDOWN = 18850;
// Longest countdown the cvar allows.
const MAX_DELAY_LIMIT = 60;
// Spoken numbers of the stock fvox voice, index = seconds left.
new const NUMBER_SOUNDS[][] =
{
"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"
};
// Played each second when more than ten seconds are left.
new const TICK_SOUND[] = "buttons/blip1";
enum RestartKind
{
RESTART_NONE,
RESTART_ROUND,
RESTART_GAME
};
// Indexed by RestartKind.
new const KIND_NAMES[RestartKind][] = { "", "round", "game" };
new const KIND_TITLES[RestartKind][] = { "", "Round", "Game" };
new g_maxDelay; // olds_rr_maxdelay
new g_log; // olds_rr_log
// ReGameDLL is there, so the endround command exists.
new bool:g_canEndRound;
new RestartKind:g_pending = RESTART_NONE;
new g_secondsLeft;
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
bind_pcvar_num(create_cvar("olds_rr_maxdelay", "10", FCVAR_NONE,
"Longest restart countdown in seconds; longer requests are cut to this",
true, 1.0, true, float(MAX_DELAY_LIMIT)), g_maxDelay);
bind_pcvar_num(create_cvar("olds_rr_log", "1", FCVAR_NONE,
"1 = write who restarted or cancelled to the AMXX log",
true, 0.0, true, 1.0), g_log);
AutoExecConfig(true, "olds_restart");
// mp_round_restart_delay is one of the cvars only ReGameDLL has.
g_canEndRound = get_cvar_pointer("mp_round_restart_delay") != 0;
register_concmd("amx_restartround", "cmd_restart_round", ADMIN_MAP,
"[seconds] - end the round (money and scores kept), again to cancel a countdown");
register_concmd("amx_restartgame", "cmd_restart_game", ADMIN_MAP,
"[seconds] - restart the game (money and scores reset), again to cancel a countdown");
// Sent at every new round.
register_event("HLTV", "ev_new_round", "a", "1=0", "2=0");
}
public cmd_restart_round(id, level, cid)
{
if (cmd_access(id, level, cid, 1))
handle_request(id, RESTART_ROUND);
return PLUGIN_HANDLED;
}
public cmd_restart_game(id, level, cid)
{
if (cmd_access(id, level, cid, 1))
handle_request(id, RESTART_GAME);
return PLUGIN_HANDLED;
}
public ev_new_round()
{
// The round the admin wanted to end has ended by itself.
if (g_pending != RESTART_ROUND)
return;
stop_countdown();
client_print_color(0, print_team_default, "The round ended by itself, so the ^4round restart^1 was dropped.");
write_log(0, "round restart dropped: the round ended by itself");
}
handle_request(id, RestartKind:kind)
{
if (g_pending != RESTART_NONE)
{
new RestartKind:cancelled = g_pending;
stop_countdown();
console_print(id, "The %s restart countdown was cancelled.", KIND_NAMES[cancelled]);
client_print(0, print_center, "%s restart cancelled", KIND_TITLES[cancelled]);
client_print_color(0, print_team_default, "The ^4%s restart^1 was cancelled.", KIND_NAMES[cancelled]);
write_log(id, "cancelled the %s restart countdown", KIND_NAMES[cancelled]);
return;
}
if (kind == RESTART_ROUND && !g_canEndRound)
{
console_print(id, "amx_restartround needs ReGameDLL (endround command). amx_restartgame works without it.");
return;
}
new seconds;
if (read_argc() > 1)
{
new arg[8];
read_argv(1, arg, charsmax(arg));
// Digits only and at most five of them, so "-3", "2.5" or "5s" are
// refused instead of being read as some other number.
new length = strlen(arg);
if (length == 0 || length > 5 || !is_str_num(arg))
{
console_print(id, "Usage: amx_restart%s [seconds from 0 to %d]", KIND_NAMES[kind], g_maxDelay);
return;
}
seconds = str_to_num(arg);
}
if (seconds > g_maxDelay)
{
console_print(id, "%d seconds is longer than olds_rr_maxdelay, so the countdown runs for %d seconds.",
seconds, g_maxDelay);
seconds = g_maxDelay;
}
if (seconds == 0)
{
console_print(id, "Restarting the %s now.", KIND_NAMES[kind]);
write_log(id, "restarted the %s", KIND_NAMES[kind]);
do_restart(kind);
return;
}
g_pending = kind;
g_secondsLeft = seconds;
console_print(id, "The %s restarts in %d seconds. Run the command again to cancel.", KIND_NAMES[kind], seconds);
client_print_color(0, print_team_default, "^4%s restart^1 in ^4%d^1 seconds.", KIND_TITLES[kind], seconds);
write_log(id, "started a %d second %s restart countdown", seconds, KIND_NAMES[kind]);
show_count();
set_task(1.0, "task_countdown", TASK_COUNTDOWN, _, _, "b");
}
public task_countdown()
{
if (--g_secondsLeft > 0)
{
show_count();
return;
}
new RestartKind:kind = g_pending;
stop_countdown();
if (kind != RESTART_NONE)
do_restart(kind);
}
show_count()
{
client_print(0, print_center, "%s restart in %d", KIND_TITLES[g_pending], g_secondsLeft);
if (g_secondsLeft < sizeof(NUMBER_SOUNDS))
client_cmd(0, "spk ^"fvox/%s^"", NUMBER_SOUNDS[g_secondsLeft]);
else
client_cmd(0, "spk %s", TICK_SOUND);
}
stop_countdown()
{
remove_task(TASK_COUNTDOWN);
g_pending = RESTART_NONE;
g_secondsLeft = 0;
}
do_restart(RestartKind:kind)
{
client_print(0, print_center, "%s restart", KIND_TITLES[kind]);
if (kind == RESTART_ROUND)
server_cmd("endround");
else
server_cmd("sv_restart 1");
}
write_log(id, const fmt[], any:...)
{
if (!g_log)
return;
new action[96], name[MAX_NAME_LENGTH], authid[MAX_AUTHID_LENGTH];
vformat(action, charsmax(action), fmt, 3);
if (id)
{
get_user_name(id, name, charsmax(name));
get_user_authid(id, authid, charsmax(authid));
log_amx("^"%s<%d><%s><>^" %s", name, get_user_userid(id), authid, action);
}
else
{
log_amx("Server %s", action);
}
}