/*
* Hidden in Plain Sight (olds.ro workshop card AMX-014)
*
* Hide and Seek: once a second the plugin notes which named map sector each
* hider is in, keeping only changes (A, A, B, A, C is stored as A, B, A, C).
* When the round closes, everyone is told the last three sectors of the last
* surviving hider. Live routes stay private: during the round a hider can read
* only their own route with /route, and seekers get nothing.
*
* Needs: AMX Mod X 1.10, ReGameDLL_CS + ReAPI, a Hide and Seek core that plays
* hiders as terrorists and seekers as counter-terrorists with the game's own
* rounds (as "Hide And Seek: Ultimate", github.com/iwonz/amxx-hns-ultimate,
* does; it has no natives, so none are used).
*
* Sectors: addons/amxmodx/configs/olds_route/<map>.ini, one box per line:
* "Sector name" x1 y1 z1 x2 y2 z2
* (two opposite corners, any order). The first box that holds the player
* wins; outside every box nothing is noted. A map without a file is not
* tracked. See _example.ini.
*
* The last surviving hider: when the round closes with one hider alive, that
* hider; with none alive, the hider killed last; if the last two hiders died
* in the same frame, a tie naming both. With two or more hiders alive there is
* no last survivor and nothing is revealed.
*
* Cvar: olds_route_reveal 1 (0 = no end-of-round message).
* Commands: say /route; olds_route_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 "Hidden in Plain Sight"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
const MAX_SECTORS = 64
const SECTOR_NAME = 32
const ROUTE_MAX = 16 // sectors kept per hider (the oldest is dropped)
const REVEAL_COUNT = 3
const TASK_SAMPLE = 7411
const NO_SECTOR = -1
new const REVEAL_SOUND[] = "events/task_complete"
new g_sectorName[MAX_SECTORS][SECTOR_NAME]
new Float:g_sectorMin[MAX_SECTORS][3]
new Float:g_sectorMax[MAX_SECTORS][3]
new g_sectorCount
new g_sectorFile[128]
new g_route[MAX_PLAYERS + 1][ROUTE_MAX] // sector indexes, oldest first
new g_routeLength[MAX_PLAYERS + 1]
new g_routeTotal[MAX_PLAYERS + 1] // changes noted this round, dropped ones included
new g_lastDead, Float:g_lastDeadTime // the hider killed last this round
new g_prevDead, Float:g_prevDeadTime // and the one before
new bool:g_roundLive
new bool:g_revealed
new g_reveal
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_route.txt")
bind_pcvar_num(create_cvar("olds_route_reveal", "1", FCVAR_NONE,
"1 = tell everyone the last hider's last three sectors when the round closes.", true, 0.0, true, 1.0), g_reveal)
AutoExecConfig(true, "olds_route")
register_clcmd("say /route", "cmd_route")
register_clcmd("say_team /route", "cmd_route")
register_concmd("olds_route_status", "cmd_status", ADMIN_CFG, "- sectors and every hider's route")
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
RegisterHookChain(RG_RoundEnd, "on_round_end_post", true)
load_sectors()
if (g_sectorCount)
set_task(1.0, "task_sample", TASK_SAMPLE, _, _, "b")
}
public plugin_precache()
{
// Stock sound, already on every client; precached so spk finds it on any map.
precache_sound(fmt("%s.wav", REVEAL_SOUND))
}
/* ---------- sectors ---------- */
load_sectors()
{
new map[64]
get_mapname(map, charsmax(map))
get_configsdir(g_sectorFile, charsmax(g_sectorFile))
format(g_sectorFile, charsmax(g_sectorFile), "%s/olds_route/%s.ini", g_sectorFile, map)
new file = fopen(g_sectorFile, "rt")
if (!file)
return
new line[256], name[SECTOR_NAME], value[6][16], lineNumber
while (fgets(file, line, charsmax(line)))
{
lineNumber++
trim(line)
if (!line[0] || line[0] == ';' || (line[0] == '/' && line[1] == '/'))
continue
if (g_sectorCount == MAX_SECTORS)
{
log_amx("%s: more than %d sectors, the rest are ignored", g_sectorFile, MAX_SECTORS)
break
}
if (parse(line, name, charsmax(name), value[0], charsmax(value[]), value[1], charsmax(value[]),
value[2], charsmax(value[]), value[3], charsmax(value[]), value[4], charsmax(value[]),
value[5], charsmax(value[])) != 7 || !name[0] || !all_numbers(value))
{
log_amx("%s line %d: expected ^"name^" x1 y1 z1 x2 y2 z2, skipped", g_sectorFile, lineNumber)
continue
}
for (new axis = 0; axis < 3; axis++)
{
new Float:a = str_to_float(value[axis]), Float:b = str_to_float(value[axis + 3])
g_sectorMin[g_sectorCount][axis] = floatmin(a, b)
g_sectorMax[g_sectorCount][axis] = floatmax(a, b)
}
copy(g_sectorName[g_sectorCount], charsmax(g_sectorName[]), name)
g_sectorCount++
}
fclose(file)
}
bool:all_numbers(const value[6][16])
{
for (new v = 0; v < 6; v++)
{
new i = (value[v][0] == '-' || value[v][0] == '+') ? 1 : 0, digits
for (; value[v][i]; i++)
{
if (isdigit(value[v][i]))
digits++
else if (value[v][i] != '.')
return false
}
if (!digits)
return false
}
return true
}
sector_at(const Float:origin[3])
{
for (new s = 0; s < g_sectorCount; s++)
{
if (g_sectorMin[s][0] <= origin[0] <= g_sectorMax[s][0]
&& g_sectorMin[s][1] <= origin[1] <= g_sectorMax[s][1]
&& g_sectorMin[s][2] <= origin[2] <= g_sectorMax[s][2])
return s
}
return NO_SECTOR
}
/* ---------- sampling ---------- */
bool:is_hider(id)
{
return TeamName:get_member(id, m_iTeam) == TEAM_TERRORIST
}
public task_sample()
{
if (!g_roundLive)
return
// A round closed by rg_round_end() from another plugin skips RG_RoundEnd.
if (get_member_game(m_bRoundTerminating))
{
close_round()
return
}
new players[MAX_PLAYERS], count, Float:origin[3]
get_players(players, count, "ah")
for (new i = 0; i < count; i++)
{
new id = players[i]
if (!is_hider(id))
continue
get_entvar(id, var_origin, origin)
new sector = sector_at(origin)
if (sector == NO_SECTOR)
continue
// Push only changes; a visit to the same sector again later is a new entry.
if (g_routeLength[id] && g_route[id][g_routeLength[id] - 1] == sector)
continue
if (g_routeLength[id] == ROUTE_MAX)
{
for (new j = 1; j < ROUTE_MAX; j++)
g_route[id][j - 1] = g_route[id][j]
g_routeLength[id]--
}
g_route[id][g_routeLength[id]++] = sector
g_routeTotal[id]++
}
}
/* ---------- rounds ---------- */
public on_restart_round_pre()
{
for (new id = 1; id <= MaxClients; id++)
clear_route(id)
g_lastDead = 0
g_prevDead = 0
g_lastDeadTime = 0.0
g_prevDeadTime = 0.0
g_revealed = false
g_roundLive = true
return HC_CONTINUE
}
clear_route(id)
{
g_routeLength[id] = 0
g_routeTotal[id] = 0
}
public client_putinserver(id)
{
clear_route(id)
}
public client_disconnected(id)
{
clear_route(id)
if (g_lastDead == id)
g_lastDead = 0
if (g_prevDead == id)
g_prevDead = 0
}
public on_killed_post(victim, attacker, gib)
{
if (!g_roundLive || !(1 <= victim <= MaxClients) || !is_hider(victim))
return HC_CONTINUE
g_prevDead = g_lastDead
g_prevDeadTime = g_lastDeadTime
g_lastDead = victim
g_lastDeadTime = get_gametime()
return HC_CONTINUE
}
public on_round_end_post(WinStatus:status, ScenarioEventEndRound:event, Float:delay)
{
if (event == ROUND_GAME_COMMENCE || event == ROUND_GAME_RESTART)
return HC_CONTINUE
if (g_roundLive && get_member_game(m_bRoundTerminating))
close_round()
return HC_CONTINUE
}
close_round()
{
g_roundLive = false
// Samples from the dying frame are in; settle the last survivor now.
if (g_revealed || !g_sectorCount)
return
g_revealed = true
new players[MAX_PLAYERS], count, alive, survivor
get_players(players, count, "ah")
for (new i = 0; i < count; i++)
{
if (is_hider(players[i]))
{
alive++
survivor = players[i]
}
}
if (alive > 1)
return
if (!g_reveal)
return
if (alive == 1)
{
reveal(survivor, "ROUTE_LAST_ALIVE")
}
else if (g_lastDead && g_prevDead && g_lastDeadTime == g_prevDeadTime)
{
new first[MAX_NAME_LENGTH], second[MAX_NAME_LENGTH]
get_user_name(g_prevDead, first, charsmax(first))
get_user_name(g_lastDead, second, charsmax(second))
client_print_color(0, print_team_default, "^4[Route]^1 %L", LANG_PLAYER, "ROUTE_TIE", first, second)
reveal(g_prevDead, "ROUTE_TIED")
reveal(g_lastDead, "ROUTE_TIED")
}
else if (g_lastDead)
{
reveal(g_lastDead, "ROUTE_LAST_KILLED")
}
}
reveal(id, const key[])
{
if (!is_user_connected(id))
return
new name[MAX_NAME_LENGTH], sectors[REVEAL_COUNT * (SECTOR_NAME + 3) + 8]
get_user_name(id, name, charsmax(name))
if (!format_route(id, REVEAL_COUNT, sectors, charsmax(sectors)))
{
client_print_color(0, print_team_default, "^4[Route]^1 %L", LANG_PLAYER, "ROUTE_NONE", name)
return
}
client_print_color(0, print_team_default, "^4[Route]^1 %L", LANG_PLAYER, key, name, sectors)
client_cmd(0, "spk %s", REVEAL_SOUND)
}
/* The last `limit` sectors, oldest first, as "A > B > C". Returns how many. */
format_route(id, limit, output[], len)
{
output[0] = EOS
new first = max(0, g_routeLength[id] - limit), length
for (new i = first; i < g_routeLength[id]; i++)
length += formatex(output[length], len - length, "%s%s", i > first ? " > " : "", g_sectorName[g_route[id][i]])
return g_routeLength[id] - first
}
/* ---------- commands ---------- */
public cmd_route(id)
{
// Seekers and spectators: nothing, so no sector leaks.
if (!is_user_connected(id) || !is_hider(id))
return PLUGIN_HANDLED
if (!g_sectorCount)
{
client_print_color(id, print_team_default, "^4[Route]^1 %L", id, "ROUTE_NO_SECTORS")
return PLUGIN_HANDLED
}
new sectors[ROUTE_MAX * (SECTOR_NAME + 3) + 8]
if (!format_route(id, ROUTE_MAX, sectors, charsmax(sectors)))
client_print_color(id, print_team_default, "^4[Route]^1 %L", id, "ROUTE_OWN_EMPTY")
else
client_print_color(id, print_team_default, "^4[Route]^1 %L", id, "ROUTE_OWN", sectors)
return PLUGIN_HANDLED
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
if (!g_sectorCount)
{
console_print(id, "[Route] no sectors (%s); nothing is tracked on this map", g_sectorFile)
return PLUGIN_HANDLED
}
console_print(id, "[Route] %d sectors from %s; round %s; reveal %d", g_sectorCount, g_sectorFile,
g_roundLive ? "live" : "closed", g_reveal)
new players[MAX_PLAYERS], count, name[MAX_NAME_LENGTH], sectors[ROUTE_MAX * (SECTOR_NAME + 3) + 8]
get_players(players, count, "h")
for (new i = 0; i < count; i++)
{
if (!is_hider(players[i]))
continue
get_user_name(players[i], name, charsmax(name))
format_route(players[i], ROUTE_MAX, sectors, charsmax(sectors))
console_print(id, "[Route] %s (%s): %d change(s): %s", name, is_user_alive(players[i]) ? "alive" : "dead",
g_routeTotal[players[i]], sectors[0] ? sectors : "-")
}
return PLUGIN_HANDLED
}