/*
* Next Wave Preview (olds.ro workshop idea IDEA-0D6C6BE5E6B29A61)
* Copyright (C) 2026 daemon (olds.ro)
*
* 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/>.
*
* Tower Defence: between waves a 4-line HUD shows what the next wave holds (enemies, their
* kinds, their lane), for the whole break, to everyone on the server (late joiners too: it is
* sent again every second). say /wave repeats it in chat. Before the last wave the HUD says
* only that the final wave is next. The wave comes from the core's td_get_wave_info native,
* or, without it, from configs/olds_tdprev_waves.ini.
*/
#include <amxmodx>
#include <amxmisc>
#include <olds_td_waves>
#define PLUGIN "Next Wave Preview"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define TASK_HUD 87100
#define MAX_WAVES 100
new g_enabled
new bool:g_noNatives
new bool:g_break // between two waves
new bool:g_wave // a wave is running
new g_next // the wave the break is before
new g_count, g_types[96], g_lane[48]
new bool:g_final
new g_hud
/* The fallback wave list (configs/olds_tdprev_waves.ini). */
new g_fileCount[MAX_WAVES + 1], g_fileTypes[MAX_WAVES + 1][96], g_fileLane[MAX_WAVES + 1][48]
new g_fileWaves
public plugin_natives()
{
set_native_filter("native_filter")
}
public native_filter(const name[], index, trap)
{
if (!trap && (equal(name, "td_get_wave_info") || equal(name, "td_get_wave_count")))
{
g_noNatives = true
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_tdprev.txt")
bind_pcvar_num(create_cvar("olds_tdprev", "1", FCVAR_NONE, "1 = show the next wave between waves", true, 0.0, true, 1.0), g_enabled)
AutoExecConfig(true, "olds_tdprev")
register_clcmd("say /wave", "cmd_wave")
register_clcmd("say_team /wave", "cmd_wave")
register_concmd("amx_tdprev_status", "cmd_status", ADMIN_RCON, "- shows the preview text")
g_hud = CreateHudSyncObj()
if (g_noNatives)
load_file()
}
load_file()
{
new path[160]
get_configsdir(path, charsmax(path))
add(path, charsmax(path), "/olds_tdprev_waves.ini")
new file = fopen(path, "rt")
if (!file)
{
log_amx("No td_get_wave_info native and no %s: no previews.", path)
return
}
new line[192], num[8], cnt[8], types[96], lane[48], bad
while (!feof(file))
{
fgets(file, line, charsmax(line))
trim(line)
if (!line[0] || line[0] == ';' || line[0] == '/')
continue
if (parse(line, num, charsmax(num), cnt, charsmax(cnt), types, charsmax(types), lane, charsmax(lane)) < 3)
{
bad++
continue
}
new wave = str_to_num(num)
if (wave < 1 || wave > MAX_WAVES)
{
bad++
continue
}
g_fileCount[wave] = max(str_to_num(cnt), 0)
copy(g_fileTypes[wave], charsmax(g_fileTypes[]), types)
replace_all(g_fileTypes[wave], charsmax(g_fileTypes[]), ",", ", ")
copy(g_fileLane[wave], charsmax(g_fileLane[]), lane)
if (wave > g_fileWaves)
g_fileWaves = wave
}
fclose(file)
if (bad)
log_amx("%s: %d bad line(s) skipped", path, bad)
}
/* ------------------------------------------------------------------ the waves */
total_waves()
{
if (!g_noNatives)
return td_get_wave_count()
return g_fileWaves
}
bool:read_wave(wave)
{
g_count = 0
g_types[0] = EOS
g_lane[0] = EOS
if (!g_noNatives)
return td_get_wave_info(wave, g_count, g_types, charsmax(g_types), g_lane, charsmax(g_lane)) != 0
if (wave < 1 || wave > g_fileWaves || !g_fileCount[wave])
return false
g_count = g_fileCount[wave]
copy(g_types, charsmax(g_types), g_fileTypes[wave])
copy(g_lane, charsmax(g_lane), g_fileLane[wave])
return true
}
public td_wave_end(wave)
{
g_wave = false
if (!g_enabled)
return
g_next = wave + 1
new total = total_waves()
if (total > 0 && g_next > total)
{
/* The game is won: no break to fill. */
g_break = false
return
}
g_final = (total > 0 && g_next == total)
if (!read_wave(g_next) && !g_final)
{
log_amx("No information about wave %d.", g_next)
g_break = false
return
}
g_break = true
show_all()
remove_task(TASK_HUD)
set_task(1.0, "show_all", TASK_HUD, _, _, "b")
}
public td_wave_start(wave)
{
g_wave = true
g_break = false
remove_task(TASK_HUD)
for (new id = 1; id <= MaxClients; id++)
if (is_user_connected(id))
ClearSyncHud(id, g_hud)
}
/* ------------------------------------------------------------------ showing */
preview_text(id, text[], len)
{
if (g_final)
{
formatex(text, len, "%L", id, "TDPREV_FINAL", g_next)
return
}
new kinds[96], lane[48]
copy(kinds, charsmax(kinds), g_types)
if (!kinds[0])
formatex(kinds, charsmax(kinds), "%L", id, "TDPREV_UNKNOWN")
copy(lane, charsmax(lane), g_lane)
if (!lane[0])
formatex(lane, charsmax(lane), "%L", id, "TDPREV_UNKNOWN")
formatex(text, len, "%L", id, "TDPREV_HUD", g_next, total_waves(), g_count, kinds, lane)
}
public show_all()
{
if (!g_break || !g_enabled)
{
remove_task(TASK_HUD)
return
}
new text[256]
set_hudmessage(120, 220, 255, 0.02, 0.25, 0, 0.0, 1.2, 0.0, 0.1, -1)
for (new id = 1; id <= MaxClients; id++)
{
if (!is_user_connected(id))
continue
preview_text(id, text, charsmax(text))
ShowSyncHudMsg(id, g_hud, "%s", text)
}
}
public cmd_wave(id)
{
if (g_break && g_enabled)
{
new text[256], line[96], rest[256]
preview_text(id, text, charsmax(text))
/* The HUD's lines, one chat line each. */
while (text[0])
{
strtok2(text, line, charsmax(line), rest, charsmax(rest), '^n', TRIM_FULL)
if (line[0])
client_print(id, print_chat, "%s", line)
copy(text, charsmax(text), rest)
}
}
else if (g_wave)
client_print(id, print_chat, "%L", id, "TDPREV_IN_PROGRESS")
else
client_print(id, print_chat, "%L", id, "TDPREV_NONE")
return PLUGIN_CONTINUE
}
public cmd_status(id, level, cid)
{
if (id && !(get_user_flags(id) & level))
{
console_print(id, "You have no access to that command.")
return PLUGIN_HANDLED
}
console_print(id, "[TDPrev] enabled %d, source %d (1 = core native, 0 = file of %d waves), break %d, wave running %d",
g_enabled, g_noNatives ? 0 : 1, g_fileWaves, g_break, g_wave)
if (g_break)
{
new text[256]
preview_text(LANG_SERVER, text, charsmax(text))
replace_all(text, charsmax(text), "^n", " | ")
new players
for (new p = 1; p <= MaxClients; p++)
if (is_user_connected(p))
players++
console_print(id, "[TDPrev] HUD (sent to %d players every second): %s", players, text)
}
return PLUGIN_HANDLED
}