Skip to content
View in the app

A better way to browse. Learn more.

Learn more

radio-digest/addons/amxmodx/scripting/olds_radiodigest.sma

olds_radiodigest.sma
328 lines · 10.4 KB · Pawn (AMX Mod X)
Raw
/*
 * Radio Digest (olds.ro workshop card AMX-027)
 *
 * A quieter radio for players who want it. A player types /radiodigest to
 * turn the digest on or off for themselves. While it is on, when a teammate
 * repeats the same radio call several times in a short time, the first calls
 * are heard as usual, the repeats are muted (sound and text), and when the
 * window closes one chat line sums them up:
 *
 *     Rex: Enemy spotted x4
 *
 * Players who did not turn the digest on hear every radio call unchanged.
 *
 * Grouping: calls of the same kind from the same teammate within
 * olds_digest_window seconds (counted from the first call) form one group.
 * Once a group reaches olds_digest_min calls, the further calls of that group
 * are muted for digest users, and the group ends with one digest line that
 * counts every call in it. A group that never reaches olds_digest_min ends
 * without a line, and nothing of it was muted.
 *
 * Chat command (chat and team chat, any letter case):
 *   /radiodigest   turns the digest on or off for you
 *
 * Cvars (in configs/plugins/olds_radiodigest.cfg, written with the defaults
 * on the first start if the file is missing):
 *   olds_digest_window 8   Seconds a group lasts, from its first call (2 - 60).
 *   olds_digest_min    3   Calls a group needs before repeats are muted and a
 *                          digest line is sent (2 - 20).
 *
 * How it works: the radio reaches each teammate as a SendAudio message (the
 * voice, as the card asks) and a TextMsg (the text); both are hooked with
 * register_message, counted once per call and muted per receiver. The card
 * also names the radio commands (register_clcmd); they are deliberately not
 * counted, because the game drops calls that come too fast (ReGameDLL's
 * mp_radio_timeout and mp_radio_maxinround) and counting the command would
 * count calls nobody heard. Counting the delivered messages covers the radio
 * menus, the direct commands and bots alike.
 * Groups are kept per sender and kind of call (bounded) and are dropped when
 * the sender changes team or leaves. Texts are in data/lang/olds_radiodigest.txt.
 *
 * Requires AMX Mod X 1.10 with the cstrike module (ships with AMX Mod X).
 * 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 <cstrike>

#pragma semicolon 1

new const PLUGIN_NAME[] = "Radio Digest";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";

// Task ids: TASK_CLOSE + sender * RADIO_COUNT + call.
const TASK_CLOSE = 27000;

// HUD_PRINTRADIO, the destination of the radio text in TextMsg.
const PRINT_RADIO = 5;

// Every radio call of the game: its voice (SendAudio), its text key
// (TextMsg), and the dictionary key of its name.
enum _:RadioCall
{
	RADIO_SOUND[24],
	RADIO_TEXT[32],
	RADIO_LABEL[24]
};

new const RADIO_CALLS[][RadioCall] =
{
	{ "%!MRAD_COVERME",     "#Cover_me",     "RADIO_COVERME" },
	{ "%!MRAD_TAKEPOINT",   "#You_take_the_point",   "RADIO_TAKEPOINT" },
	{ "%!MRAD_POSITION",    "#Hold_this_position",     "RADIO_POSITION" },
	{ "%!MRAD_REGROUP",     "#Regroup_team",     "RADIO_REGROUP" },
	{ "%!MRAD_FOLLOWME",    "#Follow_me",    "RADIO_FOLLOWME" },
	{ "%!MRAD_HITASSIST",   "#Taking_fire",  "RADIO_HITASSIST" },
	{ "%!MRAD_GO",          "#Go_go_go",          "RADIO_GO" },
	{ "%!MRAD_FALLBACK",    "#Team_fall_back",    "RADIO_FALLBACK" },
	{ "%!MRAD_STICKTOG",    "#Stick_together_team",    "RADIO_STICKTOG" },
	{ "%!MRAD_GETINPOS",    "#Get_in_position_and_wait",    "RADIO_GETINPOS" },
	{ "%!MRAD_STORMFRONT",  "#Storm_the_front",  "RADIO_STORMFRONT" },
	{ "%!MRAD_REPORTIN",    "#Report_in_team",      "RADIO_REPORTIN" },
	{ "%!MRAD_AFFIRM",      "#Affirmative",       "RADIO_AFFIRM" },
	{ "%!MRAD_ROGER",       "#Roger_that",       "RADIO_ROGER" },
	{ "%!MRAD_ENEMYSPOT",   "#Enemy_spotted",   "RADIO_ENEMYSPOT" },
	{ "%!MRAD_BACKUP",      "#Need_backup",  "RADIO_BACKUP" },
	{ "%!MRAD_CLEAR",       "#Sector_clear", "RADIO_CLEAR" },
	{ "%!MRAD_INPOS",       "#In_position",  "RADIO_INPOS" },
	{ "%!MRAD_REPRTINGIN",  "#Reporting_in", "RADIO_REPRTINGIN" },
	{ "%!MRAD_BLOW",        "#Get_out_of_there",      "RADIO_BLOW" },
	{ "%!MRAD_NEGATIVE",    "#Negative",    "RADIO_NEGATIVE" },
	{ "%!MRAD_ENEMYDOWN",   "#Enemy_down",   "RADIO_ENEMYDOWN" },
	{ "%!MRAD_FIREINHOLE",  "#Fire_in_the_hole",            "RADIO_FIREINHOLE" }
};

const RADIO_COUNT = sizeof(RADIO_CALLS);

new Float:g_window;      // olds_digest_window
new g_minCalls;          // olds_digest_min

new bool:g_digest[MAX_PLAYERS + 1];

// One group per sender and kind of call: how many calls, when it started,
// the sender's team when it started, and the game time of the last call
// counted (one call reaches every teammate in the same frame).
new g_groupCount[MAX_PLAYERS + 1][RADIO_COUNT];
new Float:g_groupStart[MAX_PLAYERS + 1][RADIO_COUNT];
new CsTeams:g_groupTeam[MAX_PLAYERS + 1][RADIO_COUNT];
new Float:g_lastCall[MAX_PLAYERS + 1][RADIO_COUNT];

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

	bind_pcvar_float(create_cvar("olds_digest_window", "8", FCVAR_NONE,
		"Seconds a group of repeated radio calls lasts, from its first call",
		true, 2.0, true, 60.0), g_window);

	bind_pcvar_num(create_cvar("olds_digest_min", "3", FCVAR_NONE,
		"Calls a group needs before repeats are muted and a digest line is sent",
		true, 2.0, true, 20.0), g_minCalls);

	AutoExecConfig(true, "olds_radiodigest");

	register_clcmd("say", "cmd_say");
	register_clcmd("say_team", "cmd_say");

	register_message(get_user_msgid("SendAudio"), "msg_send_audio");
	register_message(get_user_msgid("TextMsg"), "msg_text");

	// A team change ends the sender's groups.
	register_event("TeamInfo", "ev_team_info", "a");
}

public client_putinserver(id)
{
	g_digest[id] = false;
}

public client_disconnected(id)
{
	g_digest[id] = false;
	drop_groups(id);
}

public ev_team_info()
{
	new id = read_data(1);

	if (1 <= id <= MaxClients)
		drop_groups(id);
}

public cmd_say(id)
{
	new text[24];

	// Chat sends the whole line as one argument; a line that fills the buffer
	// is longer than the command.
	if (read_argc() != 2 || read_argv(1, text, charsmax(text)) >= charsmax(text))
		return PLUGIN_CONTINUE;

	trim(text);

	if (!equali(text, "/radiodigest"))
		return PLUGIN_CONTINUE;

	if (is_user_connected(id))
	{
		g_digest[id] = !g_digest[id];
		client_print_color(id, print_team_default, "%L", id, g_digest[id] ? "DIGEST_ON" : "DIGEST_OFF",
			g_minCalls, floatround(g_window));
	}

	return PLUGIN_HANDLED;
}

/**
 * The voice of a radio call, sent to one teammate: byte sender, string sound,
 * short pitch.
 */
public msg_send_audio(msgId, dest, receiver)
{
	if (dest != MSG_ONE && dest != MSG_ONE_UNRELIABLE)
		return PLUGIN_CONTINUE;

	new sender = get_msg_arg_int(1);

	if (!(1 <= sender <= MaxClients) || !is_user_connected(sender))
		return PLUGIN_CONTINUE;

	new sound[24];
	get_msg_arg_string(2, sound, charsmax(sound));

	new call = find_call(sound, RADIO_SOUND);

	if (call == -1)
		return PLUGIN_CONTINUE;

	note_call(sender, call);
	return should_mute(receiver, sender, call) ? PLUGIN_HANDLED : PLUGIN_CONTINUE;
}

/**
 * The text of a radio call, sent to one teammate:
 * byte HUD_PRINTRADIO, "sender index", "#Game_radio", name, "#Enemy_spotted".
 */
public msg_text(msgId, dest, receiver)
{
	if ((dest != MSG_ONE && dest != MSG_ONE_UNRELIABLE) || get_msg_args() < 5 || get_msg_arg_int(1) != PRINT_RADIO)
		return PLUGIN_CONTINUE;

	new value[32];
	get_msg_arg_string(2, value, charsmax(value));

	new sender = str_to_num(value);

	if (!(1 <= sender <= MaxClients) || !is_user_connected(sender))
		return PLUGIN_CONTINUE;

	get_msg_arg_string(5, value, charsmax(value));

	new call = find_call(value, RADIO_TEXT);

	if (call == -1)
		return PLUGIN_CONTINUE;

	note_call(sender, call);
	return should_mute(receiver, sender, call) ? PLUGIN_HANDLED : PLUGIN_CONTINUE;
}

find_call(const value[], field)
{
	for (new call = 0; call < RADIO_COUNT; call++)
	{
		if (equali(value, RADIO_CALLS[call][field]))
			return call;
	}

	return -1;
}

/**
 * Counts one call. The voice and the text of one call reach every teammate
 * in the same frame, so a call is counted once per game time.
 */
note_call(sender, call)
{
	new Float:now = get_gametime();

	if (g_lastCall[sender][call] == now)
		return;

	g_lastCall[sender][call] = now;

	new taskId = TASK_CLOSE + sender * RADIO_COUNT + call;

	// A new group starts with this call and closes after the window.
	if (!task_exists(taskId))
	{
		g_groupCount[sender][call] = 0;
		g_groupStart[sender][call] = now;
		g_groupTeam[sender][call] = cs_get_user_team(sender);
		set_task(g_window, "task_close_group", taskId);
	}

	g_groupCount[sender][call]++;
}

bool:should_mute(receiver, sender, call)
{
	return 1 <= receiver <= MaxClients && receiver != sender && g_digest[receiver]
		&& g_groupCount[sender][call] >= g_minCalls;
}

public task_close_group(taskId)
{
	new index = taskId - TASK_CLOSE;
	new sender = index / RADIO_COUNT;
	new call = index % RADIO_COUNT;

	new count = g_groupCount[sender][call];
	g_groupCount[sender][call] = 0;

	if (count < g_minCalls || !is_user_connected(sender))
		return;

	new CsTeams:team = cs_get_user_team(sender);

	if (team != g_groupTeam[sender][call])
		return;

	new name[MAX_NAME_LENGTH], label[48];
	get_user_name(sender, name, charsmax(name));

	for (new receiver = 1; receiver <= MaxClients; receiver++)
	{
		if (receiver == sender || !g_digest[receiver] || !is_user_connected(receiver) || cs_get_user_team(receiver) != team)
			continue;

		formatex(label, charsmax(label), "%L", receiver, RADIO_CALLS[call][RADIO_LABEL]);
		client_print_color(receiver, sender, "%L", receiver, "DIGEST_LINE", name, label, count);
	}
}

drop_groups(sender)
{
	for (new call = 0; call < RADIO_COUNT; call++)
	{
		remove_task(TASK_CLOSE + sender * RADIO_COUNT + call);
		g_groupCount[sender][call] = 0;
	}
}

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.