/*
* Tripwire Echo (olds.ro) - Zombie Plague 5.x add-on. A living human watches
* one named doorway; the first zombie to cross it gives that human a private
* cue (DHUD line, chat note and a click), and the watch is used up.
*
* 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/>.
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#pragma reqlib "zp50_core"
native zp_core_is_zombie(id)
#define PLUGIN "Tripwire Echo"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define MAX_DOORS 32
#define DOOR_NAME 32
#define TASK_POLL 6100
#define POLL 0.1
new const CUE_SOUND[] = "buttons/button9" // stock sound/buttons/button9.wav, played with spk
new g_doorName[MAX_DOORS][DOOR_NAME]
new Float:g_min[MAX_DOORS][3]
new Float:g_max[MAX_DOORS][3]
new g_doors
new g_watch[MAX_PLAYERS + 1] = { -1, ... } // door each player watches, -1 = none
new Float:g_until[MAX_PLAYERS + 1]
new g_inside[MAX_PLAYERS + 1] // bit per door the player stood in at the last poll
new g_cvarTimeout
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
g_cvarTimeout = create_cvar("olds_tripecho_timeout", "90", FCVAR_NONE,
"Seconds a watch stays armed", true, 5.0, true, 600.0)
AutoExecConfig(true, "olds_tripecho")
register_clcmd("say", "cmd_say")
register_clcmd("say_team", "cmd_say")
register_concmd("olds_tripecho_status", "cmd_status", ADMIN_CFG, "- doorways and armed watches")
register_logevent("on_round_end", 2, "1=Round_End")
}
public plugin_cfg()
{
load_doors()
if (g_doors)
set_task(POLL, "task_poll", TASK_POLL, _, _, "b")
}
/* ---------- doorways ---------- */
load_doors()
{
new path[192], map[64]
get_configsdir(path, charsmax(path))
get_mapname(map, charsmax(map))
format(path, charsmax(path), "%s/olds_tripecho/%s.ini", path, map)
new file = fopen(path, "rt")
if (!file)
{
server_print("[Tripwire] No doorways for %s (%s): the plugin is idle on this map.", map, path)
return
}
new line[256], name[DOOR_NAME], part[6][16], lineNo
while (!feof(file) && fgets(file, line, charsmax(line)))
{
lineNo++
trim(line)
if (!line[0] || line[0] == ';' || line[0] == '#')
continue
if (parse(line, name, charsmax(name), part[0], charsmax(part[]), part[1], charsmax(part[]), part[2], charsmax(part[]),
part[3], charsmax(part[]), part[4], charsmax(part[]), part[5], charsmax(part[])) != 7 || !name[0] || !all_numbers(part))
{
log_amx("[Tripwire] %s line %d skipped: expected ^"name^" x1 y1 z1 x2 y2 z2", path, lineNo)
continue
}
if (g_doors >= MAX_DOORS)
{
log_amx("[Tripwire] %s: more than %d doorways, the rest are skipped", path, MAX_DOORS)
break
}
for (new axis = 0; axis < 3; axis++)
{
new Float:a = str_to_float(part[axis]), Float:b = str_to_float(part[axis + 3])
g_min[g_doors][axis] = floatmin(a, b)
g_max[g_doors][axis] = floatmax(a, b)
}
copy(g_doorName[g_doors], charsmax(g_doorName[]), name)
g_doors++
}
fclose(file)
server_print("[Tripwire] %d doorway(s) loaded for %s.", g_doors, map)
}
bool:all_numbers(const part[][])
{
for (new i = 0; i < 6; i++)
{
new j, digits, dots
if (part[i][0] == '-' || part[i][0] == '+')
j++
for (; part[i][j]; j++)
{
if (part[i][j] == '.')
{
if (++dots > 1)
return false
}
else if ('0' <= part[i][j] <= '9')
digits++
else
return false
}
if (!digits)
return false
}
return true
}
doors_at(const Float:origin[3])
{
new bits
for (new d = 0; d < g_doors; d++)
{
if (g_min[d][0] <= origin[0] <= g_max[d][0]
&& g_min[d][1] <= origin[1] <= g_max[d][1]
&& g_min[d][2] <= origin[2] <= g_max[d][2])
bits |= (1 << d)
}
return bits
}
// Exact name first (case ignored), else a unique name that starts with the text.
find_door(const text[])
{
for (new d = 0; d < g_doors; d++)
{
if (equali(g_doorName[d], text))
return d
}
new found = -1, length = strlen(text)
for (new d = 0; d < g_doors; d++)
{
if (equali(g_doorName[d], text, length))
{
if (found >= 0)
return -2 // more than one match
found = d
}
}
return found
}
/* ---------- watches ---------- */
cancel(id, const why[])
{
if (g_watch[id] < 0)
return
new door = g_watch[id]
g_watch[id] = -1
if (why[0] && is_user_connected(id))
client_print(id, print_chat, "[Tripwire] Your watch on %s ended: %s.", g_doorName[door], why)
}
public client_putinserver(id)
{
g_watch[id] = -1
g_inside[id] = 0
}
public client_disconnected(id)
{
g_watch[id] = -1
g_inside[id] = 0
}
public on_round_end()
{
for (new id = 1; id <= MaxClients; id++)
cancel(id, "the round is over")
}
public cmd_say(id)
{
new text[96]
read_args(text, charsmax(text))
remove_quotes(text)
trim(text)
if (!equali(text, "/watch", 6) || (text[6] && text[6] != ' '))
return PLUGIN_CONTINUE
new arg[64]
copy(arg, charsmax(arg), text[6])
trim(arg)
if (!g_doors)
{
client_print(id, print_chat, "[Tripwire] This map has no doorways to watch.")
return PLUGIN_HANDLED
}
if (!arg[0])
{
list_doors(id)
return PLUGIN_HANDLED
}
if (equali(arg, "off"))
{
if (g_watch[id] < 0)
client_print(id, print_chat, "[Tripwire] You are not watching a doorway.")
else
cancel(id, "you stopped it")
return PLUGIN_HANDLED
}
if (!is_user_alive(id) || zp_core_is_zombie(id))
{
client_print(id, print_chat, "[Tripwire] Only a living human can watch a doorway.")
return PLUGIN_HANDLED
}
new door = find_door(arg)
if (door == -2)
{
client_print(id, print_chat, "[Tripwire] ^"%s^" matches more than one doorway; type more of the name.", arg)
return PLUGIN_HANDLED
}
if (door < 0)
{
client_print(id, print_chat, "[Tripwire] No doorway called ^"%s^".", arg)
list_doors(id)
return PLUGIN_HANDLED
}
new timeout = get_pcvar_num(g_cvarTimeout)
if (g_watch[id] >= 0 && g_watch[id] != door)
client_print(id, print_chat, "[Tripwire] %s replaces your watch on %s.", g_doorName[door], g_doorName[g_watch[id]])
g_watch[id] = door
g_until[id] = get_gametime() + float(timeout)
client_print(id, print_chat, "[Tripwire] Watching %s for %d seconds: the first zombie through it will be reported to you.", g_doorName[door], timeout)
return PLUGIN_HANDLED
}
list_doors(id)
{
new text[190], length
length = copy(text, charsmax(text), "[Tripwire] Doorways:")
for (new d = 0; d < g_doors && length < charsmax(text) - 4; d++)
{
if (d)
length += formatex(text[length], charsmax(text) - length, ", %s", g_doorName[d])
else
length += formatex(text[length], charsmax(text) - length, " %s", g_doorName[d])
}
client_print(id, print_chat, "%s. Type /watch <name> or /watch off.", text)
}
public task_poll()
{
new Float:now = get_gametime()
for (new id = 1; id <= MaxClients; id++)
{
if (g_watch[id] < 0)
continue
if (!is_user_alive(id))
cancel(id, "you died")
else if (zp_core_is_zombie(id))
cancel(id, "you were infected")
else if (now >= g_until[id])
cancel(id, "time is up")
}
new players[MAX_PLAYERS], count, Float:origin[3]
get_players(players, count, "a")
new seen[MAX_PLAYERS + 1]
for (new i = 0; i < count; i++)
{
new crosser = players[i]
pev(crosser, pev_origin, origin)
new bits = doors_at(origin)
new entered = bits & ~g_inside[crosser]
g_inside[crosser] = bits
seen[crosser] = 1
if (entered && zp_core_is_zombie(crosser))
echo(crosser, entered)
}
for (new id = 1; id <= MaxClients; id++)
{
if (!seen[id])
g_inside[id] = 0 // dead or gone: a respawn inside counts as entering
}
}
echo(crosser, entered)
{
new name[32]
get_user_name(crosser, name, charsmax(name))
for (new owner = 1; owner <= MaxClients; owner++)
{
new door = g_watch[owner]
if (door < 0 || !(entered & (1 << door)))
continue
g_watch[owner] = -1
set_dhudmessage(255, 60, 60, -1.0, 0.30, 0, 0.0, 3.0, 0.05, 0.5)
show_dhudmessage(owner, "Tripwire: a zombie crossed %s", g_doorName[door])
client_print(owner, print_chat, "[Tripwire] %s crossed %s. Your watch is used up.", name, g_doorName[door])
client_cmd(owner, "spk %s", CUE_SOUND)
server_print("[Tripwire] cue for watcher #%d: %s crossed %s", owner, name, g_doorName[door])
}
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[Tripwire] %d doorway(s), timeout %d s", g_doors, get_pcvar_num(g_cvarTimeout))
for (new d = 0; d < g_doors; d++)
console_print(id, " %d. %s", d + 1, g_doorName[d])
new name[32], Float:now = get_gametime()
for (new player = 1; player <= MaxClients; player++)
{
if (!is_user_connected(player))
continue
get_user_name(player, name, charsmax(name))
if (g_watch[player] >= 0)
console_print(id, " %s watches %s (%d s left)", name, g_doorName[g_watch[player]], floatround(g_until[player] - now, floatround_ceil))
else
console_print(id, " %s: no watch", name)
}
return PLUGIN_HANDLED
}