/*
* Admin Dead Spectate Vision (olds.ro)
* Copyright (C) 2026 daemon (olds.ro)
*
* 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. It is distributed WITHOUT ANY WARRANTY; see
* <https://www.gnu.org/licenses/>.
*
* Dead admins (ADMIN_BAN) type /dv to see a marker over every living player
* in range and a HUD list with their name, health, weapon and distance.
* Only that admin receives it; every activation is logged.
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>
#define PLUGIN "Admin Dead Spectate Vision"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define ACCESS ADMIN_BAN
#define MAX_LINES 12
new const MARKER_SPRITE[] = "sprites/laserbeam.spr"
new const LOG_FILE[] = "olds_dv.log"
new g_cvRange, g_cvRate, g_cvLog
new g_marker, g_hud
new bool:g_on[MAX_PLAYERS + 1]
new Float:g_next[MAX_PLAYERS + 1]
new g_marked[MAX_PLAYERS + 1]
public plugin_precache()
{
g_marker = precache_model(MARKER_SPRITE)
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_deadvision.txt")
g_cvRange = create_cvar("olds_dv_range", "3000", FCVAR_NONE, "Players farther than this from the admin's view are not shown", true, 100.0, true, 16384.0)
g_cvRate = create_cvar("olds_dv_rate", "0.2", FCVAR_NONE, "Seconds between two updates", true, 0.1, true, 2.0)
g_cvLog = create_cvar("olds_dv_log", "1", FCVAR_NONE, "1 = log every activation to olds_dv.log", true, 0.0, true, 1.0)
AutoExecConfig(true, "olds_deadvision")
register_clcmd("say /dv", "cmd_dv")
register_clcmd("say_team /dv", "cmd_dv")
register_concmd("amx_dv_status", "cmd_status", ACCESS, "- who uses dead vision and how many players they see")
RegisterHookChain(RG_CBasePlayer_PreThink, "on_prethink_pre", false)
RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
g_hud = CreateHudSyncObj()
}
public client_putinserver(id)
{
g_on[id] = false
g_marked[id] = 0
}
public client_disconnected(id)
{
g_on[id] = false
g_marked[id] = 0
}
public cmd_dv(id)
{
if (!is_user_connected(id))
return PLUGIN_HANDLED
if (!(get_user_flags(id) & ACCESS))
{
client_print_color(id, print_team_default, "%L", id, "DV_NO_ACCESS")
return PLUGIN_HANDLED
}
g_on[id] = !g_on[id]
if (!g_on[id])
{
ClearSyncHud(id, g_hud)
g_marked[id] = 0
client_print_color(id, print_team_default, "%L", id, "DV_OFF")
return PLUGIN_HANDLED
}
g_next[id] = 0.0
if (is_user_alive(id))
client_print_color(id, print_team_default, "%L", id, "DV_ON_ALIVE")
else
client_print_color(id, print_team_default, "%L", id, "DV_ON")
if (get_pcvar_num(g_cvLog) == 1)
{
new name[MAX_NAME_LENGTH], authid[32], map[32]
get_user_name(id, name, charsmax(name))
get_user_authid(id, authid, charsmax(authid))
get_mapname(map, charsmax(map))
log_to_file(LOG_FILE, "%s <%s> turned dead vision on (map %s, alive %d)", name, authid, map, is_user_alive(id))
}
return PLUGIN_HANDLED
}
public on_spawn_post(id)
{
// Alive again: back to the normal view; it starts again at the next death.
if (is_user_alive(id) && g_on[id])
{
ClearSyncHud(id, g_hud)
g_marked[id] = 0
}
return HC_CONTINUE
}
public on_prethink_pre(id)
{
if (!g_on[id] || !is_user_connected(id) || is_user_alive(id))
return HC_CONTINUE
new Float:now = get_gametime()
if (now < g_next[id])
return HC_CONTINUE
new Float:rate = get_pcvar_float(g_cvRate)
g_next[id] = now + rate
// A changed flag (amx_reloadadmins) ends it.
if (!(get_user_flags(id) & ACCESS))
{
g_on[id] = false
ClearSyncHud(id, g_hud)
return HC_CONTINUE
}
new Float:eye[3], Float:ofs[3]
get_entvar(id, var_origin, eye)
get_entvar(id, var_view_ofs, ofs)
for (new i = 0; i < 3; i++)
eye[i] += ofs[i]
new Float:range = get_pcvar_float(g_cvRange)
new life = max(1, floatround(rate * 10.0, floatround_ceil) + 1)
new text[512], len, lines, count
for (new p = 1; p <= MaxClients; p++)
{
if (p == id || !is_user_alive(p))
continue
new Float:origin[3]
get_entvar(p, var_origin, origin)
new Float:dist = get_distance_f(eye, origin)
if (dist > range)
continue
count++
message_begin(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, _, id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(p)
write_coord(45)
write_short(g_marker)
write_short(life)
message_end()
if (lines < MAX_LINES)
{
new name[24], weapon[24]
get_user_name(p, name, charsmax(name))
weapon_short(p, weapon, charsmax(weapon))
new team[3]
if (get_member(p, m_iTeam) == TEAM_TERRORIST)
copy(team, charsmax(team), "T")
else
copy(team, charsmax(team), "CT")
len += formatex(text[len], charsmax(text) - len, "[%s] %s %d HP %s %.0fu^n", team, name, get_user_health(p), weapon, dist)
lines++
}
}
g_marked[id] = count
if (count > lines)
len += formatex(text[len], charsmax(text) - len, "%L", id, "DV_MORE", count - lines)
if (!count)
formatex(text, charsmax(text), "%L", id, "DV_NONE")
set_hudmessage(120, 255, 120, 0.02, 0.22, 0, 0.0, rate + 0.1, 0.0, 0.0, -1)
ShowSyncHudMsg(id, g_hud, "%s", text)
return HC_CONTINUE
}
weapon_short(id, out[], len)
{
new weapon = get_user_weapon(id)
if (weapon <= 0)
{
copy(out, len, "-")
return
}
new full[32]
get_weaponname(weapon, full, charsmax(full))
if (equal(full, "weapon_", 7))
copy(out, len, full[7])
else
copy(out, len, full)
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new name[MAX_NAME_LENGTH], users
for (new p = 1; p <= MaxClients; p++)
{
if (!g_on[p] || !is_user_connected(p))
continue
get_user_name(p, name, charsmax(name))
console_print(id, "%L", id, "DV_STATUS_LINE", name, !is_user_alive(p), g_marked[p])
users++
}
console_print(id, "%L", id, "DV_STATUS", users)
return PLUGIN_HANDLED
}