/*
* Distress Vocabulary (olds.ro) - Biohazard add-on. A living human opens a
* short menu of team requests with /help; the chosen request goes to every
* living human, each in their own language from the server dictionary.
*
* Copyright (C) 2026 daemon (olds.ro), written by daemon's plugin agent
*
* 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. You should have received a copy of the GNU General Public
* License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <amxmodx>
#pragma reqlib "biohazardf"
native is_user_zombie(index)
#define PLUGIN "Distress Vocabulary"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
// Dictionary keys of the requests, in menu order.
new const REQUESTS[][] =
{
"DISTRESS_AMMO",
"DISTRESS_BACKUP",
"DISTRESS_COVER",
"DISTRESS_FALLBACK",
"DISTRESS_HOLD",
"DISTRESS_ZOMBIES",
"DISTRESS_FOLLOW"
}
new g_menu[MAX_PLAYERS + 1] = { -1, ... } // the open menu, -1 = none
new Float:g_nextUse[MAX_PLAYERS + 1]
new g_cvarCooldown
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_distress.txt")
g_cvarCooldown = create_cvar("olds_distress_cd", "5", FCVAR_NONE, "Seconds between two requests from one player", true, 0.0, true, 120.0)
AutoExecConfig(true, "olds_distress")
register_clcmd("say /help", "cmd_help")
register_clcmd("say_team /help", "cmd_help")
register_event("DeathMsg", "on_death", "a")
}
bool:is_human(id)
{
return is_user_alive(id) && !is_user_zombie(id)
}
/* ---------- pending menus ---------- */
close_menu(id)
{
if (g_menu[id] < 0)
return
new menu = g_menu[id]
g_menu[id] = -1
if (is_user_connected(id))
{
new oldMenu, newMenu
player_menu_info(id, oldMenu, newMenu)
if (newMenu == menu)
show_menu(id, 0, "^n", 1) // take it off the screen
}
menu_destroy(menu)
}
public client_disconnected(id)
{
close_menu(id)
g_nextUse[id] = 0.0
}
// Biohazard forward: a player was infected.
public event_infect(victim, attacker)
{
if (1 <= victim <= MaxClients)
close_menu(victim)
}
public on_death()
{
new victim = read_data(2)
if (1 <= victim <= MaxClients)
close_menu(victim)
}
/* ---------- menu ---------- */
public cmd_help(id)
{
if (!is_human(id))
{
client_print(id, print_chat, "%L", id, "DISTRESS_ONLY_HUMANS")
return PLUGIN_HANDLED
}
new left = floatround(g_nextUse[id] - get_gametime(), floatround_ceil)
if (left > 0)
{
client_print(id, print_chat, "%L", id, "DISTRESS_COOLDOWN", left)
return PLUGIN_HANDLED
}
close_menu(id)
new title[64], item[64], info[4]
formatex(title, charsmax(title), "%L", id, "DISTRESS_MENU_TITLE")
new menu = menu_create(title, "on_menu")
for (new i = 0; i < sizeof(REQUESTS); i++)
{
formatex(item, charsmax(item), "%L", id, REQUESTS[i])
num_to_str(i, info, charsmax(info))
menu_additem(menu, item, info)
}
formatex(item, charsmax(item), "%L", id, "DISTRESS_MENU_EXIT")
menu_setprop(menu, MPROP_EXITNAME, item)
menu_setprop(menu, MPROP_PERPAGE, 0)
menu_setprop(menu, MPROP_EXIT, MEXIT_FORCE)
g_menu[id] = menu
menu_display(id, menu)
return PLUGIN_HANDLED
}
public on_menu(id, menu, item)
{
if (g_menu[id] != menu)
{
// The menu was closed (infection, death) and destroyed already, or it is stale.
return PLUGIN_HANDLED
}
g_menu[id] = -1
if (item < 0)
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new info[4], access, callback
menu_item_getinfo(menu, item, access, info, charsmax(info), _, _, callback)
menu_destroy(menu)
new request = str_to_num(info)
if (!(0 <= request < sizeof(REQUESTS)) || !is_human(id))
return PLUGIN_HANDLED
new left = floatround(g_nextUse[id] - get_gametime(), floatround_ceil)
if (left > 0)
{
client_print(id, print_chat, "%L", id, "DISTRESS_COOLDOWN", left)
return PLUGIN_HANDLED
}
g_nextUse[id] = get_gametime() + get_pcvar_float(g_cvarCooldown)
send_request(id, request)
return PLUGIN_HANDLED
}
send_request(id, request)
{
new name[32], players[MAX_PLAYERS], count, sent
get_user_name(id, name, charsmax(name))
get_players(players, count, "a")
for (new i = 0; i < count; i++)
{
new to = players[i]
if (is_user_zombie(to))
continue
// Each recipient reads it in their own language.
client_print_color(to, id, "^4[%L]^3 %s^1: %L", to, "DISTRESS_TAG", name, to, REQUESTS[request])
sent++
}
server_print("[Distress] %s: %L (%d living human(s))", name, LANG_SERVER, REQUESTS[request], sent)
}