/*
* Head-Start Handshake (olds.ro workshop card AMX-050)
*
* Hide and Seek: a player who joins mid-round is told their actual role and
* the phase of the hunt, for example
* You are a seeker. Head start active: seekers are held until the countdown ends.
* You are a hider. Hunt live: seekers are out.
* and anyone can ask again with /phase.
*
* Needs: AMX Mod X 1.10, ReGameDLL_CS + ReAPI, and Hide And Seek: Ultimate
* (github.com/iwonz/amxx-hns-ultimate) or a core that works the same way.
* That core has no natives, so the plugin reads the state the core itself
* sets, every time, and keeps no countdown of its own:
* - role: hiders are terrorists, seekers are counter-terrorists (the core
* swaps the teams between rounds, so the answer follows the transfer);
* - head start: after freeze time the core holds every living seeker with
* FL_FROZEN until its countdown ends;
* - freeze time and round end: the game's own m_bFreezePeriod and
* m_bRoundTerminating; without both teams the core does not start a hunt.
*
* Late joiners: olds_phase_delay seconds after joining (so the core has put
* them on a team) and again after their first spawn, once each.
*
* Cvar: olds_phase_delay 3 (1-15). Commands: say /phase, olds_phase_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 "Head-Start Handshake"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
const TASK_JOIN = 5600
const TASK_SPAWN = 5700
enum Phase
{
PHASE_WAITING = 0, // not both teams: no hunt
PHASE_FREEZE, // freeze time
PHASE_HEAD_START, // seekers held by the core's countdown
PHASE_LIVE, // seekers out
PHASE_OVER // round ended
}
new bool:g_firstSpawn[MAX_PLAYERS + 1] // waiting for the first spawn after joining
new Float:g_nextUse[MAX_PLAYERS + 1]
new g_delay
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_phase.txt")
bind_pcvar_num(create_cvar("olds_phase_delay", "3", FCVAR_NONE,
"Seconds after joining or spawning before the status line (1-15).", true, 1.0, true, 15.0), g_delay)
AutoExecConfig(true, "olds_phase")
register_clcmd("say /phase", "cmd_phase")
register_clcmd("say_team /phase", "cmd_phase")
register_concmd("olds_phase_status", "cmd_status", ADMIN_CFG, "- the phase as read from the game")
RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
}
/* ---------- reading the core's state ---------- */
Phase:current_phase()
{
if (get_member_game(m_bRoundTerminating))
return PHASE_OVER
if (!get_playersnum_ex(GetPlayers_MatchTeam, "TERRORIST") || !get_playersnum_ex(GetPlayers_MatchTeam, "CT"))
return PHASE_WAITING
if (get_member_game(m_bFreezePeriod))
return PHASE_FREEZE
new players[MAX_PLAYERS], count
get_players_ex(players, count, GetPlayers_ExcludeDead | GetPlayers_MatchTeam, "CT")
for (new i = 0; i < count; i++)
if (get_entvar(players[i], var_flags) & FL_FROZEN)
return PHASE_HEAD_START
return PHASE_LIVE
}
tell(id)
{
new role[64], phase[96]
switch (TeamName:get_member(id, m_iTeam))
{
case TEAM_TERRORIST: formatex(role, charsmax(role), "%L", id, "PHASE_ROLE_HIDER")
case TEAM_CT: formatex(role, charsmax(role), "%L", id, "PHASE_ROLE_SEEKER")
default: formatex(role, charsmax(role), "%L", id, "PHASE_ROLE_NONE")
}
switch (current_phase())
{
case PHASE_WAITING: formatex(phase, charsmax(phase), "%L", id, "PHASE_WAITING")
case PHASE_FREEZE: formatex(phase, charsmax(phase), "%L", id, "PHASE_FREEZE")
case PHASE_HEAD_START: formatex(phase, charsmax(phase), "%L", id, "PHASE_HEAD_START")
case PHASE_LIVE: formatex(phase, charsmax(phase), "%L", id, "PHASE_LIVE")
default: formatex(phase, charsmax(phase), "%L", id, "PHASE_OVER")
}
client_print_color(id, print_team_default, "^4[HNS]^1 %s ^3%s", role, phase)
}
/* ---------- late joiners ---------- */
public client_putinserver(id)
{
g_firstSpawn[id] = true
remove_task(TASK_JOIN + id)
remove_task(TASK_SPAWN + id)
set_task(float(g_delay), "task_join", TASK_JOIN + id)
}
public task_join(taskId)
{
new id = taskId - TASK_JOIN
// Already spawned and about to be told: say it once, after the spawn.
if (is_user_connected(id) && !task_exists(TASK_SPAWN + id))
tell(id)
}
public on_spawn_post(id)
{
if (!(1 <= id <= MaxClients) || !g_firstSpawn[id] || !is_user_alive(id))
return HC_CONTINUE
g_firstSpawn[id] = false
remove_task(TASK_JOIN + id)
set_task(float(g_delay), "task_spawn", TASK_SPAWN + id)
return HC_CONTINUE
}
public task_spawn(taskId)
{
new id = taskId - TASK_SPAWN
if (is_user_connected(id))
tell(id)
}
public client_disconnected(id)
{
g_firstSpawn[id] = false
g_nextUse[id] = 0.0
remove_task(TASK_JOIN + id)
remove_task(TASK_SPAWN + id)
}
/* ---------- commands ---------- */
public cmd_phase(id)
{
if (!is_user_connected(id))
return PLUGIN_HANDLED
new Float:now = get_gametime()
if (now < g_nextUse[id])
return PLUGIN_HANDLED
g_nextUse[id] = now + 1.0
tell(id)
return PLUGIN_HANDLED
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new const names[Phase][] = { "waiting for both teams", "freeze time", "head start active", "hunt live", "round over" }
console_print(id, "[HNS] phase: %s; hiders %d, seekers %d; status delay %d s", names[current_phase()],
get_playersnum_ex(GetPlayers_MatchTeam, "TERRORIST"), get_playersnum_ex(GetPlayers_MatchTeam, "CT"), g_delay)
return PLUGIN_HANDLED
}