/*
* Catch Game Mode (olds.ro workshop card LIB-0843)
* Copyright (C) 2026 daemon (olds.ro)
*
* 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: <https://www.gnu.org/licenses/>.
*
* Tag. Each round one random player is the first chaser (Terrorists); everyone else runs
* (Counter-Terrorists). Nobody has weapons. A chaser who comes within olds_catch_touchdist of
* a runner, or says a runner's name within olds_catch_calldist in sight, catches them: with
* olds_catch_swap 1 the runner becomes a chaser, with 0 they are out. The last catch wins the
* round for the chasers; runners still free when the time runs out win it.
*/
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <reapi>
#define PLUGIN "Catch Game Mode"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define TASK_SCAN 84300
#define SOUND_CATCH "weapons/knife_hit4.wav"
new Float:g_touchDist, Float:g_callDist, Float:g_roundMinutes, g_swap
new bool:g_live // a catch round is running
new g_firstChaser // this round's first chaser
new g_catches
new g_candidates
public plugin_precache()
{
precache_sound(SOUND_CATCH)
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_catch.txt")
bind_pcvar_float(create_cvar("olds_catch_touchdist", "70", FCVAR_NONE, "A chaser this close to a runner catches them", true, 20.0, true, 300.0), g_touchDist)
bind_pcvar_float(create_cvar("olds_catch_roundtime", "3.0", FCVAR_NONE, "Round length in minutes", true, 0.25, true, 30.0), g_roundMinutes)
bind_pcvar_num(create_cvar("olds_catch_swap", "1", FCVAR_NONE, "1 = caught runners become chasers, 0 = they are out", true, 0.0, true, 1.0), g_swap)
bind_pcvar_float(create_cvar("olds_catch_calldist", "300", FCVAR_NONE, "Saying a runner's name catches them this close and in sight (0 = off)", true, 0.0, true, 2000.0), g_callDist)
AutoExecConfig(true, "olds_catch")
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_pre", false)
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_post", true)
RegisterHookChain(RG_RoundEnd, "on_round_end_pre", false)
RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
RegisterHookChain(RG_CBasePlayer_HasRestrictItem, "on_restrict_pre", false)
register_forward(FM_Touch, "on_touch")
register_clcmd("say", "on_say")
register_clcmd("say_team", "on_say")
register_concmd("amx_catch_status", "cmd_status", ADMIN_RCON, "- shows the catch round")
set_task(0.1, "scan", TASK_SCAN, _, _, "b")
}
/* ------------------------------------------------------------------ rounds */
public on_restart_pre()
{
g_live = false
g_firstChaser = 0
g_catches = 0
new players[MAX_PLAYERS], count
for (new id = 1; id <= MaxClients; id++)
{
if (!is_user_connected(id) || is_user_hltv(id))
continue
new TeamName:team = TeamName:get_member(id, m_iTeam)
if (team == TEAM_TERRORIST || team == TEAM_CT)
players[count++] = id
}
g_candidates = count
if (count < 2)
return
g_firstChaser = players[random(count)]
for (new i = 0; i < count; i++)
{
new id = players[i]
new TeamName:want = (id == g_firstChaser) ? TEAM_TERRORIST : TEAM_CT
if (TeamName:get_member(id, m_iTeam) != want)
rg_set_user_team(id, want)
}
}
public on_restart_post()
{
set_member_game(m_iRoundTime, floatround(g_roundMinutes * 60.0))
if (!g_firstChaser || !is_user_connected(g_firstChaser))
return
g_live = true
new name[MAX_NAME_LENGTH]
get_user_name(g_firstChaser, name, charsmax(name))
client_print(0, print_chat, "%L", LANG_PLAYER, "CATCH_FIRST", name)
log_amx("New round: %s is the first chaser (random of %d)", name, g_candidates)
}
/* Time ran out with runners free: they win, whatever the map would say. */
public on_round_end_pre(WinStatus:status, ScenarioEventEndRound:event, Float:delay)
{
if (!g_live)
return HC_CONTINUE
g_live = false
if (event == ROUND_END_DRAW || event == ROUND_TARGET_SAVED || event == ROUND_HOSTAGE_NOT_RESCUED
|| event == ROUND_VIP_NOT_ESCAPED || event == ROUND_TERRORISTS_NOT_ESCAPED)
{
if (runners_left() > 0)
{
SetHookChainArg(1, ATYPE_INTEGER, WINSTATUS_CTS)
SetHookChainArg(2, ATYPE_INTEGER, ROUND_CTS_WIN)
client_print(0, print_chat, "%L", LANG_PLAYER, "CATCH_RUNNERS_WIN", runners_left())
}
}
return HC_CONTINUE
}
public on_spawn_post(id)
{
if (is_user_alive(id))
rg_remove_all_items(id)
}
/* No buying, no picking up: hands only. */
public on_restrict_pre(id, ItemID:item, ItemRestType:type)
{
if (type == ITEM_TYPE_BUYING || type == ITEM_TYPE_TOUCHED)
{
SetHookChainReturn(ATYPE_BOOL, true)
return HC_SUPERCEDE
}
return HC_CONTINUE
}
/* ------------------------------------------------------------------ catching */
bool:is_chaser(id)
{
return is_user_alive(id) && TeamName:get_member(id, m_iTeam) == TEAM_TERRORIST
}
bool:is_runner(id)
{
return is_user_alive(id) && TeamName:get_member(id, m_iTeam) == TEAM_CT
}
runners_left()
{
new n
for (new id = 1; id <= MaxClients; id++)
if (is_runner(id))
n++
return n
}
bool:round_running()
{
return g_live && !get_member_game(m_bFreezePeriod) && !get_member_game(m_bRoundTerminating)
}
public scan()
{
if (!round_running())
return
for (new c = 1; c <= MaxClients; c++)
{
if (!is_chaser(c))
continue
for (new r = 1; r <= MaxClients; r++)
{
if (is_runner(r) && entity_range(c, r) <= g_touchDist)
{
catch_runner(c, r, false)
if (!g_live)
return
}
}
}
}
public on_touch(toucher, touched)
{
if (toucher < 1 || toucher > MaxClients || touched < 1 || touched > MaxClients || !round_running())
return FMRES_IGNORED
if (is_chaser(toucher) && is_runner(touched))
catch_runner(toucher, touched, false)
else if (is_chaser(touched) && is_runner(toucher))
catch_runner(touched, toucher, false)
return FMRES_IGNORED
}
bool:in_sight(a, b)
{
new Float:from[3], Float:to[3], Float:ofs[3]
get_entvar(a, var_origin, from)
get_entvar(a, var_view_ofs, ofs)
from[2] += ofs[2]
get_entvar(b, var_origin, to)
new trace = create_tr2()
engfunc(EngFunc_TraceLine, from, to, IGNORE_MONSTERS, a, trace)
new Float:frac
get_tr2(trace, TR_flFraction, frac)
free_tr2(trace)
return frac >= 1.0
}
public on_say(id)
{
if (g_callDist <= 0.0 || !round_running() || !is_chaser(id))
return PLUGIN_CONTINUE
new text[64]
read_args(text, charsmax(text))
remove_quotes(text)
trim(text)
if (strlen(text) < 3)
return PLUGIN_CONTINUE
/* The runner whose name is the text, or the only one whose name contains it. */
new exact, partial, partials, name[MAX_NAME_LENGTH]
for (new r = 1; r <= MaxClients; r++)
{
if (!is_runner(r))
continue
get_user_name(r, name, charsmax(name))
if (equali(name, text))
exact = r
else if (containi(name, text) >= 0)
{
partial = r
partials++
}
}
new target = exact
if (!target && partials == 1)
target = partial
if (target && entity_range(id, target) <= g_callDist && in_sight(id, target))
catch_runner(id, target, true)
return PLUGIN_CONTINUE
}
catch_runner(chaser, runner, bool:byCall)
{
g_catches++
new left = runners_left() - 1
new cname[MAX_NAME_LENGTH], rname[MAX_NAME_LENGTH]
get_user_name(chaser, cname, charsmax(cname))
get_user_name(runner, rname, charsmax(rname))
emit_sound(runner, CHAN_ITEM, SOUND_CATCH, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
if (byCall)
client_print(0, print_chat, "%L", LANG_PLAYER, "CATCH_CALLED", cname, rname, left)
else
client_print(0, print_chat, "%L", LANG_PLAYER, "CATCH_CAUGHT", cname, rname, left)
new how[12]
copy(how, charsmax(how), "by touch")
if (byCall)
copy(how, charsmax(how), "by name")
log_amx("%s caught %s (%s), %d runner(s) left", cname, rname, how, left)
if (left <= 0)
{
/* The last runner: the chasers win before any team runs empty. */
g_live = false
rg_update_teamscores(1, 0)
rg_round_end(5.0, WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "Chasers win! Everyone was caught.")
client_print(0, print_chat, "%L", LANG_PLAYER, "CATCH_CHASERS_WIN")
if (g_swap)
rg_set_user_team(runner, TEAM_TERRORIST)
return
}
if (g_swap)
{
rg_set_user_team(runner, TEAM_TERRORIST)
rg_round_respawn(runner)
}
else
user_silentkill(runner)
}
/* ------------------------------------------------------------------ admin */
public cmd_status(id, level, cid)
{
if (id && !(get_user_flags(id) & level))
{
console_print(id, "You have no access to that command.")
return PLUGIN_HANDLED
}
new name[MAX_NAME_LENGTH]
if (g_firstChaser && is_user_connected(g_firstChaser))
get_user_name(g_firstChaser, name, charsmax(name))
new chasers
for (new p = 1; p <= MaxClients; p++)
if (is_chaser(p))
chasers++
console_print(id, "[Catch] live %d, first chaser %s, chasers %d, runners %d, catches %d, round %d s, score T %d CT %d",
g_live, name, chasers, runners_left(), g_catches, get_member_game(m_iRoundTime),
get_member_game(m_iNumTerroristWins), get_member_game(m_iNumCTWins))
return PLUGIN_HANDLED
}