/*
* Spawn Buddy Window (olds.ro workshop card AMX-036)
*
* Deathmatch: when you respawn, the plugin notes once whether a living
* teammate was near you (within olds_buddy_radius units and, with
* olds_buddy_trace 1, in line of sight). When you die, your personal recap
* says whether you had a spawn buddy that life:
* Spawn buddy this life: yes, a teammate was within 600 units in sight.
* Only you see it, only after your death, and it is a plain yes or no: no
* positions, names or distances are ever sent.
*
* Needs: AMX Mod X 1.10 (fakemeta), ReGameDLL_CS + ReAPI, and CSDM 2.1
* (csdm_main), whose respawn callback csdm_PostSpawn(player, fake) runs
* after CSDM has placed the player. The check runs once per life: a second
* spawn callback in the same life and a later team switch change nothing.
* Bots are checked as teammates but never get a recap.
*
* Cvars: olds_buddy_radius 600 (100-3000), olds_buddy_trace 1.
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>
#define PLUGIN "Spawn Buddy Window"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
enum
{
BUDDY_UNKNOWN = 0, // not checked this life
BUDDY_NO,
BUDDY_YES
}
new g_result[MAX_PLAYERS + 1]
new g_radius
new g_trace
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_buddy.txt")
bind_pcvar_num(create_cvar("olds_buddy_radius", "600", FCVAR_NONE,
"Distance in units within which a teammate counts as a spawn buddy (100-3000).", true, 100.0, true, 3000.0),
g_radius)
bind_pcvar_num(create_cvar("olds_buddy_trace", "1", FCVAR_NONE,
"1 = the teammate must also be in line of sight.", true, 0.0, true, 1.0), g_trace)
AutoExecConfig(true, "olds_buddy")
RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
}
/* CSDM's respawn callback: CSDM has placed the player. */
public csdm_PostSpawn(player, bool:fake)
{
if (!(1 <= player <= MaxClients) || !is_user_alive(player) || g_result[player] != BUDDY_UNKNOWN)
return
g_result[player] = has_buddy(player) ? BUDDY_YES : BUDDY_NO
}
bool:has_buddy(id)
{
new TeamName:team = TeamName:get_member(id, m_iTeam)
if (team != TEAM_TERRORIST && team != TEAM_CT)
return false
new Float:origin[3], Float:eyes[3], Float:other[3], Float:otherEyes[3], Float:ofs[3]
get_entvar(id, var_origin, origin)
get_entvar(id, var_view_ofs, ofs)
for (new axis = 0; axis < 3; axis++)
eyes[axis] = origin[axis] + ofs[axis]
new Float:radius = float(g_radius)
for (new mate = 1; mate <= MaxClients; mate++)
{
if (mate == id || !is_user_alive(mate) || TeamName:get_member(mate, m_iTeam) != team)
continue
get_entvar(mate, var_origin, other)
if (get_distance_f(origin, other) > radius)
continue
if (!g_trace)
return true
get_entvar(mate, var_view_ofs, ofs)
for (new axis = 0; axis < 3; axis++)
otherEyes[axis] = other[axis] + ofs[axis]
if (in_sight(id, eyes, mate, otherEyes))
return true
}
return false
}
/* Eye to eye, ignoring the looker and stopping at walls (not at other players). */
bool:in_sight(id, const Float:from[3], mate, const Float:to[3])
{
new trace = create_tr2()
engfunc(EngFunc_TraceLine, from, to, IGNORE_MONSTERS, id, trace)
new Float:fraction
get_tr2(trace, TR_flFraction, fraction)
new hit = get_tr2(trace, TR_pHit)
free_tr2(trace)
return fraction >= 1.0 || hit == mate
}
public on_killed_post(victim, attacker, gib)
{
if (!(1 <= victim <= MaxClients))
return HC_CONTINUE
new result = g_result[victim]
g_result[victim] = BUDDY_UNKNOWN
if (result == BUDDY_UNKNOWN || is_user_bot(victim) || !is_user_connected(victim))
return HC_CONTINUE
if (result == BUDDY_YES)
client_print_color(victim, print_team_default, "^4[Spawn Buddy]^1 %L", victim,
g_trace ? "BUDDY_YES_SIGHT" : "BUDDY_YES", g_radius)
else
client_print_color(victim, print_team_default, "^4[Spawn Buddy]^1 %L", victim,
g_trace ? "BUDDY_NO_SIGHT" : "BUDDY_NO", g_radius)
return HC_CONTINUE
}
public client_disconnected(id)
{
g_result[id] = BUDDY_UNKNOWN
}