/*
* Armor Charger Helmet Grant (olds.ro workshop card LIB-0083)
*
* Using a wall armor charger (func_recharge) also gives a helmet once the
* charger has topped the armor up to 100.
*
* Commands: none.
*
* Cvars (in configs/plugins/olds_chargerhelmet.cfg, which ships with the
* plugin; if the file is missing, the plugin writes it with these defaults
* the first time it starts):
* olds_hc_enable 1 1 = the plugin is on.
* olds_hc_msg 1 1 = the player gets a chat line when the helmet is
* added.
* olds_hc_fullonly 1 1 = the helmet comes only when the charger brings
* the armor to 100; 0 = as soon as the charger gives
* any armor.
*
* Rules:
* - The helmet comes with armor the charger really gives: a player whose
* armor is already 100, or who uses an empty charger, gets nothing.
* - A player who already has a helmet is left alone: no second message,
* the armor type stays the same.
* - Dead players and spectators are never processed.
* - On a map without chargers the plugin does nothing.
*
* How it works, as the card asks: Ham_Use on func_recharge. Before the use
* the player's armor is kept; after it, when the armor went up (to 100 or
* more with olds_hc_fullonly 1), cs_set_user_armor(id, armor,
* CS_ARMOR_VESTHELM) adds the helmet and updates the HUD icon.
*
* Requires AMX Mod X 1.10 with the hamsandwich, cstrike and fakemeta modules.
* Written for AMX Mod X 1.10.0.5490 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 <cstrike>
#include <fakemeta>
#include <hamsandwich>
#pragma semicolon 1
new const PLUGIN_NAME[] = "Armor Charger Helmet Grant";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
new g_enabled; // olds_hc_enable
new g_message; // olds_hc_msg
new g_fullOnly; // olds_hc_fullonly
// Armor before the charger's use, -1.0 = no use in progress.
new Float:g_armorBefore[MAX_PLAYERS + 1] = { -1.0, ... };
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
register_dictionary("olds_chargerhelmet.txt");
bind_pcvar_num(create_cvar("olds_hc_enable", "1", FCVAR_NONE,
"1 = a wall armor charger also gives a helmet",
true, 0.0, true, 1.0), g_enabled);
bind_pcvar_num(create_cvar("olds_hc_msg", "1", FCVAR_NONE,
"1 = the player gets a chat line when the helmet is added",
true, 0.0, true, 1.0), g_message);
bind_pcvar_num(create_cvar("olds_hc_fullonly", "1", FCVAR_NONE,
"1 = the helmet comes only when the charger brings the armor to 100; 0 = with any armor from the charger",
true, 0.0, true, 1.0), g_fullOnly);
AutoExecConfig(true, "olds_chargerhelmet");
RegisterHam(Ham_Use, "func_recharge", "on_charger_use_pre", false);
RegisterHam(Ham_Use, "func_recharge", "on_charger_use_post", true);
}
public client_disconnected(id)
{
g_armorBefore[id] = -1.0;
}
public on_charger_use_pre(charger, caller, activator, useType, Float:value)
{
new id = charger_user(caller, activator);
if (id)
g_armorBefore[id] = Float:pev(id, pev_armorvalue);
return HAM_IGNORED;
}
public on_charger_use_post(charger, caller, activator, useType, Float:value)
{
new id = charger_user(caller, activator);
if (!id || g_armorBefore[id] < 0.0)
return HAM_IGNORED;
new Float:before = g_armorBefore[id];
g_armorBefore[id] = -1.0;
new Float:armor = Float:pev(id, pev_armorvalue);
// The charger gave nothing (full, empty, or still waiting to charge).
if (armor <= before)
return HAM_IGNORED;
if (g_fullOnly && armor < 100.0)
return HAM_IGNORED;
new CsArmorType:armorType;
cs_get_user_armor(id, armorType);
if (armorType == CS_ARMOR_VESTHELM)
return HAM_IGNORED;
cs_set_user_armor(id, floatround(armor, floatround_floor), CS_ARMOR_VESTHELM);
if (g_message)
client_print_color(id, print_team_default, "%L", id, "HC_HELMET");
return HAM_IGNORED;
}
/**
* The living player who uses the charger, or 0. A player's +use passes him
* as both the caller and the activator.
*/
charger_user(caller, activator)
{
if (!g_enabled)
return 0;
new id = (1 <= caller <= MaxClients) ? caller : activator;
if (!(1 <= id <= MaxClients) || !is_user_alive(id))
return 0;
return id;
}