/*
* Return Drill (olds.ro) - jCTF add-on. Each round it times a team's first
* recovery of its own dropped flag: from the drop to the moment a teammate
* touches it home. Timed (automatic) and admin returns do not count.
*
* Copyright (C) 2026 daemon (olds.ro), written by daemon's plugin agent
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. You should have received a copy of the GNU General Public
* License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* jCTF (Just Capture the Flag 1.32o by Digi) calls
* jctf_flag(event, player, flagTeam, assist) in every plugin:
* FLAG_DROPPED / FLAG_MANUALDROP the enemy carrier lost the flag: the clock starts
* FLAG_PICKED the enemy took it again: the attempt ends
* FLAG_RETURNED (a player) a teammate brought it home: the time is recorded
* FLAG_AUTORETURN / FLAG_ADMINRETURN / FLAG_CAPTURED: the attempt ends, nothing is recorded
*/
#include <amxmodx>
#include <amxmisc>
#include <reapi>
#define PLUGIN "Return Drill"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
// 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
}
const FLAG_RED = 1 // the terrorists' flag
const FLAG_BLUE = 2 // the counter-terrorists' flag
new Float:g_dropAt[3] // by flag team; 0.0 = no attempt running
new Float:g_roundTime[3] // first recovery this round; 0.0 = none yet
new g_roundName[3][32]
new Float:g_mapBest[3]
new g_mapBestName[3][32]
new g_cvarShow
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
g_cvarShow = create_cvar("olds_returndrill_show", "1", FCVAR_NONE, "1 = tell the team the recovery time at the return", true, 0.0, true, 1.0)
AutoExecConfig(true, "olds_returndrill")
register_clcmd("say /retstat", "cmd_retstat")
register_clcmd("say_team /retstat", "cmd_retstat")
register_concmd("olds_returndrill_status", "cmd_status", ADMIN_CFG, "- attempts and recorded times")
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
}
public on_restart_round_pre()
{
for (new team = FLAG_RED; team <= FLAG_BLUE; team++)
{
g_dropAt[team] = 0.0
g_roundTime[team] = 0.0
g_roundName[team][0] = EOS
}
return HC_CONTINUE
}
team_label(flagTeam, out[], len)
{
if (flagTeam == FLAG_RED)
copy(out, len, "red")
else
copy(out, len, "blue")
}
public jctf_flag(event, player, flagTeam, bool:assist)
{
if (assist || (flagTeam != FLAG_RED && flagTeam != FLAG_BLUE))
return
switch (event)
{
case FLAG_DROPPED, FLAG_MANUALDROP:
{
// A manual drop fires both events: keep the first time.
if (g_dropAt[flagTeam] == 0.0 && g_roundTime[flagTeam] == 0.0)
g_dropAt[flagTeam] = get_gametime()
}
case FLAG_PICKED, FLAG_STOLEN, FLAG_CAPTURED, FLAG_AUTORETURN, FLAG_ADMINRETURN:
g_dropAt[flagTeam] = 0.0
case FLAG_RETURNED:
returned(player, flagTeam)
}
}
returned(player, flagTeam)
{
new Float:dropAt = g_dropAt[flagTeam]
g_dropAt[flagTeam] = 0.0
if (dropAt == 0.0 || g_roundTime[flagTeam] != 0.0)
return // no timed drop, or already recorded this round
if (!(1 <= player <= MaxClients) || !is_user_connected(player))
return
new TeamName:team = TeamName:get_member(player, m_iTeam)
if ((flagTeam == FLAG_RED && team != TEAM_TERRORIST) || (flagTeam == FLAG_BLUE && team != TEAM_CT))
return // only the flag's own team recovers it
new Float:elapsed = get_gametime() - dropAt
g_roundTime[flagTeam] = elapsed
get_user_name(player, g_roundName[flagTeam], charsmax(g_roundName[]))
new bool:best = g_mapBest[flagTeam] == 0.0 || elapsed < g_mapBest[flagTeam]
if (best)
{
g_mapBest[flagTeam] = elapsed
copy(g_mapBestName[flagTeam], charsmax(g_mapBestName[]), g_roundName[flagTeam])
}
new label[8]
team_label(flagTeam, label, charsmax(label))
log_amx("[ReturnDrill] %s flag recovered by %s in %.1f s", label, g_roundName[flagTeam], elapsed)
if (!get_pcvar_num(g_cvarShow))
return
new players[MAX_PLAYERS], count, teamName[12]
if (flagTeam == FLAG_RED)
copy(teamName, charsmax(teamName), "TERRORIST")
else
copy(teamName, charsmax(teamName), "CT")
get_players(players, count, "ceh", teamName)
for (new i = 0; i < count; i++)
{
if (best)
client_print_color(players[i], player, "^4[Return Drill]^3 %s^1 brought the flag home ^4%.1f s^1 after the drop (best on this map).", g_roundName[flagTeam], elapsed)
else
client_print_color(players[i], player, "^4[Return Drill]^3 %s^1 brought the flag home ^4%.1f s^1 after the drop.", g_roundName[flagTeam], elapsed)
}
}
public cmd_retstat(id)
{
new label[8]
for (new flagTeam = FLAG_RED; flagTeam <= FLAG_BLUE; flagTeam++)
{
team_label(flagTeam, label, charsmax(label))
if (g_roundTime[flagTeam] > 0.0)
client_print(id, print_chat, "[Return Drill] %s flag this round: %.1f s by %s.", label, g_roundTime[flagTeam], g_roundName[flagTeam])
else
client_print(id, print_chat, "[Return Drill] %s flag this round: no recovery yet.", label)
if (g_mapBest[flagTeam] > 0.0)
client_print(id, print_chat, "[Return Drill] %s flag best on this map: %.1f s by %s.", label, g_mapBest[flagTeam], g_mapBestName[flagTeam])
}
return PLUGIN_HANDLED
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new label[8], Float:now = get_gametime()
for (new flagTeam = FLAG_RED; flagTeam <= FLAG_BLUE; flagTeam++)
{
team_label(flagTeam, label, charsmax(label))
if (g_dropAt[flagTeam] > 0.0)
console_print(id, "[ReturnDrill] %s flag: dropped %.1f s ago", label, now - g_dropAt[flagTeam])
else
console_print(id, "[ReturnDrill] %s flag: no attempt running", label)
console_print(id, " round %.1f s (%s); map best %.1f s (%s)", g_roundTime[flagTeam], g_roundName[flagTeam],
g_mapBest[flagTeam], g_mapBestName[flagTeam])
}
return PLUGIN_HANDLED
}