/*
* Admin Next Map Setter (olds.ro)
* 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.
*
* 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/>.
*
* An admin sets the next map with amx_setnext <mapname>. The name is checked (allowed
* characters, is_map_valid) and written to amx_nextmap, which the nextmap line shows and the
* stock nextmap plugin changes to at the end of the map. Without the stock nextmap plugin this
* plugin does that change itself (at intermission) and answers "say nextmap". The choice is
* for one map change only: it is forgotten at plugin_end, and without the stock plugin the
* previous amx_nextmap is put back so the map cycle goes on. The last amx_setnext wins.
*
* Cvars: olds_setnext_announce 1 (tell everyone in chat)
* Admin: amx_setnext <mapname> (ADMIN_MAP)
*/
#include <amxmodx>
#include <amxmisc>
#pragma semicolon 0
#define PLUGIN "Admin Next Map Setter"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define TASK_CHANGE 7600
new g_announce
new g_nextmap
new g_chattime
new g_chosen[32]
new g_previous[32]
new bool:g_own
new Float:g_savedChat
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_setnext.txt")
bind_pcvar_num(create_cvar("olds_setnext_announce", "1", FCVAR_NONE,
"Tell everyone in chat when an admin sets the next map", true, 0.0, true, 1.0), g_announce)
AutoExecConfig(true, "olds_setnext")
g_nextmap = register_cvar("amx_nextmap", "", FCVAR_SERVER | FCVAR_EXTDLL | FCVAR_SPONLY)
g_chattime = get_cvar_pointer("mp_chattime")
register_concmd("amx_setnext", "cmd_setnext", ADMIN_MAP, "<mapname> - sets the next map (one change only)")
}
public plugin_cfg()
{
/* With the stock nextmap plugin it changes the map and answers "say nextmap". */
g_own = !is_plugin_loaded("nextmap.amxx", true)
if (g_own)
{
register_message(SVC_INTERMISSION, "on_intermission")
register_clcmd("say nextmap", "cmd_say_nextmap")
register_clcmd("say_team nextmap", "cmd_say_nextmap")
}
new current[32], next[32]
get_mapname(current, charsmax(current))
get_pcvar_string(g_nextmap, next, charsmax(next))
if (!next[0])
copy(next, charsmax(next), "(none)")
log_amx("Map %s, amx_nextmap %s", current, next)
}
public plugin_end()
{
if (g_chosen[0] && g_own)
set_pcvar_string(g_nextmap, g_previous)
if (g_savedChat > 0.0 && g_chattime)
set_pcvar_float(g_chattime, g_savedChat)
g_chosen[0] = EOS
}
/* ------------------------------------------------------------ the command */
bool:map_name_ok(const map[])
{
new len = strlen(map)
if (len < 1 || len > 31)
return false
for (new i = 0; i < len; i++)
{
new c = map[i]
if (!(('a' <= c <= 'z') || ('A' <= c <= 'Z') || ('0' <= c <= '9') || c == '_' || c == '-' || c == '.'))
return false
}
return true
}
public cmd_setnext(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
if (read_argc() < 2)
{
console_print(id, "%L", id, "SETNEXT_USAGE")
return PLUGIN_HANDLED
}
new map[64]
read_argv(1, map, charsmax(map))
trim(map)
if (!map[0])
{
console_print(id, "%L", id, "SETNEXT_USAGE")
return PLUGIN_HANDLED
}
if (!map_name_ok(map) || !is_map_valid(map))
{
console_print(id, "%L", id, "SETNEXT_BAD", map)
log_amx("amx_setnext rejected: %s is not an installed map", map)
return PLUGIN_HANDLED
}
if (!g_chosen[0])
get_pcvar_string(g_nextmap, g_previous, charsmax(g_previous))
copy(g_chosen, charsmax(g_chosen), map)
set_pcvar_string(g_nextmap, g_chosen)
new admin[MAX_NAME_LENGTH], auth[40]
if (id)
{
get_user_name(id, admin, charsmax(admin))
get_user_authid(id, auth, charsmax(auth))
}
else
{
copy(admin, charsmax(admin), "server")
copy(auth, charsmax(auth), "console")
}
log_amx("%s <%s> set the next map to %s", admin, auth, g_chosen)
console_print(id, "%L", id, "SETNEXT_DONE", g_chosen)
if (g_announce)
{
new players[MAX_PLAYERS], count
get_players_ex(players, count, GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)
for (new i = 0; i < count; i++)
client_print_color(players[i], print_team_default, "%L", players[i], "SETNEXT_ANNOUNCE", admin, g_chosen)
log_amx("Announced: next map %s", g_chosen)
}
return PLUGIN_HANDLED
}
public cmd_say_nextmap(id)
{
new next[32]
get_pcvar_string(g_nextmap, next, charsmax(next))
if (next[0])
client_print_color(0, print_team_default, "%L", LANG_PLAYER, "SETNEXT_LINE", next)
else
client_print_color(0, print_team_default, "%L", LANG_PLAYER, "SETNEXT_LINE_NONE")
return PLUGIN_CONTINUE
}
/* ------------------------------------------------------------ the map change (no stock nextmap) */
public on_intermission()
{
if (!g_chosen[0] || task_exists(TASK_CHANGE))
return PLUGIN_CONTINUE
/* Stay ahead of the game's own map cycle change, which comes at the end of mp_chattime. */
new Float:chat = 10.0
if (g_chattime)
{
chat = floatclamp(get_pcvar_float(g_chattime), 0.0, 60.0)
g_savedChat = get_pcvar_float(g_chattime)
set_pcvar_float(g_chattime, chat + 2.0)
}
set_task(floatmax(chat, 0.1), "task_change", TASK_CHANGE)
log_amx("Intermission: changing to %s in %.1f s", g_chosen, chat)
return PLUGIN_CONTINUE
}
public task_change()
{
if (!g_chosen[0] || !is_map_valid(g_chosen))
return
new map[32]
copy(map, charsmax(map), g_chosen)
engine_changelevel(map)
}