/*
* Death Message Blocker (olds.ro workshop card LIB-1551)
*
* Hides chosen lines of the kill feed (the list of kills at the top right),
* for example knife kills or suicides, and leaves every other line as it is.
* Only the kill-feed line is hidden: the kill itself, the frag and the death
* on the scoreboard count as usual.
*
* What is hidden is listed in addons/amxmodx/configs/olds_deathblock.ini,
* one entry per line:
* knife, grenade, awp, ... kills with that weapon (the name the kill feed
* uses; "weapon_knife" works too)
* suicide a player killed themselves (console "kill",
* own grenade, ...)
* team a player killed a teammate (not with
* mp_freeforall 1, where there are no teammates)
* world deaths without a killing player (falls,
* trigger_hurt, the bomb, ...)
*
* Cvar (saved with its description in configs/plugins/olds_deathblock.cfg the
* first time the plugin starts):
* olds_dblock_log 0 1 = write every hidden line to the AMXX log.
*
* Admin command (ADMIN_CFG, flag "h"; also from the server console):
* amx_dblock_reload reads olds_deathblock.ini again, without a map change
*
* Requires AMX Mod X 1.10 or newer. No extra modules; ReAPI is not used.
*
* 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[] = "Death Message Blocker";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
new const DICTIONARY[] = "olds_deathblock.txt";
new const LIST_FILE[] = "olds_deathblock.ini";
// Longest weapon name kept from the list or a DeathMsg.
const WEAPON_LENGTH = 32;
// Why a kill-feed line is hidden.
enum _:BlockFlag (<<= 1)
{
BLOCK_SUICIDE = 1,
BLOCK_TEAM,
BLOCK_WORLD
};
new g_log; // olds_dblock_log
// Weapon names on the list (keys only).
new Trie:g_weapons;
new g_weaponCount;
new g_flags;
new g_pcvarFreeForAll;
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
register_dictionary(DICTIONARY);
bind_pcvar_num(create_cvar("olds_dblock_log", "0", FCVAR_NONE,
"1 = write every hidden kill-feed line to the AMXX log, 0 = do not log",
true, 0.0, true, 1.0), g_log);
AutoExecConfig(true, "olds_deathblock");
register_concmd("amx_dblock_reload", "cmd_reload", ADMIN_CFG, "OLDS_DBLOCK_HELP", -1, true);
// ReGameDLL_CS only; 0 when the cvar does not exist.
g_pcvarFreeForAll = get_cvar_pointer("mp_freeforall");
g_weapons = TrieCreate();
load_list();
register_message(get_user_msgid("DeathMsg"), "msg_death");
}
public plugin_end()
{
TrieDestroy(g_weapons);
}
public cmd_reload(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED;
if (load_list())
console_print(id, "%L", id, "OLDS_DBLOCK_RELOADED", g_weaponCount, flag_count());
else
console_print(id, "%L", id, "OLDS_DBLOCK_NO_FILE", LIST_FILE);
return PLUGIN_HANDLED;
}
/**
* DeathMsg: killer (byte), victim (byte), headshot (byte), weapon (string).
*/
public msg_death(msgId, dest, receiver)
{
new killer = get_msg_arg_int(1);
new victim = get_msg_arg_int(2);
new weapon[WEAPON_LENGTH];
get_msg_arg_string(4, weapon, charsmax(weapon));
strtolower(weapon);
new reason[32];
if (!get_block_reason(killer, victim, weapon, reason, charsmax(reason)))
return PLUGIN_CONTINUE;
if (g_log)
{
new killerName[MAX_NAME_LENGTH], victimName[MAX_NAME_LENGTH];
if (is_player(killer))
get_user_name(killer, killerName, charsmax(killerName));
else
copy(killerName, charsmax(killerName), "world");
if (is_player(victim))
get_user_name(victim, victimName, charsmax(victimName));
// Not in the "X" killed "Y" form of the game's own log lines, so log
// readers (HLstatsX, PsychoStats) cannot count it as a second kill.
log_amx("Hidden kill-feed line: ^"%s^" -> ^"%s^", weapon %s (%s)", killerName, victimName, weapon, reason);
}
return PLUGIN_HANDLED;
}
/**
* Returns true and the reason if this kill-feed line is on the list.
*/
bool:get_block_reason(killer, victim, const weapon[], reason[], maxLength)
{
if (g_weaponCount && weapon[0] && TrieKeyExists(g_weapons, weapon))
{
formatex(reason, maxLength, "weapon %s", weapon);
return true;
}
if (!is_player(killer))
{
copy(reason, maxLength, "world");
return (g_flags & BLOCK_WORLD) != 0;
}
if (killer == victim)
{
copy(reason, maxLength, "suicide");
return (g_flags & BLOCK_SUICIDE) != 0;
}
if ((g_flags & BLOCK_TEAM) && is_player(victim) && is_team_kill(killer, victim))
{
copy(reason, maxLength, "team kill");
return true;
}
return false;
}
bool:is_team_kill(killer, victim)
{
if (g_pcvarFreeForAll && get_pcvar_num(g_pcvarFreeForAll))
return false;
new team = get_user_team(killer);
return team > 0 && team == get_user_team(victim);
}
bool:is_player(id)
{
return 1 <= id <= MaxClients;
}
/**
* Reads the list. Returns false if the file does not exist (the list is then
* empty and nothing is hidden).
*/
bool:load_list()
{
TrieClear(g_weapons);
g_weaponCount = 0;
g_flags = 0;
new path[PLATFORM_MAX_PATH];
get_configsdir(path, charsmax(path));
format(path, charsmax(path), "%s/%s", path, LIST_FILE);
new file = fopen(path, "rt");
if (!file)
{
log_amx("%s not found: no kill-feed line is hidden.", path);
return false;
}
new line[128], lineNumber;
while (fgets(file, line, charsmax(line)))
{
lineNumber++;
trim(line);
strtolower(line);
if (!line[0] || line[0] == ';' || line[0] == '#' || (line[0] == '/' && line[1] == '/'))
continue;
if (equal(line, "suicide"))
g_flags |= BLOCK_SUICIDE;
else if (equal(line, "team"))
g_flags |= BLOCK_TEAM;
else if (equal(line, "world"))
g_flags |= BLOCK_WORLD;
else if (is_weapon_name(line))
{
// The kill feed names weapons without the "weapon_" prefix.
new start = equal(line, "weapon_", 7) ? 7 : 0;
if (strlen(line[start]) >= WEAPON_LENGTH)
{
log_amx("%s line %d: ^"%s^" is too long for a weapon name and was skipped.", path, lineNumber, line);
continue;
}
if (!TrieKeyExists(g_weapons, line[start]))
{
TrieSetCell(g_weapons, line[start], 1);
g_weaponCount++;
}
}
else
{
log_amx("%s line %d: ^"%s^" is not a weapon name or suicide, team, world, and was skipped.",
path, lineNumber, line);
}
}
fclose(file);
return true;
}
/**
* A weapon name is one word of letters, digits and _.
*/
bool:is_weapon_name(const text[])
{
for (new i = 0; text[i]; i++)
{
if (!isalnum(text[i]) && text[i] != '_')
return false;
}
return text[0] != EOS;
}
flag_count()
{
return ((g_flags & BLOCK_SUICIDE) ? 1 : 0) + ((g_flags & BLOCK_TEAM) ? 1 : 0) + ((g_flags & BLOCK_WORLD) ? 1 : 0);
}