/*
* Recording Cue Sheet (olds.ro workshop card AMX-033)
*
* While a demo or HLTV recording runs, writes a cue sheet next to it: round
* starts and ends and bomb plants and defuses, each stamped with the time
* since the recording started, so the moments are easy to find in the demo.
*
* == recording started 2026-12-05 21:04:10 (de_dust2) ==
* 00:00 round 3 start
* 00:42 bomb planted (Alpha)
* 01:05 bomb defused (Bravo)
* 01:05 round 3 end: Counter-Terrorists win
* 01:30 == recording stopped ==
*
* The recorder tells this plugin when it really starts and stops (the
* adapter), in either of two ways:
* - console / rcon: olds_cues_start [label] and olds_cues_stop [failed]
* (an HLTV or demo script sends them when its recording starts and ends);
* - natives for recorder plugins (library "olds_cues"):
* native olds_cues_recording_start(const label[] = "")
* native olds_cues_recording_stop(bool:failed = false)
* HLTV writes one demo per map, so a recording ends at the map change and the
* adapter starts it again on the next map.
*
* Output: <AMXX logs>/olds_cues_<map>.txt, one file per map (a new map writes
* a new file; the same map later appends a new section). At most
* olds_cues_max lines are written per file per recording; then one last line
* says so and nothing more is added. If the file cannot be opened, one error
* is logged and writing stops until the next start.
*
* Events: RG_CSGameRules_RestartRound (round start), RG_RoundEnd (round end),
* CSX bomb_planted and bomb_defused.
*
* Cvar: olds_cues_max 400 (10-10000). Commands: olds_cues_start,
* olds_cues_stop (ADMIN_RCON), olds_cues_status (ADMIN_CFG).
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#include <csx>
#include <reapi>
#define PLUGIN "Recording Cue Sheet"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
new g_path[192]
new g_map[64]
new bool:g_recording
new bool:g_failed // the file could not be written: silent until the next start
new Float:g_start
new g_lines // lines written in this recording
new bool:g_capped
new g_round
new g_label[64]
new g_maxLines
public plugin_natives()
{
register_library("olds_cues")
register_native("olds_cues_recording_start", "native_start")
register_native("olds_cues_recording_stop", "native_stop")
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
bind_pcvar_num(create_cvar("olds_cues_max", "400", FCVAR_NONE,
"Most lines per cue file for one recording (10-10000).", true, 10.0, true, 10000.0), g_maxLines)
AutoExecConfig(true, "olds_cues")
register_concmd("olds_cues_start", "cmd_start", ADMIN_RCON, "[label] - the recording has started")
register_concmd("olds_cues_stop", "cmd_stop", ADMIN_RCON, "[failed] - the recording has stopped")
register_concmd("olds_cues_status", "cmd_status", ADMIN_CFG, "- recording state and the cue file")
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_post", true)
RegisterHookChain(RG_RoundEnd, "on_round_end_post", true)
get_mapname(g_map, charsmax(g_map))
new logs[128]
get_localinfo("amxx_logs", logs, charsmax(logs))
if (!logs[0])
copy(logs, charsmax(logs), "addons/amxmodx/logs")
formatex(g_path, charsmax(g_path), "%s/olds_cues_%s.txt", logs, g_map)
}
public plugin_end()
{
if (g_recording)
stop_recording("== map change: recording closed ==")
}
/* ---------- the adapter ---------- */
start_recording(const label[])
{
if (g_recording)
stop_recording("== recording restarted ==")
g_recording = true
g_failed = false
g_capped = false
g_lines = 0
g_start = get_gametime()
copy(g_label, charsmax(g_label), label)
new stamp[32]
get_time("%Y-%m-%d %H:%M:%S", stamp, charsmax(stamp))
write_raw(fmt("== recording started %s (%s)%s%s ==", stamp, g_map, g_label[0] ? " " : "", g_label))
}
stop_recording(const marker[])
{
if (!g_recording)
return
write_cue(marker, true)
g_recording = false
}
public cmd_start(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new label[64]
read_args(label, charsmax(label))
remove_quotes(label)
trim(label)
clean(label)
start_recording(label)
console_print(id, "[Cues] recording started; writing %s", g_path)
return PLUGIN_HANDLED
}
public cmd_stop(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
if (!g_recording)
{
console_print(id, "[Cues] no recording is running")
return PLUGIN_HANDLED
}
new reason[16]
read_argv(1, reason, charsmax(reason))
stop_recording(equali(reason, "failed") ? "== recording failed: stopped ==" : "== recording stopped ==")
console_print(id, "[Cues] recording stopped")
return PLUGIN_HANDLED
}
public native_start(plugin, params)
{
new label[64]
if (params >= 1)
get_string(1, label, charsmax(label))
clean(label)
start_recording(label)
return 1
}
public native_stop(plugin, params)
{
new bool:failed = params >= 1 && get_param(1) != 0
if (!g_recording)
return 0
stop_recording(failed ? "== recording failed: stopped ==" : "== recording stopped ==")
return 1
}
/* ---------- events ---------- */
public on_restart_round_post()
{
g_round++
if (g_recording)
write_cue(fmt("round %d start", g_round))
}
public on_round_end_post(WinStatus:status, ScenarioEventEndRound:event, Float:delay)
{
if (!g_recording || event == ROUND_GAME_COMMENCE || event == ROUND_GAME_RESTART)
return HC_CONTINUE
if (!get_member_game(m_bRoundTerminating))
return HC_CONTINUE
new winner[32]
switch (status)
{
case WINSTATUS_CTS: copy(winner, charsmax(winner), "Counter-Terrorists win")
case WINSTATUS_TERRORISTS: copy(winner, charsmax(winner), "Terrorists win")
case WINSTATUS_DRAW: copy(winner, charsmax(winner), "draw")
default: copy(winner, charsmax(winner), "no winner")
}
write_cue(fmt("round %d end: %s", g_round, winner))
return HC_CONTINUE
}
public bomb_planted(planter)
{
if (!g_recording)
return
new name[MAX_NAME_LENGTH]
player_name(planter, name, charsmax(name))
write_cue(fmt("bomb planted (%s)", name))
}
public bomb_defused(defuser)
{
if (!g_recording)
return
new name[MAX_NAME_LENGTH]
player_name(defuser, name, charsmax(name))
write_cue(fmt("bomb defused (%s)", name))
}
/* ---------- the file ---------- */
write_cue(const text[], bool:final = false)
{
if (g_failed || (g_capped && !final))
return
new elapsed = max(0, floatround(get_gametime() - g_start, floatround_floor))
new stamp[16]
if (elapsed >= 3600)
formatex(stamp, charsmax(stamp), "%d:%02d:%02d", elapsed / 3600, elapsed / 60 % 60, elapsed % 60)
else
formatex(stamp, charsmax(stamp), "%02d:%02d", elapsed / 60, elapsed % 60)
// The last line allowed says the limit was reached; the stop marker may still follow.
if (!final && g_lines == g_maxLines - 1)
{
g_capped = true
write_raw(fmt("%s == line limit (%d) reached: no more cues for this recording ==", stamp, g_maxLines))
return
}
write_raw(fmt("%s %s", stamp, text))
}
write_raw(const line[])
{
if (g_failed)
return
new file = fopen(g_path, "at")
if (!file)
{
g_failed = true
log_amx("Cannot write %s: no cues until the next recording starts", g_path)
return
}
fprintf(file, "%s^n", line)
fclose(file)
g_lines++
}
player_name(id, name[], len)
{
copy(name, len, "-")
if (1 <= id <= MaxClients && is_user_connected(id))
get_user_name(id, name, len)
}
/* Keeps a label to one plain line. */
clean(text[])
{
for (new i = 0; text[i]; i++)
if ((text[i] & 0xFF) < ' ' || text[i] == '=')
text[i] = ' '
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[Cues] %s; file %s; %d line(s) this recording, limit %d%s%s",
g_recording ? "recording" : "not recording", g_path, g_lines, g_maxLines,
g_capped ? ", limit reached" : "", g_failed ? ", WRITE FAILED" : "")
if (g_recording)
console_print(id, "[Cues] elapsed %d s, round %d, label %s",
floatround(get_gametime() - g_start, floatround_floor), g_round, g_label[0] ? g_label : "-")
return PLUGIN_HANDLED
}