/*
* C4 Death Icon (olds.ro workshop card LIB-0150)
*
* When the bomb's explosion kills someone, the kill feed shows the C4 icon
* instead of the grenade icon or a skull. Optionally the planter gets the
* frag for each enemy the bomb kills.
*
* Commands: none.
*
* Cvars (in configs/plugins/olds_c4icon.cfg, which ships with the plugin; if
* the file is missing, the plugin writes it with these defaults the first
* time it starts):
* olds_ci_enable 1 1 = bomb deaths show the C4 icon.
* olds_ci_credit 1 1 = the planter gets +1 frag for each enemy the bomb
* kills and is shown as the killer in the feed.
*
* Rules:
* - Only a death caused by the bomb's own blast counts. A grenade, a fall
* or a bullet in the same moment keeps its own icon.
* - No frag for the planter's own death or for a teammate's. If the game
* itself already names the planter as the killer, no extra frag is
* given.
* - Bots and humans are treated the same.
*
* How it works, as the card asks: RG_CGrenade_ExplodeBomb (pre) marks the
* moment of the blast; RG_CBasePlayer_TakeDamage (pre) remembers what hurt
* each player last. register_message on DeathMsg then rewrites the weapon
* to "c4" with set_msg_arg_string when the victim was killed by the bomb
* within 0.1 s of the blast. The frag is added after the death (Killed
* post) with Ham_AddPoints, which also updates the scoreboard.
*
* Requires AMX Mod X 1.10 with ReAPI (ReGameDLL_CS) and the hamsandwich
* 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 <hamsandwich>
#include <reapi>
#pragma semicolon 1
new const PLUGIN_NAME[] = "C4 Death Icon";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
// A bomb death must come this soon after the blast.
const Float:BLAST_WINDOW = 0.1;
new g_enabled; // olds_ci_enable
new g_credit; // olds_ci_credit
new g_bomb; // the bomb planted last
new g_planterUserId; // its planter's userid, 0 = unknown
new Float:g_blastTime = -1.0;
new g_lastInflictor[MAX_PLAYERS + 1];
new Float:g_lastHurtTime[MAX_PLAYERS + 1];
// The game already named the planter as the killer of this victim.
new bool:g_gameCredited[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_ci_enable", "1", FCVAR_NONE,
"1 = bomb deaths show the C4 icon in the kill feed",
true, 0.0, true, 1.0), g_enabled);
bind_pcvar_num(create_cvar("olds_ci_credit", "1", FCVAR_NONE,
"1 = the planter gets +1 frag for each enemy the bomb kills",
true, 0.0, true, 1.0), g_credit);
AutoExecConfig(true, "olds_c4icon");
register_message(get_user_msgid("DeathMsg"), "on_death_msg");
RegisterHookChain(RG_PlantBomb, "on_plant_bomb_post", true);
RegisterHookChain(RG_CGrenade_ExplodeBomb, "on_explode_bomb_pre", false);
RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_pre", false);
RegisterHookChain(RG_CBasePlayer_Killed, "on_player_killed_post", true);
}
public on_plant_bomb_post(id, Float:origin[3], Float:velocity[3])
{
new bomb = GetHookChainReturn(ATYPE_INTEGER);
if (bomb > 0)
{
g_bomb = bomb;
g_planterUserId = is_user_connected(id) ? get_user_userid(id) : 0;
}
return HC_CONTINUE;
}
public on_explode_bomb_pre(bomb)
{
if (bomb == g_bomb)
g_blastTime = get_gametime();
return HC_CONTINUE;
}
public on_take_damage_pre(victim, inflictor, attacker, Float:damage, damageBits)
{
g_lastInflictor[victim] = inflictor;
g_lastHurtTime[victim] = get_gametime();
return HC_CONTINUE;
}
/**
* DeathMsg: killer, victim, headshot, weapon.
*/
public on_death_msg(msgId, msgDest, msgEntity)
{
new victim = get_msg_arg_int(2);
if (!g_enabled || !killed_by_bomb(victim))
return PLUGIN_CONTINUE;
set_msg_arg_string(4, "c4");
new planter = planter_index();
g_gameCredited[victim] = (planter && get_msg_arg_int(1) == planter);
if (credit_due(planter, victim) && !g_gameCredited[victim])
set_msg_arg_int(1, ARG_BYTE, planter);
return PLUGIN_CONTINUE;
}
/**
* The frag is added after the death message, outside it.
*/
public on_player_killed_post(victim, killer, gib)
{
if (!g_enabled || !(1 <= victim <= MaxClients) || !killed_by_bomb(victim))
return HC_CONTINUE;
new planter = planter_index();
if (credit_due(planter, victim) && !g_gameCredited[victim])
ExecuteHamB(Ham_AddPoints, planter, 1, false);
g_gameCredited[victim] = false;
return HC_CONTINUE;
}
bool:killed_by_bomb(victim)
{
if (!(1 <= victim <= MaxClients) || !g_bomb || g_blastTime < 0.0)
return false;
new Float:now = get_gametime();
return g_lastInflictor[victim] == g_bomb
&& now - g_blastTime <= BLAST_WINDOW
&& now - g_lastHurtTime[victim] <= BLAST_WINDOW;
}
/**
* The planter gets the frag for an enemy, never for himself or a teammate.
*/
bool:credit_due(planter, victim)
{
return g_credit && planter && planter != victim
&& get_member(planter, m_iTeam) != get_member(victim, m_iTeam);
}
planter_index()
{
if (!g_planterUserId)
return 0;
new planter = find_player_ex(FindPlayer_MatchUserId, g_planterUserId);
return (planter > 0 && is_user_connected(planter)) ? planter : 0;
}