/*
* Assist Window (olds.ro workshop card AMX-028)
*
* When a teammate finishes an enemy you hurt shortly before, you get a short
* private DHUD line with your last hit on that enemy, for example
* "Assist on Rex: 40 dmg, 3.0 s ago", and a soft beep. It tells you your
* damage counted even though someone else got the kill.
*
* Only a hit of at least olds_assistwin_mindmg damage, made at most
* olds_assistwin_secs seconds before the kill, counts. Hits on yourself, on a
* teammate and from the world never count, and neither do hits from an
* earlier life: when you or the enemy respawn, the old hits are forgotten.
*
* Cvars (in configs/plugins/olds_assistwin.cfg, written with the defaults on
* the first start if the file is missing):
* olds_assistwin_secs 6 Look-back window in seconds (1 - 30).
* olds_assistwin_mindmg 10 Least damage of the hit (1 - 500).
*
* How it works, as the card asks: RG_CBasePlayer_TakeDamage (post) stores the
* attacker, the victim, the time and the damage of each hit, and
* RG_CBasePlayer_Killed looks back when a player dies.
* Texts are in data/lang/olds_assistwin.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[] = "Assist Window";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
new const CUE_SOUND[] = "buttons/blip1";
// Value of g_hitTime[][] for "no hit stored".
const Float:NO_HIT = -1.0;
// DHUD placement and look.
const Float:DHUD_X = -1.0;
const Float:DHUD_Y = 0.30;
const Float:DHUD_HOLD = 3.0;
new Float:g_window; // olds_assistwin_secs
new g_minDamage; // olds_assistwin_mindmg
// Last hit of each attacker on each victim: when, and how much damage.
// Bounded: one slot per pair of players.
new Float:g_hitTime[MAX_PLAYERS + 1][MAX_PLAYERS + 1];
new g_hitDamage[MAX_PLAYERS + 1][MAX_PLAYERS + 1];
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
register_dictionary("olds_assistwin.txt");
bind_pcvar_float(create_cvar("olds_assistwin_secs", "6", FCVAR_NONE,
"Seconds before a kill in which a teammate's hit counts as an assist",
true, 1.0, true, 30.0), g_window);
bind_pcvar_num(create_cvar("olds_assistwin_mindmg", "10", FCVAR_NONE,
"Least damage a hit needs to count as an assist",
true, 1.0, true, 500.0), g_minDamage);
AutoExecConfig(true, "olds_assistwin");
RegisterHookChain(RG_CBasePlayer_TakeDamage, "fw_take_damage_post", true);
RegisterHookChain(RG_CBasePlayer_Killed, "fw_killed_post", true);
// A respawn starts a new life: hits from and on the old one are dropped.
RegisterHookChain(RG_CBasePlayer_Spawn, "fw_spawn_post", true);
clear_all();
}
public client_disconnected(id)
{
forget_player(id);
}
public fw_spawn_post(const id)
{
forget_player(id);
return HC_CONTINUE;
}
public fw_take_damage_post(const victim, inflictor, attacker, Float:damage, damageBits)
{
// Only a hit by another player, on an enemy, that really did damage.
if (!GetHookChainReturn(ATYPE_INTEGER) || !is_valid_player(attacker) || attacker == victim)
return HC_CONTINUE;
if (get_member(attacker, m_iTeam) == get_member(victim, m_iTeam))
return HC_CONTINUE;
g_hitTime[attacker][victim] = get_gametime();
g_hitDamage[attacker][victim] = floatround(damage);
return HC_CONTINUE;
}
public fw_killed_post(const victim, killer, gib)
{
// Only a kill by an enemy player has teammates who could have helped.
if (is_valid_player(killer) && killer != victim && get_member(killer, m_iTeam) != get_member(victim, m_iTeam))
{
new TeamName:team = get_member(killer, m_iTeam);
new Float:now = get_gametime();
for (new supporter = 1; supporter <= MaxClients; supporter++)
{
if (supporter == killer || supporter == victim || !is_user_connected(supporter))
continue;
if (get_member(supporter, m_iTeam) != team || g_hitTime[supporter][victim] == NO_HIT)
continue;
new Float:age = now - g_hitTime[supporter][victim];
if (age <= g_window && g_hitDamage[supporter][victim] >= g_minDamage)
show_assist(supporter, victim, g_hitDamage[supporter][victim], age);
}
}
// The victim's hits are over either way.
for (new attacker = 1; attacker <= MaxClients; attacker++)
g_hitTime[attacker][victim] = NO_HIT;
return HC_CONTINUE;
}
show_assist(supporter, victim, damage, Float:age)
{
new name[MAX_NAME_LENGTH];
get_user_name(victim, name, charsmax(name));
// Tenths of a second, written with whole numbers so the value is exact.
new tenths = floatround(age * 10.0);
set_dhudmessage(80, 220, 120, DHUD_X, DHUD_Y, 0, 0.0, DHUD_HOLD, 0.1, 0.5);
show_dhudmessage(supporter, "%L", supporter, "ASSIST_LINE", name, damage, tenths / 10, tenths % 10);
client_cmd(supporter, "spk %s", CUE_SOUND);
}
forget_player(id)
{
for (new other = 1; other <= MaxClients; other++)
{
g_hitTime[id][other] = NO_HIT;
g_hitTime[other][id] = NO_HIT;
}
}
clear_all()
{
for (new id = 1; id <= MaxClients; id++)
forget_player(id);
}
bool:is_valid_player(id)
{
return 1 <= id <= MaxClients && is_user_connected(id);
}