/*
* Bomb Duty Queue (olds.ro workshop card AMX-021)
*
* During the freeze time a Terrorist who wants the bomb types /bombme. The
* bomb carrier types /bombduty and picks one of the volunteers from a menu;
* the bomb moves to that player at once (rg_transfer_c4) and both hear a short
* radio cue. It saves the usual "drop the bomb!" chat at round start.
*
* Each teammate can volunteer once per round. Requests are open from the new
* round until the freeze time ends, plus olds_bombduty_expire seconds; then
* they are cleared. When the carrier picks a name, everything is checked
* again: the carrier must still hold the bomb, the volunteer must still be a
* living Terrorist, and the game must confirm the handover. Otherwise nothing
* moves and the carrier is told why.
*
* Chat commands (chat and team chat, any letter case):
* /bombme volunteer to carry the bomb this round
* /bombduty (the bomb carrier) choose a volunteer from a menu
*
* Cvars (in configs/plugins/olds_bombduty.cfg, written with the defaults on
* the first start if the file is missing):
* olds_bombduty_expire 0 Seconds requests stay open after the freeze time
* ends (0 - 60; 0 = they end with the freeze time).
*
* The commands exist only on bomb maps. The cue is the stock
* radio/com_getinpos.wav. Texts are in data/lang/olds_bombduty.txt.
*
* Requires AMX Mod X 1.10 with ReAPI (ReGameDLL_CS). Written and tested on
* 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 Duty Queue";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
new const CUE_SOUND[] = "radio/com_getinpos";
const TASK_EXPIRE = 21021;
// Seconds the volunteer menu stays on screen.
const MENU_TIME = 15;
new g_expireSeconds; // olds_bombduty_expire
// Requests are accepted right now.
new bool:g_open;
// Who volunteered this round.
new bool:g_volunteer[MAX_PLAYERS + 1];
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
register_dictionary("olds_bombduty.txt");
bind_pcvar_num(create_cvar("olds_bombduty_expire", "0", FCVAR_NONE,
"Seconds bomb duty requests stay open after the freeze time ends (0 = they end with it)",
true, 0.0, true, 60.0), g_expireSeconds);
AutoExecConfig(true, "olds_bombduty");
// Only bomb maps have a bomb to hand over.
if (rg_find_ent_by_class(NULLENT, "func_bomb_target") == NULLENT
&& rg_find_ent_by_class(NULLENT, "info_bomb_target") == NULLENT)
return;
register_clcmd("say", "cmd_say");
register_clcmd("say_team", "cmd_say");
RegisterHookChain(RG_CSGameRules_RestartRound, "fw_restart_round_post", true);
RegisterHookChain(RG_CSGameRules_OnRoundFreezeEnd, "fw_freeze_end_post", true);
// A plugin loaded in the middle of a freeze time still takes requests.
g_open = bool:get_member_game(m_bFreezePeriod);
}
public client_disconnected(id)
{
g_volunteer[id] = false;
}
public fw_restart_round_post()
{
remove_task(TASK_EXPIRE);
clear_requests();
g_open = true;
return HC_CONTINUE;
}
public fw_freeze_end_post()
{
remove_task(TASK_EXPIRE);
if (g_expireSeconds > 0)
set_task(float(g_expireSeconds), "task_expire", TASK_EXPIRE);
else
task_expire();
return HC_CONTINUE;
}
public task_expire()
{
g_open = false;
clear_requests();
}
public cmd_say(id)
{
new text[16];
// Chat sends the whole line as one argument; a line that fills the buffer
// is longer than the commands.
if (read_argc() != 2 || read_argv(1, text, charsmax(text)) >= charsmax(text))
return PLUGIN_CONTINUE;
trim(text);
if (equali(text, "/bombme"))
{
if (is_user_connected(id))
volunteer(id);
return PLUGIN_HANDLED;
}
if (equali(text, "/bombduty"))
{
if (is_user_connected(id))
open_menu(id);
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
volunteer(id)
{
if (!is_user_alive(id) || get_member(id, m_iTeam) != TEAM_TERRORIST)
{
client_print_color(id, print_team_default, "%L", id, "BOMBDUTY_T_ONLY");
return;
}
if (!g_open)
{
client_print_color(id, print_team_default, "%L", id, "BOMBDUTY_CLOSED");
return;
}
if (get_member(id, m_bHasC4))
{
client_print_color(id, print_team_default, "%L", id, "BOMBDUTY_YOU_CARRY");
return;
}
if (g_volunteer[id])
{
client_print_color(id, print_team_default, "%L", id, "BOMBDUTY_ALREADY");
return;
}
g_volunteer[id] = true;
client_print_color(id, print_team_default, "%L", id, "BOMBDUTY_VOLUNTEERED");
new carrier = find_carrier();
if (carrier)
{
new name[MAX_NAME_LENGTH];
get_user_name(id, name, charsmax(name));
client_print_color(carrier, id, "%L", carrier, "BOMBDUTY_TO_CARRIER", name);
}
}
open_menu(id)
{
if (!is_user_alive(id) || !get_member(id, m_bHasC4))
{
client_print_color(id, print_team_default, "%L", id, "BOMBDUTY_NO_BOMB");
return;
}
if (!g_open)
{
client_print_color(id, print_team_default, "%L", id, "BOMBDUTY_CLOSED");
return;
}
new title[64];
formatex(title, charsmax(title), "%L", id, "BOMBDUTY_MENU_TITLE");
new menu = menu_create(title, "menu_bombduty");
new name[MAX_NAME_LENGTH], info[12], items;
// Each volunteer once; the user id identifies them when the answer comes.
for (new player = 1; player <= MaxClients; player++)
{
if (!g_volunteer[player] || player == id || !is_user_alive(player) || get_member(player, m_iTeam) != TEAM_TERRORIST)
continue;
get_user_name(player, name, charsmax(name));
num_to_str(get_user_userid(player), info, charsmax(info));
menu_additem(menu, name, info);
items++;
}
if (!items)
{
menu_destroy(menu);
client_print_color(id, print_team_default, "%L", id, "BOMBDUTY_NO_VOLUNTEERS");
return;
}
menu_display(id, menu, 0, MENU_TIME);
}
/**
* The carrier's choice. item is negative when the menu closed without one.
* Everything is checked again: time has passed since the menu opened.
*/
public menu_bombduty(id, menu, item)
{
if (item < 0 || !is_user_connected(id))
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new info[12], access, callback;
menu_item_getinfo(menu, item, access, info, charsmax(info), _, _, callback);
menu_destroy(menu);
if (!is_user_alive(id) || !get_member(id, m_bHasC4))
{
client_print_color(id, print_team_default, "%L", id, "BOMBDUTY_NO_CARRIER");
return PLUGIN_HANDLED;
}
if (!g_open)
{
client_print_color(id, print_team_default, "%L", id, "BOMBDUTY_CLOSED");
return PLUGIN_HANDLED;
}
new target = find_player("k", str_to_num(info));
new name[MAX_NAME_LENGTH];
if (!target || !is_user_alive(target) || get_member(target, m_iTeam) != TEAM_TERRORIST || !g_volunteer[target])
{
if (target)
get_user_name(target, name, charsmax(name));
else
copy(name, charsmax(name), "?");
client_print_color(id, print_team_default, "%L", id, "BOMBDUTY_REFUSED", name);
return PLUGIN_HANDLED;
}
get_user_name(target, name, charsmax(name));
if (!rg_transfer_c4(id, target) || !get_member(target, m_bHasC4))
{
client_print_color(id, print_team_default, "%L", id, "BOMBDUTY_FAILED");
return PLUGIN_HANDLED;
}
new carrierName[MAX_NAME_LENGTH];
get_user_name(id, carrierName, charsmax(carrierName));
client_print_color(id, target, "%L", id, "BOMBDUTY_HANDED", name);
client_print_color(target, id, "%L", target, "BOMBDUTY_RECEIVED", carrierName);
client_cmd(id, "spk %s", CUE_SOUND);
client_cmd(target, "spk %s", CUE_SOUND);
// The bomb has its new carrier: this round's requests are done.
clear_requests();
return PLUGIN_HANDLED;
}
find_carrier()
{
for (new player = 1; player <= MaxClients; player++)
{
if (is_user_alive(player) && get_member(player, m_bHasC4))
return player;
}
return 0;
}
clear_requests()
{
for (new player = 1; player <= MaxClients; player++)
g_volunteer[player] = false;
}