/*
* Bomb Countdown Display (olds.ro workshop card LIB-0109)
*
* Once the bomb is planted, every player sees the seconds left before it
* explodes, counting down each second. Three styles: a plain number, a short
* text, or a number that turns red in the last 10 seconds. Each player can
* switch it off and on with /c4timer.
*
* Commands:
* say /c4timer, say_team /c4timer switch the countdown off or on for
* yourself
*
* Cvars (in configs/plugins/olds_c4timer.cfg, which ships with the plugin;
* if the file is missing, the plugin writes it with these defaults the first
* time it starts):
* olds_c4t_style 0 0 = number ("45"), 1 = text ("Bomb
* explodes in 45 s"), 2 = number that turns
* red in the last 10 seconds.
* olds_c4t_color "255 255 0" Colour (red green blue, 0-255).
* olds_c4t_x -1.0 Horizontal position (-1 = centre).
* olds_c4t_y 0.1 Vertical position (0.0 top, 1.0 bottom).
*
* Rules:
* - The countdown starts at the plant (mp_c4timer, 45 by default) and
* ends when the bomb is defused, explodes or the round restarts. It is
* never shown in the next round.
* - Every player sees it, dead players and spectators too, unless he
* switched it off with /c4timer (remembered until he leaves).
* - Each number lives 0.9 s. Director HUD texts cannot be cleared, so
* after a defuse the last number is gone within 0.9 s.
*
* How it works, as the card asks: on RG_PlantBomb (post) a 1 s repeating
* task reads the bomb's explode time (m_flC4Blow, through get_member) and
* prints the seconds left with set_dhudmessage.
*
* Requires AMX Mod X 1.10 with ReAPI (ReGameDLL_CS). 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 <reapi>
#pragma semicolon 1
new const PLUGIN_NAME[] = "Bomb Countdown Display";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
const TASK_TICK = 10900;
const Float:TICK = 1.0;
const Float:HOLD = 0.9;
// Style 2 turns red at this many seconds.
const RED_AT = 10;
enum
{
STYLE_NUMBER = 0,
STYLE_TEXT,
STYLE_RED_END
};
new g_style; // olds_c4t_style
new g_colorText[32]; // olds_c4t_color
new Float:g_x; // olds_c4t_x
new Float:g_y; // olds_c4t_y
// The planted bomb (0 = none).
new g_bomb;
new bool:g_hidden[MAX_PLAYERS + 1];
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
// The bomb hooks and members come from ReGameDLL_CS.
if (!is_regamedll())
set_fail_state("ReGameDLL_CS is not running. This plugin needs ReGameDLL_CS and ReAPI.");
register_dictionary("olds_c4timer.txt");
bind_pcvar_num(create_cvar("olds_c4t_style", "0", FCVAR_NONE,
"0 = number, 1 = text, 2 = number that turns red in the last 10 seconds",
true, 0.0, true, 2.0), g_style);
bind_pcvar_string(create_cvar("olds_c4t_color", "255 255 0", FCVAR_NONE,
"Colour of the countdown: red green blue (0-255)"),
g_colorText, charsmax(g_colorText));
bind_pcvar_float(create_cvar("olds_c4t_x", "-1.0", FCVAR_NONE,
"Horizontal position of the countdown (-1 = centre)",
true, -1.0, true, 1.0), g_x);
bind_pcvar_float(create_cvar("olds_c4t_y", "0.1", FCVAR_NONE,
"Vertical position of the countdown (0.0 top, 1.0 bottom)",
true, -1.0, true, 1.0), g_y);
AutoExecConfig(true, "olds_c4timer");
register_clcmd("say /c4timer", "cmd_toggle");
register_clcmd("say_team /c4timer", "cmd_toggle");
RegisterHookChain(RG_PlantBomb, "on_plant_bomb_post", true);
RegisterHookChain(RG_CGrenade_DefuseBombEnd, "on_defuse_end_post", true);
RegisterHookChain(RG_CGrenade_ExplodeBomb, "on_explode_bomb_pre", false);
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_post", true);
}
public client_putinserver(id)
{
g_hidden[id] = false;
}
public client_disconnected(id)
{
g_hidden[id] = false;
}
public cmd_toggle(id)
{
g_hidden[id] = !g_hidden[id];
client_print_color(id, print_team_default, "%L", id, g_hidden[id] ? "C4T_OFF" : "C4T_ON");
return PLUGIN_HANDLED;
}
public on_plant_bomb_post(planter, Float:origin[3], Float:velocity[3])
{
new bomb = GetHookChainReturn(ATYPE_INTEGER);
if (bomb <= 0)
return HC_CONTINUE;
g_bomb = bomb;
remove_task(TASK_TICK);
set_task(TICK, "task_tick", TASK_TICK, _, _, "b");
task_tick();
return HC_CONTINUE;
}
public on_defuse_end_post(bomb, defuser, bool:defused)
{
if (defused && bomb == g_bomb)
stop_countdown();
return HC_CONTINUE;
}
public on_explode_bomb_pre(bomb, trace, damageBits)
{
if (bomb == g_bomb)
stop_countdown();
return HC_CONTINUE;
}
public on_restart_round_post()
{
stop_countdown();
return HC_CONTINUE;
}
stop_countdown()
{
g_bomb = 0;
remove_task(TASK_TICK);
}
public task_tick()
{
if (!g_bomb || !is_entity(g_bomb) || !get_member(g_bomb, m_Grenade_bIsC4))
{
stop_countdown();
return;
}
new seconds = floatround(Float:get_member(g_bomb, m_Grenade_flC4Blow) - get_gametime(), floatround_ceil);
if (seconds <= 0)
return;
new red, green, blue;
parse_color(red, green, blue);
if (g_style == STYLE_RED_END && seconds <= RED_AT)
{
red = 255;
green = 0;
blue = 0;
}
set_dhudmessage(red, green, blue, g_x, g_y, 0, 0.0, HOLD, 0.0, 0.0);
for (new id = 1; id <= MaxClients; id++)
{
if (!is_user_connected(id) || g_hidden[id])
continue;
if (g_style == STYLE_TEXT)
show_dhudmessage(id, "%L", id, "C4T_TEXT", seconds);
else
show_dhudmessage(id, "%d", seconds);
}
}
parse_color(&red, &green, &blue)
{
new part[3][8];
red = 255;
green = 255;
blue = 0;
if (parse(g_colorText, part[0], charsmax(part[]), part[1], charsmax(part[]), part[2], charsmax(part[])) != 3)
return;
red = clamp(str_to_num(part[0]), 0, 255);
green = clamp(str_to_num(part[1]), 0, 255);
blue = clamp(str_to_num(part[2]), 0, 255);
}