/*
* Auto Demo Recorder (olds.ro workshop card LIB-0832)
*
* Starts a demo on every player's own client a few seconds after they join,
* named <map>_<date>_<nickname>, so evidence of rule breakers is kept on the
* players' side. The client engine writes it into its own cstrike folder;
* nothing is sent from the server. Bots and HLTV are skipped.
*
* On joining (and again after every map change, when clients join anew):
* olds_autodemo_delay seconds later the client gets "stop" and then
* "record <name>". The name keeps only letters, digits, '_' and '-' from the
* map and the nickname (anything else becomes '_'), so it is always a valid
* file name inside the game folder.
*
* Cvars: olds_autodemo_enable 1, olds_autodemo_delay 8.0 (1-60),
* olds_autodemo_tell 1 (the player is told the demo's name in chat).
* Command: olds_autodemo_status (ADMIN_CFG).
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Auto Demo Recorder"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
const TASK_RECORD = 8320
const NAME_PART = 24
const DEMO_NAME = 80
new g_demo[MAX_PLAYERS + 1][DEMO_NAME] // empty = no demo started
new g_map[NAME_PART + 1]
new g_enable
new Float:g_delay
new g_tell
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_autodemo.txt")
bind_pcvar_num(create_cvar("olds_autodemo_enable", "1", FCVAR_NONE,
"1 = record a demo on every joining player's client.", true, 0.0, true, 1.0), g_enable)
bind_pcvar_float(create_cvar("olds_autodemo_delay", "8.0", FCVAR_NONE,
"Seconds after joining before the demo starts (1-60).", true, 1.0, true, 60.0), g_delay)
bind_pcvar_num(create_cvar("olds_autodemo_tell", "1", FCVAR_NONE,
"1 = tell the player the demo's name in chat.", true, 0.0, true, 1.0), g_tell)
AutoExecConfig(true, "olds_autodemo")
register_concmd("olds_autodemo_status", "cmd_status", ADMIN_CFG, "- demos started on this map")
new map[64]
get_mapname(map, charsmax(map))
clean(map, g_map, charsmax(g_map), "map")
}
/* Letters, digits, '_' and '-'; anything else '_'; never empty. */
clean(const text[], out[], maxLength, const fallback[])
{
new length
for (new i = 0; text[i] && length < maxLength; i++)
{
new c = text[i]
out[length++] = (('a' <= c <= 'z') || ('A' <= c <= 'Z') || ('0' <= c <= '9') || c == '_' || c == '-') ? c : '_'
}
out[length] = EOS
// A name of only underscores says nothing: use the fallback.
for (new i = 0; i < length; i++)
if (out[i] != '_')
return
copy(out, maxLength, fallback)
}
public client_putinserver(id)
{
g_demo[id][0] = EOS
remove_task(TASK_RECORD + id)
if (!g_enable || is_user_bot(id) || is_user_hltv(id))
return
set_task(g_delay, "task_record", TASK_RECORD + id)
}
public task_record(taskId)
{
new id = taskId - TASK_RECORD
if (!g_enable || !is_user_connected(id) || is_user_bot(id) || is_user_hltv(id))
return
new nick[MAX_NAME_LENGTH], cleanNick[NAME_PART + 1], date[12]
get_user_name(id, nick, charsmax(nick))
clean(nick, cleanNick, charsmax(cleanNick), "player")
get_time("%Y%m%d", date, charsmax(date))
formatex(g_demo[id], charsmax(g_demo[]), "%s_%s_%s", g_map, date, cleanNick)
client_cmd(id, "stop")
client_cmd(id, "record ^"%s^"", g_demo[id])
if (g_tell)
client_print_color(id, print_team_default, "^4[Demo]^1 %L", id, "AUTODEMO_TELL", g_demo[id])
}
public client_disconnected(id)
{
g_demo[id][0] = EOS
remove_task(TASK_RECORD + id)
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[AutoDemo] %s; delay %.1f s; tell %d", g_enable ? "enabled" : "disabled", g_delay, g_tell)
new name[MAX_NAME_LENGTH]
for (new p = 1; p <= MaxClients; p++)
{
if (!is_user_connected(p))
continue
get_user_name(p, name, charsmax(name))
if (is_user_bot(p) || is_user_hltv(p))
console_print(id, "[AutoDemo] %s: skipped (%s)", name, is_user_bot(p) ? "bot" : "HLTV")
else if (g_demo[p][0])
console_print(id, "[AutoDemo] %s: %s.dem", name, g_demo[p])
else
console_print(id, "[AutoDemo] %s: %s", name, task_exists(TASK_RECORD + p) ? "starting soon" : "not recording")
}
return PLUGIN_HANDLED
}