/*
* Platform Courtesy (olds.ro workshop card AMX-047)
*
* Bunny hop: on maps with shared platforms that collapse or reset under a
* runner, a player can watch up to olds_platcourt_max platforms. While
* another runner stands on a watched platform, the watcher sees a DHUD line:
* Platform 2 (Red lift): occupied by Bravo
* It clears as soon as the platform is free again.
*
* say /platform <number> watch a platform, or stop watching it
* say /platform off stop watching all
* say /platform list the platforms and the ones you watch
*
* Platforms: addons/amxmodx/configs/olds_platcourt/<map>.ini, one per line,
* numbered from 1 in file order:
* "targetname" "Label"
* Every entity with that targetname belongs to the platform. A map without
* the file has no platforms (/platform says so).
*
* Contact: every 0.2 s, each living player with FL_ONGROUND stands on
* pev_groundentity; if that entity belongs to a platform, the player occupies
* it. Dead players occupy nothing, and you never see a marker for yourself.
* When a platform's entities disappear (the map resets them) they are looked
* up again by targetname every 5 seconds.
*
* Cvar: olds_platcourt_max 3 (1-10). Command: olds_platcourt_status (ADMIN_CFG).
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>
#define PLUGIN "Platform Courtesy"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
const MAX_PLATFORMS = 32
const MAX_PARTS = 8 // entities per platform
const LABEL_LENGTH = 32
const TASK_POLL = 4711
const TASK_RESCAN = 4712
const Float:POLL = 0.2
new g_target[MAX_PLATFORMS][64]
new g_label[MAX_PLATFORMS][LABEL_LENGTH]
new g_part[MAX_PLATFORMS][MAX_PARTS]
new g_parts[MAX_PLATFORMS]
new g_count
new g_file[160]
new g_occupant[MAX_PLATFORMS] // first runner found on the platform, 0 = free
new g_watch[MAX_PLAYERS + 1] // bit per platform
new Float:g_nextUse[MAX_PLAYERS + 1]
new g_max
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_platcourt.txt")
bind_pcvar_num(create_cvar("olds_platcourt_max", "3", FCVAR_NONE,
"Platforms one player may watch at once (1-10).", true, 1.0, true, 10.0), g_max)
AutoExecConfig(true, "olds_platcourt")
register_clcmd("say", "on_say")
register_clcmd("say_team", "on_say")
register_concmd("olds_platcourt_status", "cmd_status", ADMIN_CFG, "- the platforms and who is on them")
load_platforms()
if (!g_count)
return
scan_parts()
set_task(POLL, "task_poll", TASK_POLL, _, _, "b")
set_task(5.0, "task_rescan", TASK_RESCAN, _, _, "b")
}
/* ---------- platforms ---------- */
load_platforms()
{
new map[64]
get_mapname(map, charsmax(map))
get_configsdir(g_file, charsmax(g_file))
format(g_file, charsmax(g_file), "%s/olds_platcourt/%s.ini", g_file, map)
new file = fopen(g_file, "rt")
if (!file)
return
new line[160], target[64], label[LABEL_LENGTH], number
while (fgets(file, line, charsmax(line)))
{
number++
trim(line)
if (!line[0] || line[0] == ';' || (line[0] == '/' && line[1] == '/'))
continue
if (g_count == MAX_PLATFORMS)
{
log_amx("%s: more than %d platforms, the rest are ignored", g_file, MAX_PLATFORMS)
break
}
if (parse(line, target, charsmax(target), label, charsmax(label)) != 2 || !target[0] || !label[0])
{
log_amx("%s line %d: expected ^"targetname^" ^"Label^", skipped", g_file, number)
continue
}
copy(g_target[g_count], charsmax(g_target[]), target)
copy(g_label[g_count], charsmax(g_label[]), label)
g_count++
}
fclose(file)
}
scan_parts()
{
for (new p = 0; p < g_count; p++)
{
g_parts[p] = 0
new entity = MaxClients
while ((entity = engfunc(EngFunc_FindEntityByString, entity, "targetname", g_target[p])) > 0
&& g_parts[p] < MAX_PARTS)
g_part[p][g_parts[p]++] = entity
}
}
public task_rescan()
{
for (new p = 0; p < g_count; p++)
{
for (new i = 0; i < g_parts[p]; i++)
{
if (!part_valid(p, g_part[p][i]))
{
scan_parts()
return
}
}
if (!g_parts[p])
{
scan_parts()
return
}
}
}
bool:part_valid(p, entity)
{
if (is_nullent(entity))
return false
new name[64]
get_entvar(entity, var_targetname, name, charsmax(name))
return bool:equal(name, g_target[p])
}
platform_of(entity)
{
if (entity <= MaxClients)
return -1
for (new p = 0; p < g_count; p++)
for (new i = 0; i < g_parts[p]; i++)
if (g_part[p][i] == entity)
return part_valid(p, entity) ? p : -1
return -1
}
/* ---------- polling ---------- */
public task_poll()
{
for (new p = 0; p < g_count; p++)
g_occupant[p] = 0
// Who stands where: only living runners on the ground.
for (new id = 1; id <= MaxClients; id++)
{
if (!is_user_alive(id) || !(pev(id, pev_flags) & FL_ONGROUND))
continue
new p = platform_of(pev(id, pev_groundentity))
if (p >= 0 && !g_occupant[p])
g_occupant[p] = id
}
for (new id = 1; id <= MaxClients; id++)
{
if (!g_watch[id] || !is_user_connected(id))
continue
new line[192], written, name[MAX_NAME_LENGTH]
for (new p = 0; p < g_count; p++)
{
if (!(g_watch[id] & (1 << p)) || !g_occupant[p] || g_occupant[p] == id)
continue
// Somebody else may share it with the watcher.
new other = other_occupant(p, id)
if (!other)
continue
get_user_name(other, name, charsmax(name))
written += formatex(line[written], charsmax(line) - written, "%s%L", written ? "^n" : "", id,
"PLATCOURT_HUD", p + 1, g_label[p], name)
}
if (!written)
continue
set_dhudmessage(255, 160, 60, -1.0, 0.62, 0, 0.0, POLL + 0.15, 0.0, 0.0)
show_dhudmessage(id, "%s", line)
}
}
/* A runner other than the watcher on platform p, or 0. */
other_occupant(p, watcher)
{
if (g_occupant[p] != watcher)
return g_occupant[p]
for (new id = 1; id <= MaxClients; id++)
{
if (id == watcher || !is_user_alive(id) || !(pev(id, pev_flags) & FL_ONGROUND))
continue
if (platform_of(pev(id, pev_groundentity)) == p)
return id
}
return 0
}
/* ---------- /platform ---------- */
public on_say(id)
{
if (!is_user_connected(id))
return PLUGIN_CONTINUE
new text[48]
read_args(text, charsmax(text))
remove_quotes(text)
trim(text)
if (!equali(text, "/platform", 9) || (text[9] && text[9] != ' '))
return PLUGIN_CONTINUE
new Float:now = get_gametime()
if (now < g_nextUse[id])
return PLUGIN_HANDLED
g_nextUse[id] = now + 1.0
if (!g_count)
{
say_to(id, "PLATCOURT_NO_PLATFORMS")
return PLUGIN_HANDLED
}
new arg[16]
copy(arg, charsmax(arg), text[9])
trim(arg)
if (!arg[0])
list_platforms(id)
else if (equali(arg, "off"))
{
g_watch[id] = 0
say_to(id, "PLATCOURT_ALL_OFF")
}
else
toggle(id, arg)
return PLUGIN_HANDLED
}
toggle(id, const arg[])
{
new number = is_digits(arg) ? str_to_num(arg) : 0
if (!(1 <= number <= g_count))
{
say_to(id, "PLATCOURT_BAD_NUMBER", g_count)
return
}
new p = number - 1, bit = 1 << p
if (g_watch[id] & bit)
{
g_watch[id] &= ~bit
say_to(id, "PLATCOURT_UNWATCHED", number, g_label[p])
return
}
if (watched(id) >= g_max)
{
say_to(id, "PLATCOURT_LIMIT", g_max)
return
}
g_watch[id] |= bit
say_to(id, "PLATCOURT_WATCHING", number, g_label[p])
}
watched(id)
{
new count
for (new p = 0; p < g_count; p++)
if (g_watch[id] & (1 << p))
count++
return count
}
list_platforms(id)
{
new line[192], written
for (new p = 0; p < g_count; p++)
written += formatex(line[written], charsmax(line) - written, "%s%d %s%s", p ? ", " : "", p + 1, g_label[p],
(g_watch[id] & (1 << p)) ? " *" : "")
say_to(id, "PLATCOURT_LIST", line)
}
bool:is_digits(const text[])
{
if (!text[0] || strlen(text) > 2)
return false
for (new i = 0; text[i]; i++)
if (!isdigit(text[i]))
return false
return true
}
say_to(id, const key[], any:...)
{
new pattern[160], message[224]
formatex(pattern, charsmax(pattern), "%L", id, key)
vformat(message, charsmax(message), pattern, 3)
client_print_color(id, print_team_default, "^4[Platforms]^1 %s", message)
}
public client_disconnected(id)
{
g_watch[id] = 0
g_nextUse[id] = 0.0
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[Platforms] %d platform(s) from %s; up to %d watched each", g_count, g_file, g_max)
new name[MAX_NAME_LENGTH]
for (new p = 0; p < g_count; p++)
{
name[0] = EOS
if (g_occupant[p] && is_user_connected(g_occupant[p]))
get_user_name(g_occupant[p], name, charsmax(name))
console_print(id, "[Platforms] %d. %s (^"%s^", %d part(s)): %s", p + 1, g_label[p], g_target[p], g_parts[p],
name[0] ? name : "free")
}
return PLUGIN_HANDLED
}