/*
* Ladder Bottleneck (olds.ro workshop card AMX-103)
*
* Arms Race: finds the slowest levels on each team's own weapon ladder. Every
* visit to a level is timed on the core's active-play clock, from the moment
* a player reaches the level until they level up out of it by playing.
* amx_bottleneck prints, per team ladder, the three levels with the highest
* average time per visit among those with enough eligible visits.
*
* Adapter: the core (an Arms Race fork with progression reasons, ladder
* definitions and an active-play timer) reports through two natives
* (library "olds_bottleneck", include/olds_bottleneck.inc):
* olds_bottleneck_ladder(team, const definition[])
* the team's ladder (1 = T, 2 = CT) as one text, e.g. its weapon
* list; a different text discards that ladder's stored times
* olds_bottleneck_level(id, level, reason, Float:activeClock)
* the player is now on this level; activeClock = the player's
* active-play seconds (the core's timer, which stops in downtime)
*
* Eligible visit: it began by playing (OBN_PLAY) or at the start of a session
* (OBN_START), and ended by playing up to the next level, on the same team,
* with the clock moving forward. Forced (OBN_FORCED) and admin (OBN_ADMIN)
* changes, demotions, team changes and disconnects drop the open visit.
*
* Cvar: olds_bottleneck_visits 3 (1-100), eligible visits a level needs to be
* listed. Command: amx_bottleneck (ADMIN_MAP), printed in the admin's console
* only. Times are kept until the map changes or the ladder changes.
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Ladder Bottleneck"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
const TEAMS = 2
const MAX_LEVELS = 64
const LADDER_TEXT = 512
const SHOWN = 3
enum
{
OBN_PLAY = 0,
OBN_START,
OBN_FORCED,
OBN_ADMIN,
OBN_REASONS
}
new g_ladder[TEAMS][LADDER_TEXT]
new Float:g_total[TEAMS][MAX_LEVELS + 1]
new g_visits[TEAMS][MAX_LEVELS + 1]
new g_visitLevel[MAX_PLAYERS + 1] // 0 = no open visit
new g_visitTeam[MAX_PLAYERS + 1]
new Float:g_visitStart[MAX_PLAYERS + 1]
new bool:g_visitEligible[MAX_PLAYERS + 1]
new g_minVisits
public plugin_natives()
{
register_library("olds_bottleneck")
register_native("olds_bottleneck_ladder", "native_ladder")
register_native("olds_bottleneck_level", "native_level")
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
bind_pcvar_num(create_cvar("olds_bottleneck_visits", "3", FCVAR_NONE,
"Eligible visits a level needs before amx_bottleneck lists it (1-100).", true, 1.0, true, 100.0), g_minVisits)
AutoExecConfig(true, "olds_bottleneck")
register_concmd("amx_bottleneck", "cmd_bottleneck", ADMIN_MAP, "- the three slowest levels on each team ladder")
}
/* T = 0, CT = 1, anything else -1. */
team_slot(id)
{
switch (get_user_team(id))
{
case 1: return 0
case 2: return 1
}
return -1
}
close_visit(id)
{
g_visitLevel[id] = 0
g_visitTeam[id] = -1
g_visitStart[id] = 0.0
g_visitEligible[id] = false
}
/* ---------- natives ---------- */
public native_ladder(plugin, params)
{
new team = get_param(1)
if (team != 1 && team != 2)
{
log_error(AMX_ERR_NATIVE, "olds_bottleneck_ladder: team %d (1 = T, 2 = CT)", team)
return 0
}
new definition[LADDER_TEXT]
get_string(2, definition, charsmax(definition))
new slot = team - 1
if (equal(definition, g_ladder[slot]))
return 0
new bool:hadTimes
for (new level = 1; level <= MAX_LEVELS; level++)
{
if (g_visits[slot][level])
hadTimes = true
g_visits[slot][level] = 0
g_total[slot][level] = 0.0
}
for (new id = 1; id <= MaxClients; id++)
if (g_visitLevel[id] && g_visitTeam[id] == slot)
close_visit(id)
copy(g_ladder[slot], charsmax(g_ladder[]), definition)
if (hadTimes)
log_amx("%s ladder changed: its stored level times were discarded", slot ? "CT" : "T")
return 1
}
public native_level(plugin, params)
{
new id = get_param(1), level = get_param(2), reason = get_param(3)
new Float:clock = get_param_f(4)
if (!(1 <= level <= MAX_LEVELS) || !(0 <= reason < OBN_REASONS))
{
log_error(AMX_ERR_NATIVE, "olds_bottleneck_level: level %d (1-%d), reason %d (0-%d)", level, MAX_LEVELS, reason,
OBN_REASONS - 1)
return 0
}
if (!(1 <= id <= MaxClients) || !is_user_connected(id) || clock < 0.0)
return 0
new slot = team_slot(id), recorded
if (g_visitLevel[id] && g_visitEligible[id] && reason == OBN_PLAY && level == g_visitLevel[id] + 1
&& slot == g_visitTeam[id] && clock > g_visitStart[id])
{
g_total[slot][g_visitLevel[id]] += clock - g_visitStart[id]
g_visits[slot][g_visitLevel[id]]++
recorded = 1
}
close_visit(id)
if (slot >= 0)
{
g_visitLevel[id] = level
g_visitTeam[id] = slot
g_visitStart[id] = clock
g_visitEligible[id] = (reason == OBN_PLAY || reason == OBN_START)
}
return recorded
}
public client_disconnected(id)
{
close_visit(id)
}
/* ---------- report ---------- */
public cmd_bottleneck(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
for (new slot = 0; slot < TEAMS; slot++)
{
console_print(id, "[Bottleneck] %s ladder: slowest levels (at least %d eligible visits)",
slot ? "CT" : "T", g_minVisits)
new bool:shown[MAX_LEVELS + 1], printed
while (printed < SHOWN)
{
new best, Float:bestAverage
for (new l = 1; l <= MAX_LEVELS; l++)
{
if (shown[l] || g_visits[slot][l] < g_minVisits)
continue
new Float:average = g_total[slot][l] / float(g_visits[slot][l])
if (!best || average > bestAverage)
{
best = l
bestAverage = average
}
}
if (!best)
break
shown[best] = true
printed++
console_print(id, "[Bottleneck] %d. level %d: average %d s over %d visits", printed, best,
floatround(bestAverage), g_visits[slot][best])
}
if (!printed)
console_print(id, "[Bottleneck] no level has %d eligible visits yet", g_minVisits)
}
return PLUGIN_HANDLED
}