/*
* Alive Voice Silence Window (olds.ro workshop card LIB-0068)
*
* For a while after a player dies, the living players cannot hear his
* voice, so the dead can talk among themselves without giving information
* away. Dead players and spectators still hear him.
*
* Commands:
* olds_vs_status (ADMIN_KICK, also from the server console) lists the
* players who are not alive and whether the living can
* hear them now.
*
* Cvars (in configs/plugins/olds_voicesilence.cfg, which ships with the
* plugin; if the file is missing, the plugin writes it with these defaults
* the first time it starts):
* olds_vs_enable 1 1 = the plugin is on.
* olds_vs_window 20 Seconds after a death during which the living
* cannot hear the dead player; 0 = for the whole
* time he is dead.
* olds_vs_admin 1 1 = admins (flag i, ADMIN_CHAT) are always heard.
*
* Rules:
* - It works on top of the game's own rules: with sv_alltalk 1 the
* living still do not hear a dead player or a spectator during the
* window. It never lets anyone hear more than the game allows.
* - The window starts when the player dies, joins the spectators or
* connects; it ends when he spawns again.
* - The state is checked every time, so a team change or a cvar change
* takes effect at once.
*
* How it works, as the card asks: the fakemeta forward
* FM_Voice_SetClientListening; when the listener is alive and the speaker
* is not (and in his window), the engine is told he cannot hear him.
*
* Requires AMX Mod X 1.10 with ReAPI (ReGameDLL_CS) and the fakemeta module.
* Written for AMX Mod X 1.10.0.5490, ReAPI 5.29.0.358 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>
#include <fakemeta>
#include <reapi>
#pragma semicolon 1
new const PLUGIN_NAME[] = "Alive Voice Silence Window";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
new g_enabled; // olds_vs_enable
new Float:g_window; // olds_vs_window
new g_adminHeard; // olds_vs_admin
// When each player stopped being alive.
new Float:g_deadSince[MAX_PLAYERS + 1];
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
if (!is_regamedll())
set_fail_state("ReGameDLL_CS is not running. This plugin needs ReGameDLL_CS and ReAPI.");
bind_pcvar_num(create_cvar("olds_vs_enable", "1", FCVAR_NONE,
"1 = for a while after a death the living cannot hear the dead player",
true, 0.0, true, 1.0), g_enabled);
bind_pcvar_float(create_cvar("olds_vs_window", "20", FCVAR_NONE,
"Seconds after a death during which the living cannot hear the dead player; 0 = the whole time he is dead",
true, 0.0, true, 600.0), g_window);
bind_pcvar_num(create_cvar("olds_vs_admin", "1", FCVAR_NONE,
"1 = admins (flag i) are always heard",
true, 0.0, true, 1.0), g_adminHeard);
AutoExecConfig(true, "olds_voicesilence");
register_concmd("olds_vs_status", "cmd_status", ADMIN_KICK, "- who the living can hear now");
register_forward(FM_Voice_SetClientListening, "on_set_client_listening", false);
RegisterHookChain(RG_CBasePlayer_Killed, "on_player_killed_post", true);
RegisterHookChain(RG_CBasePlayer_Spawn, "on_player_spawn_post", true);
}
public client_putinserver(id)
{
g_deadSince[id] = get_gametime();
}
public on_player_killed_post(victim, killer, gib)
{
g_deadSince[victim] = get_gametime();
return HC_CONTINUE;
}
public on_player_spawn_post(id)
{
// A player who leaves the game alive (to the spectators) starts a new
// window when he is next seen dead; see dead_since().
if (is_user_alive(id))
g_deadSince[id] = 0.0;
return HC_CONTINUE;
}
/**
* The game tells the engine whether the receiver hears the sender.
*/
public on_set_client_listening(receiver, sender, bool:listen)
{
if (!listen || !is_silenced(receiver, sender))
return FMRES_IGNORED;
engfunc(EngFunc_SetClientListening, receiver, sender, false);
forward_return(FMV_CELL, false);
return FMRES_SUPERCEDE;
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED;
console_print(id, "[Voice] olds_vs_enable %d, olds_vs_window %.0f, olds_vs_admin %d",
g_enabled, g_window, g_adminHeard);
new count = 0;
for (new player = 1; player <= MaxClients; player++)
{
if (!is_user_connected(player) || is_user_alive(player))
continue;
new Float:dead = get_gametime() - dead_since(player);
console_print(id, "[Voice] %n: not alive for %.0f s, the living %s", player, dead,
silenced_speaker(player) ? "cannot hear him" : "can hear him");
count++;
}
if (!count)
console_print(id, "[Voice] every player is alive");
return PLUGIN_HANDLED;
}
bool:is_silenced(receiver, sender)
{
if (receiver == sender || !is_user_connected(receiver) || !is_user_alive(receiver))
return false;
return silenced_speaker(sender);
}
/**
* True when the living cannot hear this player now.
*/
bool:silenced_speaker(sender)
{
if (!g_enabled || !is_user_connected(sender) || is_user_alive(sender))
return false;
if (g_adminHeard && (get_user_flags(sender) & ADMIN_CHAT))
return false;
return g_window <= 0.0 || get_gametime() - dead_since(sender) < g_window;
}
/**
* When the player stopped being alive. One who left the game alive (moved
* to the spectators without dying) counts from now on.
*/
Float:dead_since(id)
{
if (g_deadSince[id] <= 0.0)
g_deadSince[id] = get_gametime();
return g_deadSince[id];
}