Skip to content
View in the app

A better way to browse. Learn more.

Learn more

map-debrief/addons/amxmodx/scripting/olds_debrief.sma

olds_debrief.sma
263 lines · 7.3 KB · Pawn (AMX Mod X)
Raw
/*
 * Map Debrief (olds.ro workshop card AMX-018)
 *
 * Collects one playtest note per player for the current map. A player types
 * /mapnote <text> in chat; typing it again replaces their note, so each
 * player ends the map with one final note. Admins read the notes live with
 * amx_mapnotes. When the map ends, the final notes are written to
 * addons/amxmodx/logs/olds_mapnotes_<map>.txt with the map name and the time,
 * one section per play of the map.
 *
 * Chat command (chat and team chat):
 *   /mapnote <text>   sets or replaces your note for this map
 *   /mapnote          shows your current note
 *
 * Console command (admins with the ADMIN_BAN flag, and the server console):
 *   amx_mapnotes      lists the notes of this map so far
 *
 * Cvars (in configs/plugins/olds_debrief.cfg, written with the defaults on
 * the first start if the file is missing):
 *   olds_debrief_len 120   Longest note in characters (10 - 180); a longer
 *                          note is cut and the player is told.
 *
 * Notes are kept by Steam ID, so a player who reconnects replaces their own
 * note; players without a lasting Steam ID (bots, LAN IDs) are kept by name.
 * At most 64 notes are kept per map. If the file cannot be written at the end
 * of the map, one line says so in the server console and the AMX Mod X log.
 * Texts are in data/lang/olds_debrief.txt.
 *
 * Requires AMX Mod X 1.10; no extra modules and no ReAPI. Written and tested
 * on AMX Mod X 1.10.0.5490, ReHLDS 3.15.0.896 and ReGameDLL_CS 5.30.0.814.
 *
 * 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[] = "Map Debrief";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";

new const COMMAND[] = "/mapnote";

// Notes kept per map.
const MAX_NOTES = 64;

// Longest note the cvar allows, and the buffer that holds it.
const MAX_NOTE_LENGTH = 180;

// Room for the command and a note in one chat line.
const CHAT_LENGTH = 192;

new g_noteLength;    // olds_debrief_len

new g_noteCount;
new g_noteKey[MAX_NOTES][MAX_AUTHID_LENGTH + MAX_NAME_LENGTH];
new g_noteName[MAX_NOTES][MAX_NAME_LENGTH];
new g_noteText[MAX_NOTES][MAX_NOTE_LENGTH + 1];
new g_noteTime[MAX_NOTES];

new g_mapName[32];

public plugin_init()
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
	register_dictionary("olds_debrief.txt");

	bind_pcvar_num(create_cvar("olds_debrief_len", "120", FCVAR_NONE,
		"Longest map note in characters; longer notes are cut",
		true, 10.0, true, float(MAX_NOTE_LENGTH)), g_noteLength);

	AutoExecConfig(true, "olds_debrief");

	register_clcmd("say", "cmd_say");
	register_clcmd("say_team", "cmd_say");
	register_concmd("amx_mapnotes", "cmd_mapnotes", ADMIN_BAN, "- list the playtest notes of this map");

	get_mapname(g_mapName, charsmax(g_mapName));
}

public plugin_end()
{
	if (g_noteCount > 0)
		write_notes();
}

public cmd_say(id)
{
	new line[CHAT_LENGTH];

	if (read_argc() != 2)
		return PLUGIN_CONTINUE;

	read_argv(1, line, charsmax(line));
	trim(line);

	// The command, alone or followed by a space and the note.
	new commandLength = sizeof(COMMAND) - 1;

	if (!equali(line, COMMAND, commandLength) || (line[commandLength] != EOS && line[commandLength] != ' '))
		return PLUGIN_CONTINUE;

	if (!is_user_connected(id))
		return PLUGIN_HANDLED;

	new note[CHAT_LENGTH];
	copy(note, charsmax(note), line[commandLength]);
	trim(note);

	if (!note[0])
		show_own_note(id);
	else
		set_note(id, note);

	// The note is for the admins, not for the chat.
	return PLUGIN_HANDLED;
}

public cmd_mapnotes(id, level, cid)
{
	if (!cmd_access(id, level, cid, 1))
		return PLUGIN_HANDLED;

	if (!g_noteCount)
	{
		console_print(id, "%L", id, "DEBRIEF_LIST_EMPTY", g_mapName);
		return PLUGIN_HANDLED;
	}

	console_print(id, "%L", id, "DEBRIEF_LIST_HEAD", g_mapName, g_noteCount);

	new clock[16];

	for (new note = 0; note < g_noteCount; note++)
	{
		format_time(clock, charsmax(clock), "%H:%M:%S", g_noteTime[note]);
		console_print(id, "%L", id, "DEBRIEF_LIST_LINE", note + 1, g_noteName[note], clock, g_noteText[note]);
	}

	return PLUGIN_HANDLED;
}

set_note(id, note[])
{
	new bool:cut = strlen(note) > g_noteLength;

	if (cut)
		note[g_noteLength] = EOS;

	new key[sizeof(g_noteKey[])];
	note_key(id, key, charsmax(key));

	new slot = find_note(key);
	new bool:revised = slot != -1;

	if (!revised)
	{
		if (g_noteCount >= MAX_NOTES)
		{
			client_print_color(id, print_team_default, "%L", id, "DEBRIEF_FULL", MAX_NOTES);
			return;
		}

		slot = g_noteCount++;
		copy(g_noteKey[slot], charsmax(g_noteKey[]), key);
	}

	get_user_name(id, g_noteName[slot], charsmax(g_noteName[]));
	copy(g_noteText[slot], charsmax(g_noteText[]), note);
	g_noteTime[slot] = get_systime();

	client_print_color(id, print_team_default, "%L", id, revised ? "DEBRIEF_REVISED" : "DEBRIEF_SAVED", g_mapName);

	if (cut)
		client_print_color(id, print_team_default, "%L", id, "DEBRIEF_CUT", g_noteLength);
}

show_own_note(id)
{
	new key[sizeof(g_noteKey[])];
	note_key(id, key, charsmax(key));

	new slot = find_note(key);

	if (slot == -1)
		client_print_color(id, print_team_default, "%L", id, "DEBRIEF_USAGE", g_noteLength);
	else
		client_print_color(id, print_team_default, "%L", id, "DEBRIEF_YOURS", g_noteText[slot]);
}

find_note(const key[])
{
	for (new note = 0; note < g_noteCount; note++)
	{
		if (equal(g_noteKey[note], key))
			return note;
	}

	return -1;
}

/**
 * Steam ID when it lasts between visits; otherwise the name, so bots and LAN
 * players (who share one ID) each keep their own note.
 */
note_key(id, key[], length)
{
	new authid[MAX_AUTHID_LENGTH];
	get_user_authid(id, authid, charsmax(authid));

	if (!is_user_bot(id) && equal(authid, "STEAM_", 6) && !equal(authid, "STEAM_ID_LAN") && !equal(authid, "STEAM_ID_PENDING"))
	{
		copy(key, length, authid);
		return;
	}

	new name[MAX_NAME_LENGTH];
	get_user_name(id, name, charsmax(name));
	formatex(key, length, "name:%s", name);
}

write_notes()
{
	new path[128];
	get_localinfo("amxx_logs", path, charsmax(path));
	format(path, charsmax(path), "%s/olds_mapnotes_%s.txt", path, g_mapName);

	// Each play of the map adds its own section.
	new file = fopen(path, "at");

	if (!file)
	{
		server_print("[Map Debrief] Could not write %s; %d note(s) of this map were not saved.", path, g_noteCount);
		log_amx("Could not write %s; %d note(s) of this map were not saved.", path, g_noteCount);
		return;
	}

	new clock[32];
	format_time(clock, charsmax(clock), "%Y-%m-%d %H:%M:%S", get_systime());
	fprintf(file, "Map debrief for %s, written %s, %d note(s)^n", g_mapName, clock, g_noteCount);

	for (new note = 0; note < g_noteCount; note++)
	{
		format_time(clock, charsmax(clock), "%H:%M:%S", g_noteTime[note]);
		fprintf(file, "%s  %s: %s^n", clock, g_noteName[note], g_noteText[note]);
	}

	fprintf(file, "^n");
	fclose(file);
}

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.