Skip to content
View in the app

A better way to browse. Learn more.

Learn more

hltv-report/addons/amxmodx/scripting/olds_hltvrep.sma

olds_hltvrep.sma
171 lines · 4.9 KB · Pawn (AMX Mod X)
Raw
/*
 * HLTV Report (olds.ro workshop card LIB-0837)
 *
 * Admins check that an HLTV broadcast is healthy:
 *   amx_hltvstatus   (ADMIN_KICK) prints, to the console and the chat, every HLTV
 *                    proxy on the server with its address, the broadcast delay
 *                    (tv_delay), the proxy slots (tv_maxclients) and the number of
 *                    spectators on the server; with no proxy it says so plainly.
 *
 * Cvars
 *   olds_hltvrep_interval 0   seconds between automatic reports to every online
 *                             admin with ADMIN_KICK (and the server console);
 *                             0 = off, otherwise 10 to 3600
 *
 * tv_delay and tv_maxclients are read every time a report is made, so a change
 * shows in the next one. A server without those cvars gets "not set" for them.
 *
 * Copyright (C) 2026 daemon (olds.ro)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include <amxmodx>
#include <amxmisc>

#define PLUGIN  "HLTV Report"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

const TASK_REPORT = 8370
const LINE_LEN = 190

new g_interval
new g_elapsed

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_dictionary("olds_hltvrep.txt")
    bind_pcvar_num(create_cvar("olds_hltvrep_interval", "0", FCVAR_NONE,
        "Seconds between automatic HLTV reports to admins (0 = off, 10 to 3600).", true, 0.0, true, 3600.0), g_interval)
    AutoExecConfig(true, "olds_hltvrep")
    register_concmd("amx_hltvstatus", "cmd_status", ADMIN_KICK, "- HLTV proxies, delay and spectators")
}

public plugin_cfg()
{
    set_task(1.0, "task_tick", TASK_REPORT, _, _, "b")
}

/* Counts seconds against olds_hltvrep_interval, read every tick, so a change of
 * the cvar takes effect at once. */
public task_tick()
{
    new secs = g_interval
    if (secs <= 0)
    {
        g_elapsed = 0
        return
    }
    if (secs < 10)
        secs = 10
    if (++g_elapsed >= secs)
    {
        g_elapsed = 0
        send_report(0, true)
    }
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    send_report(id, false)
    return PLUGIN_HANDLED
}

/* id 0 with to_admins: every online ADMIN_KICK admin and the server console.
 * id 0 alone: the server console. Otherwise the one admin. */
send_report(id, bool:to_admins)
{
    new players[MAX_PLAYERS], num
    get_players(players, num)

    new proxies[MAX_PLAYERS], proxyCount, spectators
    for (new i = 0; i < num; i++)
    {
        new p = players[i]
        if (is_user_hltv(p))
            proxies[proxyCount++] = p
        else if (get_user_team(p) == 3 || (get_user_team(p) == 0 && !is_user_bot(p)))
            spectators++
    }

    new delay[16], slots[16]
    read_tv_cvar("tv_delay", delay, charsmax(delay))
    read_tv_cvar("tv_maxclients", slots, charsmax(slots))

    new targets[MAX_PLAYERS], targetCount
    if (id)
        targets[targetCount++] = id
    else if (to_admins)
    {
        for (new i = 0; i < num; i++)
        {
            new p = players[i]
            if (!is_user_bot(p) && !is_user_hltv(p) && (get_user_flags(p) & ADMIN_KICK))
                targets[targetCount++] = p
        }
    }
    new bool:console = (id == 0)

    new line[LINE_LEN], name[32], ip[32]
    if (!proxyCount)
    {
        for (new t = 0; t < targetCount; t++)
        {
            formatex(line, charsmax(line), "%L", targets[t], "HLTVREP_NONE", spectators)
            deliver(targets[t], line)
        }
        if (console)
        {
            formatex(line, charsmax(line), "%L", LANG_SERVER, "HLTVREP_NONE", spectators)
            server_print("[HLTV] %s", line)
        }
        return
    }

    for (new k = 0; k < proxyCount; k++)
    {
        get_user_name(proxies[k], name, charsmax(name))
        get_user_ip(proxies[k], ip, charsmax(ip), 0)
        for (new t = 0; t < targetCount; t++)
        {
            formatex(line, charsmax(line), "%L", targets[t], "HLTVREP_PROXY", name, ip, delay, slots)
            deliver(targets[t], line)
        }
        if (console)
        {
            formatex(line, charsmax(line), "%L", LANG_SERVER, "HLTVREP_PROXY", name, ip, delay, slots)
            server_print("[HLTV] %s", line)
        }
    }
    for (new t = 0; t < targetCount; t++)
    {
        formatex(line, charsmax(line), "%L", targets[t], "HLTVREP_TOTAL", proxyCount, spectators)
        deliver(targets[t], line)
    }
    if (console)
    {
        formatex(line, charsmax(line), "%L", LANG_SERVER, "HLTVREP_TOTAL", proxyCount, spectators)
        server_print("[HLTV] %s", line)
    }
}

deliver(id, const line[])
{
    if (!is_user_connected(id))
        return
    console_print(id, "[HLTV] %s", line)
    client_print(id, print_chat, "[HLTV] %s", line)
}

read_tv_cvar(const cvar[], out[], len)
{
    new pointer = get_cvar_pointer(cvar)
    if (!pointer)
    {
        formatex(out, len, "%L", LANG_SERVER, "HLTVREP_NOTSET")
        return
    }
    formatex(out, len, "%d", get_pcvar_num(pointer))
}

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.