Skip to content
View in the app

A better way to browse. Learn more.

Learn more

spawn-queue-survey/addons/amxmodx/scripting/olds_spawnq.sma

olds_spawnq.sma
254 lines · 7.5 KB · Pawn (AMX Mod X)
Raw
/*
 * Spawn Queue Survey (olds.ro workshop card AMX-045)
 *
 * Kreedz: finds start positions where something regularly blocks a player
 * who spawns there. After every spawn on a listed anchor the plugin traces a
 * standing player's hull at the anchor once and counts what was in the way:
 * another player, or static map geometry (the world or a brush entity).
 * amx_spawnq prints the counts per anchor for mappers.
 *
 * Anchors: addons/amxmodx/configs/olds_spawnq/<map>.ini, one per line:
 *     "Anchor name"  x y z
 * A spawn counts for the nearest anchor within 64 units of the spawn point.
 * Bad lines (wrong count, not numbers, beyond the +/-4096 map limit, a
 * repeated name) are skipped with one log warning each; the rest still
 * report.
 *
 * Trace: EngFunc_TraceHull with HULL_HUMAN at the anchor, ignoring the
 * spawning player. In the way = the hull starts in something solid; the hit
 * entity's class tells "player" from "static" (worldspawn, func_*).
 *
 *   amx_spawnq                  the report
 *   amx_spawnq reload | reset   read the anchors again (clears counts) / clear counts
 * ADMIN_MAP.
 *
 * Cvar: olds_spawnq_samples 200 (10-10000), samples kept per anchor; a full
 * anchor stops counting until reset. Counts last until the map changes.
 *
 * 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 Queue Survey"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

const MAX_ANCHORS = 64
const ANCHOR_NAME = 32
const Float:MATCH_RADIUS = 64.0
const Float:WORLD_LIMIT = 4096.0

new g_name[MAX_ANCHORS][ANCHOR_NAME]
new Float:g_origin[MAX_ANCHORS][3]
new g_count
new g_file[128]

new g_samples[MAX_ANCHORS]
new g_byPlayer[MAX_ANCHORS]
new g_byStatic[MAX_ANCHORS]
new g_lastStatic[MAX_ANCHORS][32]       // class of the last static blocker

new g_maxSamples

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)

    bind_pcvar_num(create_cvar("olds_spawnq_samples", "200", FCVAR_NONE,
        "Spawn samples kept per anchor (10-10000).", true, 10.0, true, 10000.0), g_maxSamples)
    AutoExecConfig(true, "olds_spawnq")

    register_concmd("amx_spawnq", "cmd_spawnq", ADMIN_MAP, "[reload | reset] - spawn obstructions per start anchor")
    RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)

    new map[64]
    get_mapname(map, charsmax(map))
    get_configsdir(g_file, charsmax(g_file))
    format(g_file, charsmax(g_file), "%s/olds_spawnq/%s.ini", g_file, map)
    load_anchors()
}

/* ---------- anchors ---------- */

load_anchors()
{
    g_count = 0
    reset_counts()
    new file = fopen(g_file, "rt")
    if (!file)
        return
    new line[160], name[ANCHOR_NAME], value[3][16], number
    while (fgets(file, line, charsmax(line)))
    {
        number++
        trim(line)
        if (!line[0] || line[0] == ';' || (line[0] == '/' && line[1] == '/'))
            continue
        if (g_count == MAX_ANCHORS)
        {
            log_amx("%s: more than %d anchors, the rest are ignored", g_file, MAX_ANCHORS)
            break
        }
        if (parse(line, name, charsmax(name), value[0], charsmax(value[]), value[1], charsmax(value[]), value[2],
            charsmax(value[])) != 4 || !name[0] || !all_numbers(value))
        {
            log_amx("%s line %d: expected ^"name^" x y z, anchor skipped", g_file, number)
            continue
        }
        new Float:origin[3], bool:inside = true
        for (new axis = 0; axis < 3; axis++)
        {
            origin[axis] = str_to_float(value[axis])
            if (floatabs(origin[axis]) > WORLD_LIMIT)
                inside = false
        }
        if (!inside)
        {
            log_amx("%s line %d: anchor ^"%s^" is beyond the map limit, skipped", g_file, number, name)
            continue
        }
        if (anchor_named(name) >= 0)
        {
            log_amx("%s line %d: anchor ^"%s^" is listed twice, the second is skipped", g_file, number, name)
            continue
        }
        copy(g_name[g_count], charsmax(g_name[]), name)
        g_origin[g_count] = origin
        g_count++
    }
    fclose(file)
}

anchor_named(const name[])
{
    for (new a = 0; a < g_count; a++)
        if (equali(g_name[a], name))
            return a
    return -1
}

bool:all_numbers(const value[3][16])
{
    for (new v = 0; v < 3; v++)
    {
        new i = (value[v][0] == '-' || value[v][0] == '+') ? 1 : 0, digits
        for (; value[v][i]; i++)
        {
            if (isdigit(value[v][i]))
                digits++
            else if (value[v][i] != '.')
                return false
        }
        if (!digits)
            return false
    }
    return true
}

reset_counts()
{
    for (new a = 0; a < MAX_ANCHORS; a++)
    {
        g_samples[a] = 0
        g_byPlayer[a] = 0
        g_byStatic[a] = 0
        g_lastStatic[a][0] = EOS
    }
}

/* ---------- sampling ---------- */

public on_spawn_post(id)
{
    if (!g_count || !(1 <= id <= MaxClients) || !is_user_alive(id))
        return HC_CONTINUE
    new Float:origin[3]
    get_entvar(id, var_origin, origin)
    new anchor = -1, Float:best = MATCH_RADIUS
    for (new a = 0; a < g_count; a++)
    {
        new Float:distance = get_distance_f(origin, g_origin[a])
        if (distance <= best)
        {
            best = distance
            anchor = a
        }
    }
    if (anchor < 0 || g_samples[anchor] >= g_maxSamples)
        return HC_CONTINUE
    sample(anchor, id)
    return HC_CONTINUE
}

/* One hull trace at the anchor, ignoring the player who spawned there. */
sample(anchor, id)
{
    new trace = create_tr2()
    engfunc(EngFunc_TraceHull, g_origin[anchor], g_origin[anchor], DONT_IGNORE_MONSTERS, HULL_HUMAN, id, trace)
    new bool:blocked = get_tr2(trace, TR_StartSolid) || get_tr2(trace, TR_AllSolid)
    new hit = get_tr2(trace, TR_pHit)
    free_tr2(trace)

    g_samples[anchor]++
    if (!blocked)
        return

    new classname[32]
    if (hit > 0 && !is_nullent(hit))
        get_entvar(hit, var_classname, classname, charsmax(classname))
    else
        copy(classname, charsmax(classname), "worldspawn")
    if (equal(classname, "player"))
        g_byPlayer[anchor]++
    else
    {
        g_byStatic[anchor]++
        copy(g_lastStatic[anchor], charsmax(g_lastStatic[]), classname)
    }
}

/* ---------- report ---------- */

public cmd_spawnq(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    new action[16]
    read_argv(1, action, charsmax(action))
    if (equali(action, "reload"))
    {
        load_anchors()
        console_print(id, "[SpawnQ] %d anchor(s) read from %s; counts cleared", g_count, g_file)
        return PLUGIN_HANDLED
    }
    if (equali(action, "reset"))
    {
        reset_counts()
        console_print(id, "[SpawnQ] counts cleared")
        return PLUGIN_HANDLED
    }
    if (!g_count)
    {
        console_print(id, "[SpawnQ] no valid anchors in %s", g_file)
        return PLUGIN_HANDLED
    }
    console_print(id, "[SpawnQ] %d anchor(s) from %s; up to %d samples each", g_count, g_file, g_maxSamples)
    for (new a = 0; a < g_count; a++)
    {
        new samples = g_samples[a]
        console_print(id, "[SpawnQ]   %s: %d sample(s), blocked by player %d (%d%%), static %d (%d%%)%s%s%s",
            g_name[a], samples, g_byPlayer[a], percent(g_byPlayer[a], samples), g_byStatic[a],
            percent(g_byStatic[a], samples), g_lastStatic[a][0] ? " last " : "", g_lastStatic[a],
            samples >= g_maxSamples ? " [full]" : "")
    }
    return PLUGIN_HANDLED
}

percent(part, whole)
{
    return whole ? (part * 100 + whole / 2) / whole : 0
}

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.