/*
* Lineup Partners (olds.ro workshop card AMX-068)
*
* Jailbreak: the warden says /pairs and the living prisoners are paired at
* random for an activity. Each pair gets one readable token such as
* RED-LAMP, so partners can find each other by calling it out. With an odd
* number, one prisoner is "waiting". Each prisoner is told privately (chat
* and a DHUD line); /partner repeats it to them alone.
*
* say /pairs warden only: pair the living prisoners now (again: new pairs)
* say /partner your token and your partner
*
* Needs: AMX Mod X 1.10, ReGameDLL_CS + ReAPI, and the Jailbreak core
* "[JB] Core" (library "jailbreak"; github.com/al1k24/JailBreak-ReAPI):
* jb_get_simon_id() names the warden. Prisoners are the living terrorists.
* The pairs are cleared when another player becomes warden (checked every
* second) and at every round restart. A prisoner whose partner leaves or
* dies is told they are now waiting.
*
* Tokens: addons/amxmodx/configs/olds_pairs.txt, one per line (letters,
* digits and '-', up to 23 characters); each pair gets a different one. If
* there are not enough, PAIR-1, PAIR-2... are used for the rest.
*
* Cvar: olds_pairs_max 24 (2-32), prisoners in one lineup.
* Command: olds_pairs_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 "Lineup Partners"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
/* Jailbreak core API (jb/core.inc), declared here so it compiles without the core's includes. */
#pragma reqlib "jailbreak"
native jb_get_simon_id()
const MAX_TOKENS = 128
const TOKEN_LENGTH = 24
const TASK_WATCH = 6811
new g_token[MAX_TOKENS][TOKEN_LENGTH]
new g_tokenCount
new g_partner[MAX_PLAYERS + 1] // 0 = no partner
new g_pairToken[MAX_PLAYERS + 1][TOKEN_LENGTH] // empty = not in the lineup
new bool:g_waiting[MAX_PLAYERS + 1]
new bool:g_active
new g_wardenUserId // warden who made the lineup
new Float:g_nextUse[MAX_PLAYERS + 1]
new g_max
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_pairs.txt")
bind_pcvar_num(create_cvar("olds_pairs_max", "24", FCVAR_NONE,
"Most prisoners in one lineup (2-32).", true, 2.0, true, float(MAX_PLAYERS)), g_max)
AutoExecConfig(true, "olds_pairs")
register_clcmd("say /pairs", "cmd_pairs")
register_clcmd("say_team /pairs", "cmd_pairs")
register_clcmd("say /partner", "cmd_partner")
register_clcmd("say_team /partner", "cmd_partner")
register_concmd("olds_pairs_status", "cmd_status", ADMIN_CFG, "- the current lineup")
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
set_task(1.0, "task_watch_warden", TASK_WATCH, _, _, "b")
load_tokens()
}
/* ---------- tokens ---------- */
load_tokens()
{
new path[128]
get_configsdir(path, charsmax(path))
add(path, charsmax(path), "/olds_pairs.txt")
new file = fopen(path, "rt")
if (!file)
return
new line[64]
while (g_tokenCount < MAX_TOKENS && fgets(file, line, charsmax(line)))
{
trim(line)
if (!line[0] || line[0] == ';' || (line[0] == '/' && line[1] == '/'))
continue
if (!valid_token(line))
{
log_amx("%s: token ^"%s^" skipped (letters, digits and '-', up to %d characters)", path, line,
TOKEN_LENGTH - 1)
continue
}
strtoupper(line)
copy(g_token[g_tokenCount++], TOKEN_LENGTH - 1, line)
}
fclose(file)
}
bool:valid_token(const text[])
{
new length = strlen(text)
if (!length || length >= TOKEN_LENGTH)
return false
for (new i = 0; i < length; i++)
if (!isalnum(text[i]) && text[i] != '-')
return false
return true
}
/* ---------- the warden ---------- */
current_warden()
{
new warden = jb_get_simon_id()
return (1 <= warden <= MaxClients && is_user_connected(warden)) ? warden : 0
}
public task_watch_warden()
{
if (!g_active)
return
new warden = current_warden()
if (warden && get_user_userid(warden) != g_wardenUserId)
clear_lineup()
}
/* ---------- /pairs ---------- */
public cmd_pairs(id)
{
if (!is_user_connected(id) || !cooled(id))
return PLUGIN_HANDLED
if (id != current_warden())
{
client_print_color(id, print_team_default, "^4[Pairs]^1 %L", id, "PAIRS_WARDEN_ONLY")
return PLUGIN_HANDLED
}
new prisoners[MAX_PLAYERS], count
get_players_ex(prisoners, count, GetPlayers_ExcludeDead | GetPlayers_MatchTeam, "TERRORIST")
if (count < 2)
{
client_print_color(id, print_team_default, "^4[Pairs]^1 %L", id, "PAIRS_TOO_FEW")
return PLUGIN_HANDLED
}
clear_lineup()
shuffle(prisoners, count)
new used = min(count, g_max)
// Tokens in a random order, so each pair gets a different one.
new order[MAX_TOKENS]
for (new t = 0; t < g_tokenCount; t++)
order[t] = t
shuffle(order, g_tokenCount)
new pair
for (new i = 0; i + 1 < used; i += 2)
{
new a = prisoners[i], b = prisoners[i + 1], token[TOKEN_LENGTH]
if (pair < g_tokenCount)
copy(token, charsmax(token), g_token[order[pair]])
else
formatex(token, charsmax(token), "PAIR-%d", pair + 1)
pair++
g_partner[a] = b
g_partner[b] = a
copy(g_pairToken[a], charsmax(g_pairToken[]), token)
copy(g_pairToken[b], charsmax(g_pairToken[]), token)
}
if (used % 2)
g_waiting[prisoners[used - 1]] = true
g_active = true
g_wardenUserId = get_user_userid(id)
for (new i = 0; i < used; i++)
tell(prisoners[i], true)
client_print_color(id, print_team_default, "^4[Pairs]^1 %L", id, "PAIRS_FORMED", pair, used % 2, count - used)
return PLUGIN_HANDLED
}
shuffle(list[], count)
{
for (new i = count - 1; i > 0; i--)
{
new j = random_num(0, i), swap = list[i]
list[i] = list[j]
list[j] = swap
}
}
/* ---------- /partner ---------- */
public cmd_partner(id)
{
if (!is_user_connected(id) || !cooled(id))
return PLUGIN_HANDLED
tell(id, false)
return PLUGIN_HANDLED
}
tell(id, bool:hud)
{
if (!g_active)
{
client_print_color(id, print_team_default, "^4[Pairs]^1 %L", id, "PAIRS_NONE")
return
}
if (g_waiting[id])
{
client_print_color(id, print_team_default, "^4[Pairs]^1 %L", id, "PAIRS_WAITING")
if (hud)
show_line(id, fmt("%L", id, "PAIRS_HUD_WAITING"))
return
}
if (!g_partner[id])
{
client_print_color(id, print_team_default, "^4[Pairs]^1 %L", id, "PAIRS_NOT_IN")
return
}
new name[MAX_NAME_LENGTH]
get_user_name(g_partner[id], name, charsmax(name))
client_print_color(id, print_team_default, "^4[Pairs]^1 %L", id, "PAIRS_YOURS", g_pairToken[id], name)
if (hud)
show_line(id, fmt("%L", id, "PAIRS_HUD", g_pairToken[id], name))
}
show_line(id, const text[])
{
set_dhudmessage(255, 200, 80, -1.0, 0.30, 0, 0.0, 6.0, 0.2, 0.6)
show_dhudmessage(id, "%s", text)
}
/* ---------- partners leaving ---------- */
/* The other half of a pair is left waiting. */
lose_partner(id)
{
new other = g_partner[id]
g_partner[id] = 0
g_pairToken[id][0] = EOS
g_waiting[id] = false
if (other && g_partner[other] == id)
{
g_partner[other] = 0
g_pairToken[other][0] = EOS
g_waiting[other] = true
if (is_user_connected(other))
client_print_color(other, print_team_default, "^4[Pairs]^1 %L", other, "PAIRS_PARTNER_GONE")
}
}
public on_killed_post(victim, attacker, gib)
{
if (g_active && 1 <= victim <= MaxClients && (g_partner[victim] || g_waiting[victim]))
lose_partner(victim)
return HC_CONTINUE
}
public client_disconnected(id)
{
if (g_active)
lose_partner(id)
g_nextUse[id] = 0.0
}
clear_lineup()
{
for (new id = 1; id <= MaxClients; id++)
{
g_partner[id] = 0
g_pairToken[id][0] = EOS
g_waiting[id] = false
}
g_active = false
g_wardenUserId = 0
}
public on_restart_round_pre()
{
clear_lineup()
return HC_CONTINUE
}
/* ---------- helpers ---------- */
bool:cooled(id)
{
new Float:now = get_gametime()
if (now < g_nextUse[id])
return false
g_nextUse[id] = now + 1.0
return true
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[Pairs] %d token(s) loaded; lineup %s; up to %d prisoners", g_tokenCount,
g_active ? "active" : "none", g_max)
new name[MAX_NAME_LENGTH], other[MAX_NAME_LENGTH]
for (new p = 1; p <= MaxClients; p++)
{
if (!is_user_connected(p) || (!g_partner[p] && !g_waiting[p]))
continue
get_user_name(p, name, charsmax(name))
if (g_waiting[p])
console_print(id, "[Pairs] %s: waiting", name)
else if (p < g_partner[p])
{
get_user_name(g_partner[p], other, charsmax(other))
console_print(id, "[Pairs] %s: %s + %s", g_pairToken[p], name, other)
}
}
return PLUGIN_HANDLED
}