/*
* Buyable Antidote (olds.ro workshop card LIB-0031) - Biohazard add-on
*
* An infected player may buy an antidote with money and turn back into a human:
* say /antidote, olds_ad_cost dollars, olds_ad_limit times per round, not sooner than
* olds_ad_delay seconds after the infection. With olds_ad_firstzombie 0 the first
* zombies of the round (infected by the game, without an attacker) cannot buy it.
*
* Needs the Biohazard Zombie Core (library "olds_biohazard", include/olds_biohazard.inc,
* workshop card LIB-0030): bh_cure, bh_is_zombie and the forward bh_fw_infected. After
* the cure the human model is put back and the health set to 100.
*
* Cvars: olds_ad_cost 5000, olds_ad_limit 1, olds_ad_delay 5, olds_ad_firstzombie 1.
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <cstrike>
#include <reapi>
#include <olds_biohazard>
#define PLUGIN "Buyable Antidote"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
#define SND_CURE "items/medshot4.wav"
new g_cost, g_limit, Float:g_delay, g_firstAllowed;
new g_bought[MAX_PLAYERS + 1]; // antidotes this round
new bool:g_first[MAX_PLAYERS + 1]; // a first zombie of the round (no attacker)
new Float:g_infectedAt[MAX_PLAYERS + 1];
new Float:g_nextUse[MAX_PLAYERS + 1];
public plugin_precache()
{
precache_sound(SND_CURE);
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_dictionary("olds_antidote.txt");
bind_pcvar_num(create_cvar("olds_ad_cost", "5000", FCVAR_NONE,
"Price of the antidote in dollars", true, 0.0, true, 16000.0), g_cost);
bind_pcvar_num(create_cvar("olds_ad_limit", "1", FCVAR_NONE,
"Antidotes one player may buy per round", true, 1.0, true, 10.0), g_limit);
bind_pcvar_float(create_cvar("olds_ad_delay", "5", FCVAR_NONE,
"Seconds after the infection before the antidote can be bought", true, 0.0, true, 120.0), g_delay);
bind_pcvar_num(create_cvar("olds_ad_firstzombie", "1", FCVAR_NONE,
"0 = the first zombies of the round cannot buy it", true, 0.0, true, 1.0), g_firstAllowed);
AutoExecConfig(true, "olds_antidote");
register_clcmd("say /antidote", "cmd_antidote");
register_clcmd("say_team /antidote", "cmd_antidote");
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round", false);
RegisterHookChain(RG_CBasePlayer_Killed, "on_killed", true);
}
/* ---------- core events ---------- */
public bh_fw_infected(victim, attacker)
{
if (!(1 <= victim <= MaxClients))
return;
g_infectedAt[victim] = get_gametime();
g_first[victim] = (attacker == 0);
}
public bh_fw_cured(id)
{
if (1 <= id <= MaxClients)
g_first[id] = false;
}
public on_restart_round()
{
for (new id = 1; id <= MaxClients; id++)
{
g_bought[id] = 0;
g_first[id] = false;
g_infectedAt[id] = 0.0;
}
}
public on_killed(victim)
{
if (1 <= victim <= MaxClients)
{
g_first[victim] = false;
g_infectedAt[victim] = 0.0;
}
return HC_CONTINUE;
}
public client_disconnected(id)
{
g_bought[id] = 0;
g_first[id] = false;
g_infectedAt[id] = 0.0;
g_nextUse[id] = 0.0;
}
/* ---------- the antidote ---------- */
public cmd_antidote(id)
{
if (!is_user_connected(id))
return PLUGIN_HANDLED;
new Float:now = get_gametime();
if (now < g_nextUse[id])
return PLUGIN_HANDLED;
g_nextUse[id] = now + 1.0;
if (!is_user_alive(id) || !bh_is_zombie(id))
{
client_print_color(id, print_team_default, "^4[Antidote]^1 %L", id, "AD_NOT_INFECTED");
return PLUGIN_HANDLED;
}
if (g_first[id] && !g_firstAllowed)
{
client_print_color(id, print_team_default, "^4[Antidote]^1 %L", id, "AD_FIRST");
return PLUGIN_HANDLED;
}
if (g_bought[id] >= g_limit)
{
client_print_color(id, print_team_default, "^4[Antidote]^1 %L", id, "AD_LIMIT", g_limit);
return PLUGIN_HANDLED;
}
new Float:wait = g_infectedAt[id] + g_delay - now;
if (g_infectedAt[id] > 0.0 && wait > 0.0)
{
client_print_color(id, print_team_default, "^4[Antidote]^1 %L", id, "AD_WAIT",
floatround(wait, floatround_ceil));
return PLUGIN_HANDLED;
}
new money = cs_get_user_money(id);
if (money < g_cost)
{
client_print_color(id, print_team_default, "^4[Antidote]^1 %L", id, "AD_MONEY", g_cost, g_cost - money);
return PLUGIN_HANDLED;
}
if (!bh_cure(id))
{
client_print_color(id, print_team_default, "^4[Antidote]^1 %L", id, "AD_FAILED");
return PLUGIN_HANDLED;
}
// Paid only for a cure that worked.
cs_set_user_money(id, money - g_cost);
g_bought[id]++;
g_first[id] = false;
g_infectedAt[id] = 0.0;
if (is_user_alive(id))
{
cs_reset_user_model(id);
set_entvar(id, var_health, 100.0);
}
emit_sound(id, CHAN_ITEM, SND_CURE, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
new name[MAX_NAME_LENGTH];
get_user_name(id, name, charsmax(name));
client_print_color(0, id, "^4[Antidote]^1 %l", "AD_CURED", name);
log_amx("%s bought an antidote for $%d", name, g_cost);
return PLUGIN_HANDLED;
}