/*
* Return Receipt (olds.ro workshop card AMX-010)
*
* When a team captures the enemy flag, it gets a receipt naming every
* teammate who carried that flag on its way to the capture, each name once.
*
* Needs: AMX Mod X 1.10, ReGameDLL_CS + ReAPI, and the "Just Capture the Flag"
* core (jCTF). Verified against jCTF 1.32o by Digi (jctf_base.sma in
* github.com/OsweRRR/jCTF-by-Digi, commit 89a76b9); other versions load with a
* warning in the log.
*
* Flag lifecycle, from the core's jctf_flag(event, player, flagTeam, assist) forward:
* FLAG_STOLEN taken from its base -> a new attempt starts with this carrier
* FLAG_PICKED picked up from the ground -> carrier added (once per player)
* FLAG_DROPPED / FLAG_MANUALDROP -> the attempt continues
* FLAG_RETURNED, FLAG_AUTORETURN, FLAG_ADMINRETURN -> the attempt is discarded
* FLAG_CAPTURED (not the assist calls) -> the receipt is printed, then discarded
* The core also sends both flags home on every new round without a forward, so a
* new round discards both attempts too. Assist calls (assist = true) are ignored:
* they are about returns and kills, not carrying.
*
* Carriers are recorded by user id (a reconnect in the same slot is a new
* player) with the name they had when they took the flag, so a carrier who
* leaves before the capture is still on the receipt. Up to 8 carriers are
* named; more are counted as "+N more".
*
* Cvar: olds_receipt_show (0 off, 1 capturing team only, 2 everyone; default 1).
* Command: olds_receipt_status (ADMIN_CFG) prints both pending attempts.
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#include <reapi>
#define PLUGIN "Return Receipt"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
#define CORE_NAME "Just Capture the Flag"
#define CORE_TESTED_VERSION "1.32o"
// jctf_flag() events, as jctf.inc numbers them.
enum
{
FLAG_STOLEN = 0,
FLAG_PICKED,
FLAG_DROPPED,
FLAG_MANUALDROP,
FLAG_RETURNED,
FLAG_CAPTURED,
FLAG_AUTORETURN,
FLAG_ADMINRETURN
}
// jCTF flag teams: red is the terrorists' flag, blue the CTs'.
const FLAG_RED = 1
const FLAG_BLUE = 2
const MAX_CARRIERS = 8
const LINE_LEN = 150
new const CUE_SOUND[] = "events/task_complete"
enum ShowMode
{
SHOW_OFF,
SHOW_TEAM,
SHOW_ALL
}
// Pending attempt per flag team (index FLAG_RED / FLAG_BLUE).
new bool:g_active[3]
new g_carrierUserId[3][MAX_CARRIERS]
new g_carrierName[3][MAX_CARRIERS][MAX_NAME_LENGTH]
new g_carrierCount[3]
new g_extraCarriers[3]
new ShowMode:g_show
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_receipt.txt")
bind_pcvar_num(create_cvar("olds_receipt_show", "1", FCVAR_NONE,
"Who sees capture receipts: 0 nobody, 1 the capturing team, 2 everyone.", true, 0.0, true, 2.0), g_show)
AutoExecConfig(true, "olds_receipt")
register_concmd("olds_receipt_status", "cmd_status", ADMIN_CFG, "- both pending flag attempts and their carriers")
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
}
public plugin_cfg()
{
new version[32]
if (!find_core(version, charsmax(version)))
{
set_fail_state("The %s core is not running. Load it before this plugin.", CORE_NAME)
return
}
if (!equal(version, CORE_TESTED_VERSION))
log_amx("%s %s is installed; this plugin was verified with %s. Check that receipts are right.",
CORE_NAME, version, CORE_TESTED_VERSION)
}
bool:find_core(version[], versionLen)
{
new file[2], name[64], author[2], status[16]
new count = get_pluginsnum()
for (new i = 0; i < count; i++)
{
if (get_plugin(i, file, 0, name, charsmax(name), version, versionLen, author, 0, status, charsmax(status)) == -1)
continue
if (equal(name, CORE_NAME))
return equal(status, "running") || equal(status, "debug")
}
return false
}
/* ---------- the core's forward ---------- */
public jctf_flag(event, player, flagTeam, bool:assist)
{
if (assist || (flagTeam != FLAG_RED && flagTeam != FLAG_BLUE))
return
switch (event)
{
case FLAG_STOLEN:
{
discard(flagTeam)
g_active[flagTeam] = true
add_carrier(flagTeam, player)
}
case FLAG_PICKED:
{
// A pick-up from the ground continues an attempt; if this plugin
// was loaded after the steal, the attempt starts here.
g_active[flagTeam] = true
add_carrier(flagTeam, player)
}
case FLAG_RETURNED, FLAG_AUTORETURN, FLAG_ADMINRETURN:
{
discard(flagTeam)
}
case FLAG_CAPTURED:
{
if (g_active[flagTeam])
{
add_carrier(flagTeam, player) // normally already listed
print_receipt(flagTeam, player)
}
discard(flagTeam)
}
}
}
add_carrier(flagTeam, player)
{
if (!is_user_connected(player))
return
new userId = get_user_userid(player)
for (new i = 0; i < g_carrierCount[flagTeam]; i++)
{
if (g_carrierUserId[flagTeam][i] == userId)
return
}
if (g_carrierCount[flagTeam] == MAX_CARRIERS)
{
g_extraCarriers[flagTeam]++
return
}
new slot = g_carrierCount[flagTeam]++
g_carrierUserId[flagTeam][slot] = userId
get_user_name(player, g_carrierName[flagTeam][slot], charsmax(g_carrierName[][]))
}
discard(flagTeam)
{
g_active[flagTeam] = false
g_carrierCount[flagTeam] = 0
g_extraCarriers[flagTeam] = 0
}
public on_restart_round_pre()
{
// The core sends both flags home on a new round without firing a forward.
discard(FLAG_RED)
discard(FLAG_BLUE)
return HC_CONTINUE
}
/* ---------- the receipt ---------- */
print_receipt(flagTeam, capturer)
{
new capturerName[MAX_NAME_LENGTH]
get_user_name(capturer, capturerName, charsmax(capturerName))
// One line in the AMXX log for the record, whoever sees the receipt.
new names[MAX_CARRIERS * (MAX_NAME_LENGTH + 2)]
list_carriers(flagTeam, names, charsmax(names))
log_amx("Capture of the %s flag by %s, carriers: %s (+%d)", flagTeam == FLAG_RED ? "red" : "blue",
capturerName, names, g_extraCarriers[flagTeam])
if (g_show == SHOW_OFF)
return
// The capturing team is the one that does not own the flag.
new capturingTeam[16], any:color
if (flagTeam == FLAG_RED)
{
copy(capturingTeam, charsmax(capturingTeam), "CT")
color = print_team_blue
}
else
{
copy(capturingTeam, charsmax(capturingTeam), "TERRORIST")
color = print_team_red
}
new players[MAX_PLAYERS], count
if (g_show == SHOW_TEAM)
get_players(players, count, "ceh", capturingTeam)
else
get_players(players, count, "ch")
for (new i = 0; i < count; i++)
{
new id = players[i]
client_print_color(id, color, "^4[Receipt]^1 %L", id, "RECEIPT_TITLE", capturerName, g_carrierCount[flagTeam] + g_extraCarriers[flagTeam])
print_carriers(id, flagTeam, color)
client_cmd(id, "spk %s", CUE_SOUND)
}
}
/* Plain "A, B, C" list of the named carriers. */
list_carriers(flagTeam, names[], len)
{
names[0] = EOS
new length
for (new i = 0; i < g_carrierCount[flagTeam]; i++)
{
if (i)
length += copy(names[length], len - length, ", ")
length += copy(names[length], len - length, g_carrierName[flagTeam][i])
}
}
/* The carriers in team colour, split over chat lines so none is cut. */
print_carriers(id, flagTeam, any:color)
{
new line[LINE_LEN + MAX_NAME_LENGTH + 8], length
for (new i = 0; i < g_carrierCount[flagTeam]; i++)
{
if (length && length + strlen(g_carrierName[flagTeam][i]) + 4 > LINE_LEN)
{
client_print_color(id, color, "^4[Receipt]^1 %s", line)
line[0] = EOS
length = 0
}
if (length)
length += copy(line[length], charsmax(line) - length, "^1, ")
length += formatex(line[length], charsmax(line) - length, "^3%s", g_carrierName[flagTeam][i])
}
if (g_extraCarriers[flagTeam])
length += formatex(line[length], charsmax(line) - length, "^1 %L", id, "RECEIPT_MORE", g_extraCarriers[flagTeam])
if (length)
client_print_color(id, color, "^4[Receipt]^1 %s", line)
}
/* ---------- commands ---------- */
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
for (new flagTeam = FLAG_RED; flagTeam <= FLAG_BLUE; flagTeam++)
{
new names[MAX_CARRIERS * (MAX_NAME_LENGTH + 2)]
list_carriers(flagTeam, names, charsmax(names))
console_print(id, "[Receipt] %s flag: %s, carriers [%s] +%d", flagTeam == FLAG_RED ? "red" : "blue",
g_active[flagTeam] ? "in play" : "home", names, g_extraCarriers[flagTeam])
}
return PLUGIN_HANDLED
}