/*
* Juggernaut Turn Queue (olds.ro workshop card AMX-097)
*
* Juggernaut: players who want a turn as Juggernaut say /jug to join a queue
* (again to leave). When the mode picks its next Juggernaut, the first
* living volunteer in queue order gets the turn; a dead or teamless volunteer
* is passed over but keeps their place.
*
* say /jug join or leave the queue
* say /jugqueue your place and the queue length
*
* Adapter: Juggernaut cores have no common API, so this plugin is the
* selection adapter. It offers two natives (library "olds_jugqueue",
* include/olds_jugqueue.inc) that the core, or a small bridge, calls when it
* selects its next Juggernaut:
* olds_jugqueue_candidate() the first eligible volunteer (connected,
* alive, on a team), or 0 for none; changes
* nothing
* olds_jugqueue_confirm(id) the core has really made id Juggernaut:
* id leaves the queue and everyone behind
* moves up; returns 1, or 0 if id was not
* queued
* If the core cannot assign the role, it simply does not call confirm, and
* the queue stays as it was: no role is ever forced from here.
*
* Leaving the server removes a player from the queue. The queue lives in
* memory and starts empty on every map.
*
* Cvar: olds_jugqueue_max 8 (1-32). Command: olds_jugqueue_status (ADMIN_CFG).
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#include <reapi>
#define PLUGIN "Juggernaut Turn Queue"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
new g_queue[MAX_PLAYERS]
new g_length
new Float:g_nextUse[MAX_PLAYERS + 1]
new g_max
public plugin_natives()
{
register_library("olds_jugqueue")
register_native("olds_jugqueue_candidate", "native_candidate")
register_native("olds_jugqueue_confirm", "native_confirm")
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_jugqueue.txt")
bind_pcvar_num(create_cvar("olds_jugqueue_max", "8", FCVAR_NONE,
"Most volunteers in the Juggernaut queue (1-32).", true, 1.0, true, float(MAX_PLAYERS)), g_max)
AutoExecConfig(true, "olds_jugqueue")
register_clcmd("say /jug", "cmd_jug")
register_clcmd("say_team /jug", "cmd_jug")
register_clcmd("say /jugqueue", "cmd_place")
register_clcmd("say_team /jugqueue", "cmd_place")
register_concmd("olds_jugqueue_status", "cmd_status", ADMIN_CFG, "- the Juggernaut queue")
}
/* ---------- the queue ---------- */
place_of(id)
{
for (new i = 0; i < g_length; i++)
if (g_queue[i] == id)
return i
return -1
}
bool:remove_from_queue(id)
{
new place = place_of(id)
if (place < 0)
return false
for (new i = place; i < g_length - 1; i++)
g_queue[i] = g_queue[i + 1]
g_queue[--g_length] = 0
return true
}
bool:eligible(id)
{
if (!is_user_connected(id) || !is_user_alive(id))
return false
new TeamName:team = TeamName:get_member(id, m_iTeam)
return team == TEAM_TERRORIST || team == TEAM_CT
}
/* ---------- commands ---------- */
public cmd_jug(id)
{
if (!is_user_connected(id) || !cooled(id))
return PLUGIN_HANDLED
if (remove_from_queue(id))
{
client_print_color(id, print_team_default, "^4[Juggernaut]^1 %L", id, "JUGQ_LEFT")
return PLUGIN_HANDLED
}
if (g_length >= min(g_max, MAX_PLAYERS))
{
client_print_color(id, print_team_default, "^4[Juggernaut]^1 %L", id, "JUGQ_FULL", g_max)
return PLUGIN_HANDLED
}
g_queue[g_length++] = id
client_print_color(id, print_team_default, "^4[Juggernaut]^1 %L", id, "JUGQ_JOINED", g_length)
return PLUGIN_HANDLED
}
public cmd_place(id)
{
if (!is_user_connected(id) || !cooled(id))
return PLUGIN_HANDLED
new place = place_of(id)
if (place < 0)
client_print_color(id, print_team_default, "^4[Juggernaut]^1 %L", id, "JUGQ_NOT_IN", g_length)
else
client_print_color(id, print_team_default, "^4[Juggernaut]^1 %L", id, "JUGQ_PLACE", place + 1, g_length)
return PLUGIN_HANDLED
}
bool:cooled(id)
{
new Float:now = get_gametime()
if (now < g_nextUse[id])
return false
g_nextUse[id] = now + 1.0
return true
}
public client_disconnected(id)
{
remove_from_queue(id)
g_nextUse[id] = 0.0
}
/* ---------- natives for the core ---------- */
public native_candidate(plugin, params)
{
for (new i = 0; i < g_length; i++)
if (eligible(g_queue[i]))
return g_queue[i]
return 0
}
public native_confirm(plugin, params)
{
new id = get_param(1)
if (!(1 <= id <= MaxClients))
{
log_error(AMX_ERR_NATIVE, "olds_jugqueue_confirm: invalid player %d", id)
return 0
}
if (!remove_from_queue(id))
return 0
if (is_user_connected(id))
client_print_color(id, print_team_default, "^4[Juggernaut]^1 %L", id, "JUGQ_YOUR_TURN")
// Tell the first one in line that they are next.
if (g_length && is_user_connected(g_queue[0]))
client_print_color(g_queue[0], print_team_default, "^4[Juggernaut]^1 %L", g_queue[0], "JUGQ_NEXT")
return 1
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[Juggernaut] queue %d of %d", g_length, g_max)
new name[MAX_NAME_LENGTH]
for (new i = 0; i < g_length; i++)
{
get_user_name(g_queue[i], name, charsmax(name))
console_print(id, "[Juggernaut] %d. %s%s", i + 1, name, eligible(g_queue[i]) ? "" : " (not eligible now)")
}
return PLUGIN_HANDLED
}