/*
* Last Splatter (olds.ro workshop card AMX-003)
*
* Counts each side's confirmed paint hits in named field sectors and, when the
* round ends, tells each team where it was busiest. Players type /splat to see
* their team's last report again. The plugin only reads game events: it never
* changes damage, health or frags.
*
* Needs: AMX Mod X 1.10, ReGameDLL_CS + ReAPI, and the "Paintball Gun" 1.1 core.
*
* How a paint hit is recognised
* The core has no hit forward. Its paintball touch handler, fw_touch() in
* paintballgun.sma 1.1 (WhooKid & O'Zone), line 321 of the copy at
* github.com/TheDoctor0/AMXXLegacy (commit 2736cf1), applies a hit as:
* ExecuteHam(Ham_TakeDamage, ent, owner, owner, float(get_pcvar_num(damge)), 4098);
* that is, the shooter is both inflictor and attacker, and 4098 is
* DMG_BULLET | DMG_NEVERGIB. ExecuteHam skips Ham hooks but not ReAPI's
* hookchain, so this plugin sees the call. A core build that passes its
* ball entity ("pbBullet", or "pbPaint" once it has splatted) as the
* inflictor, owned by the shooter, is accepted too.
* A normal bullet uses the same damage bits, but it always passes through
* TraceAttack first in the same frame. So a hit counts when:
* - the damage bits match and the inflictor is the shooter or their paintball,
* - no TraceAttack by that attacker on that victim ran in this frame,
* - attacker and victim are on opposing teams,
* - the victim actually lost health or died (not blocked),
* - and it is the first such hit for that pair in this frame.
* The hit is placed where the victim stood.
*
* Sectors: configs/olds_splat/<map>.ini, one per line:
* "Name" x1 y1 z1 x2 y2 z2 (two opposite corners of a box)
* Maps without that file keep hit tracking switched off.
*
* Cvar: olds_splat_minhits (1-1000, default 5) hides sectors below that count.
* Commands: say /splat, say_team /splat; olds_splat_status (ADMIN_CFG) prints
* this round's counts and the last reports to the console.
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#include <reapi>
#define PLUGIN "Last Splatter"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
// The Paintball core this plugin reads hits from, as it registers itself.
#define CORE_NAME "Paintball Gun"
#define CORE_VERSION "1.1"
const MAX_SECTORS = 32
const SECTOR_NAME_LEN = 32
const REPORT_LEN = 192
const PAINT_DAMAGE_BITS = DMG_BULLET | DMG_NEVERGIB
const Float:SPLAT_COOLDOWN = 2.0
new const CHIME_SOUND[] = "events/task_complete"
// The core's paintball entity: in flight, and after it has splatted.
new const BALL_CLASS[] = "pbBullet"
new const SPLAT_CLASS[] = "pbPaint"
enum _:Side
{
SIDE_T,
SIDE_CT
}
new const SIDE_TEAM[Side][] = { "TERRORIST", "CT" }
enum ReportState
{
REPORT_PENDING, // no round has ended on this map yet
REPORT_QUIET, // no sector reached olds_splat_minhits
REPORT_BUSY
}
// Sectors of the current map.
new g_sectorName[MAX_SECTORS][SECTOR_NAME_LEN]
new Float:g_sectorMin[MAX_SECTORS][3]
new Float:g_sectorMax[MAX_SECTORS][3]
new g_sectorCount
// Hits of the round in progress, per attacking side.
new g_hits[Side][MAX_SECTORS]
// The last finished round, per side.
new ReportState:g_report[Side]
new g_reportHits[Side]
new g_reportSectors[Side] // bit n set = sector n is among the busiest
// Per-frame bookkeeping, indexed [victim][attacker].
new Float:g_bulletTime[MAX_PLAYERS + 1][MAX_PLAYERS + 1]
new Float:g_hitTime[MAX_PLAYERS + 1][MAX_PLAYERS + 1]
new Float:g_healthBefore[MAX_PLAYERS + 1]
new bool:g_aliveBefore[MAX_PLAYERS + 1]
new Float:g_nextSplat[MAX_PLAYERS + 1]
new g_minHits
new HookChain:g_hooks[5]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_splat.txt")
bind_pcvar_num(create_cvar("olds_splat_minhits", "5", FCVAR_NONE,
"Sectors with fewer hits than this are not reported as busy (1-1000).",
true, 1.0, true, 1000.0), g_minHits)
AutoExecConfig(true, "olds_splat")
register_clcmd("say /splat", "cmd_splat")
register_clcmd("say_team /splat", "cmd_splat")
register_concmd("olds_splat_status", "cmd_status", ADMIN_CFG, "- this round's paint hits per field sector")
register_concmd("olds_splat_where", "cmd_where", ADMIN_CFG, "- your position and field sector, for writing sector files")
g_hooks[0] = RegisterHookChain(RG_CBasePlayer_TraceAttack, "on_trace_attack_post", true)
g_hooks[1] = RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_pre", false)
g_hooks[2] = RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_post", true)
g_hooks[3] = RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
g_hooks[4] = RegisterHookChain(RG_RoundEnd, "on_round_end_post", true)
set_hooks(false)
}
public plugin_cfg()
{
new version[32]
if (!find_core(version, charsmax(version)))
{
set_fail_state("The %s core is not running. Load it before this plugin.", CORE_NAME)
return
}
if (!equal(version, CORE_VERSION))
{
set_fail_state("%s %s is installed; this plugin is pinned to %s.", CORE_NAME, version, CORE_VERSION)
return
}
load_sectors()
set_hooks(g_sectorCount > 0)
}
set_hooks(bool:enable)
{
for (new i = 0; i < sizeof g_hooks; i++)
{
if (enable)
EnableHookChain(g_hooks[i])
else
DisableHookChain(g_hooks[i])
}
}
/* Finds the core by its registered name. Returns false unless it is running. */
bool:find_core(version[], versionLen)
{
new file[2], name[64], author[2], status[16]
new count = get_pluginsnum()
for (new i = 0; i < count; i++)
{
if (get_plugin(i, file, 0, name, charsmax(name), version, versionLen, author, 0, status, charsmax(status)) == -1)
continue
if (equal(name, CORE_NAME))
return equal(status, "running") || equal(status, "debug")
}
return false
}
/* ---------- sectors ---------- */
load_sectors()
{
new map[32], path[PLATFORM_MAX_PATH]
get_mapname(map, charsmax(map))
get_configsdir(path, charsmax(path))
format(path, charsmax(path), "%s/olds_splat/%s.ini", path, map)
new file = fopen(path, "rt")
if (!file)
{
log_amx("No sectors for %s (%s): hit tracking is off on this map.", map, path)
return
}
new line[256], name[SECTOR_NAME_LEN], coord[6][16], lineNumber
new Float:a[3], Float:b[3]
while (fgets(file, line, charsmax(line)))
{
lineNumber++
trim(line)
if (!line[0] || line[0] == ';' || line[0] == '#' || (line[0] == '/' && line[1] == '/'))
continue
if (g_sectorCount == MAX_SECTORS)
{
log_amx("%s: only the first %d sectors are used.", path, MAX_SECTORS)
break
}
new parts = parse(line, name, charsmax(name),
coord[0], charsmax(coord[]), coord[1], charsmax(coord[]), coord[2], charsmax(coord[]),
coord[3], charsmax(coord[]), coord[4], charsmax(coord[]), coord[5], charsmax(coord[]))
if (parts != 7 || !name[0])
{
log_amx("%s line %d: expected ^"Name^" x1 y1 z1 x2 y2 z2.", path, lineNumber)
continue
}
if (!read_float(coord[0], a[0]) || !read_float(coord[1], a[1]) || !read_float(coord[2], a[2])
|| !read_float(coord[3], b[0]) || !read_float(coord[4], b[1]) || !read_float(coord[5], b[2]))
{
log_amx("%s line %d: the six corner values must be numbers.", path, lineNumber)
continue
}
if (a[0] == b[0] || a[1] == b[1] || a[2] == b[2])
{
log_amx("%s line %d: sector ^"%s^" has no volume.", path, lineNumber, name)
continue
}
if (find_sector(name) != -1)
{
log_amx("%s line %d: sector ^"%s^" is already defined.", path, lineNumber, name)
continue
}
new s = g_sectorCount++
copy(g_sectorName[s], charsmax(g_sectorName[]), name)
for (new axis = 0; axis < 3; axis++)
{
g_sectorMin[s][axis] = floatmin(a[axis], b[axis])
g_sectorMax[s][axis] = floatmax(a[axis], b[axis])
}
}
fclose(file)
log_amx("%d sector(s) loaded for %s.", g_sectorCount, map)
}
bool:read_float(const text[], &Float:value)
{
new i, digits, dots
if (text[i] == '-' || text[i] == '+')
i++
for (; text[i]; i++)
{
if (isdigit(text[i]))
digits++
else if (text[i] == '.' && ++dots == 1)
continue
else
return false
}
if (!digits)
return false
value = str_to_float(text)
return true
}
find_sector(const name[])
{
for (new s = 0; s < g_sectorCount; s++)
{
if (equali(g_sectorName[s], name))
return s
}
return -1
}
/* Overlapping boxes: the first sector in the file wins. */
sector_at(const Float:origin[3])
{
for (new s = 0; s < g_sectorCount; s++)
{
if (origin[0] >= g_sectorMin[s][0] && origin[0] <= g_sectorMax[s][0]
&& origin[1] >= g_sectorMin[s][1] && origin[1] <= g_sectorMax[s][1]
&& origin[2] >= g_sectorMin[s][2] && origin[2] <= g_sectorMax[s][2])
return s
}
return -1
}
/* ---------- hits ---------- */
public on_trace_attack_post(victim, attacker, Float:damage, Float:direction[3], trace, bits)
{
if (is_player(victim) && is_player(attacker))
g_bulletTime[victim][attacker] = get_gametime()
return HC_CONTINUE
}
public on_take_damage_pre(victim, inflictor, attacker, Float:damage, bits)
{
if (is_player(victim))
{
g_aliveBefore[victim] = bool:is_user_alive(victim)
g_healthBefore[victim] = Float:get_entvar(victim, var_health)
}
return HC_CONTINUE
}
public on_take_damage_post(victim, inflictor, attacker, Float:damage, bits)
{
if (bits != PAINT_DAMAGE_BITS || victim == attacker)
return HC_CONTINUE
if (!is_player(victim) || !is_player(attacker) || !is_user_connected(victim) || !is_user_connected(attacker))
return HC_CONTINUE
if (!is_paint_inflictor(inflictor, attacker))
return HC_CONTINUE
if (!g_aliveBefore[victim])
return HC_CONTINUE
new Float:now = get_gametime()
if (g_bulletTime[victim][attacker] == now || g_hitTime[victim][attacker] == now)
return HC_CONTINUE
// Confirmed only if the hit landed: health dropped or the victim died.
if (is_user_alive(victim) && Float:get_entvar(victim, var_health) >= g_healthBefore[victim])
return HC_CONTINUE
new attackerSide = side_of(attacker)
new victimSide = side_of(victim)
if (attackerSide == -1 || victimSide == -1 || attackerSide == victimSide)
return HC_CONTINUE
new Float:origin[3]
get_entvar(victim, var_origin, origin)
new sector = sector_at(origin)
if (sector == -1)
return HC_CONTINUE
g_hitTime[victim][attacker] = now
g_hits[attackerSide][sector]++
return HC_CONTINUE
}
/* ---------- rounds ---------- */
public on_restart_round_pre()
{
for (new side = 0; side < Side; side++)
arrayset(g_hits[side], 0, sizeof g_hits[])
return HC_CONTINUE
}
public on_round_end_post(WinStatus:status, ScenarioEventEndRound:event, Float:delay)
{
if (!GetHookChainReturn(ATYPE_BOOL))
return HC_CONTINUE
// A restart or the first players joining is not a played round.
if (event == ROUND_GAME_COMMENCE || event == ROUND_GAME_RESTART)
return HC_CONTINUE
for (new side = 0; side < Side; side++)
{
build_report(side)
announce(side)
}
return HC_CONTINUE
}
build_report(side)
{
new best, sectors
for (new s = 0; s < g_sectorCount; s++)
{
if (g_hits[side][s] > best)
{
best = g_hits[side][s]
sectors = 1 << s
}
else if (best && g_hits[side][s] == best)
{
sectors |= 1 << s
}
}
g_reportHits[side] = best
g_reportSectors[side] = sectors
g_report[side] = (best && best >= g_minHits) ? REPORT_BUSY : REPORT_QUIET
}
announce(side)
{
new players[MAX_PLAYERS], count
get_players(players, count, "ceh", SIDE_TEAM[side])
for (new i = 0; i < count; i++)
show_report(players[i], side, true)
}
show_report(id, side, bool:onScreen)
{
new text[REPORT_LEN]
format_report(id, side, text, charsmax(text))
client_print_color(id, print_team_default, "^4[Splat]^1 %s", text)
if (onScreen)
{
// show_dhudmessage cuts text at 128 characters, so the screen gets the short form.
format_report(id, side, text, charsmax(text), true)
set_dhudmessage(255, 170, 40, -1.0, 0.25, 0, 0.0, 6.0, 0.2, 0.6)
show_dhudmessage(id, "%s", text)
client_cmd(id, "spk %s", CHIME_SOUND)
}
}
/* lang is a player index or LANG_SERVER; brief picks the short on-screen wording. */
format_report(lang, side, text[], len, bool:brief = false)
{
switch (g_report[side])
{
case REPORT_PENDING:
formatex(text, len, "%L", lang, "SPLAT_NO_REPORT")
case REPORT_QUIET:
formatex(text, len, "%L", lang, brief ? "SPLAT_HUD_QUIET" : "SPLAT_QUIET", g_minHits)
case REPORT_BUSY:
{
new names[REPORT_LEN / 2], tied
for (new s = 0; s < g_sectorCount; s++)
{
if (!(g_reportSectors[side] & (1 << s)))
continue
if (tied++)
add(names, charsmax(names), ", ")
add(names, charsmax(names), g_sectorName[s])
}
if (brief)
formatex(text, len, "%L", lang, "SPLAT_HUD_BUSY", names, g_reportHits[side])
else
formatex(text, len, "%L", lang, tied > 1 ? "SPLAT_BUSY_TIE" : "SPLAT_BUSY_ONE", names, g_reportHits[side])
}
}
}
/* ---------- commands ---------- */
public cmd_splat(id)
{
if (!is_user_connected(id))
return PLUGIN_HANDLED
new Float:now = get_gametime()
if (now < g_nextSplat[id])
return PLUGIN_HANDLED
g_nextSplat[id] = now + SPLAT_COOLDOWN
if (!g_sectorCount)
{
client_print_color(id, print_team_default, "^4[Splat]^1 %L", id, "SPLAT_NO_SECTORS")
return PLUGIN_HANDLED
}
new side = side_of(id)
if (side == -1)
{
client_print_color(id, print_team_default, "^4[Splat]^1 %L", id, "SPLAT_NO_TEAM")
return PLUGIN_HANDLED
}
show_report(id, side, false)
return PLUGIN_HANDLED
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[Splat] %d sector(s), minimum %d hit(s)", g_sectorCount, g_minHits)
for (new s = 0; s < g_sectorCount; s++)
console_print(id, "[Splat] %-24s T %4d CT %4d", g_sectorName[s], g_hits[SIDE_T][s], g_hits[SIDE_CT][s])
new text[REPORT_LEN]
for (new side = 0; side < Side; side++)
{
format_report(id ? id : LANG_SERVER, side, text, charsmax(text))
console_print(id, "[Splat] last %s report: %s", SIDE_TEAM[side], text)
}
return PLUGIN_HANDLED
}
public cmd_where(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
if (!id || !is_user_alive(id))
{
console_print(id, "[Splat] Only a living player has a position.")
return PLUGIN_HANDLED
}
new Float:origin[3]
get_entvar(id, var_origin, origin)
new sector = sector_at(origin)
if (sector == -1)
console_print(id, "[Splat] %.0f %.0f %.0f (no sector)", origin[0], origin[1], origin[2])
else
console_print(id, "[Splat] %.0f %.0f %.0f in ^"%s^"", origin[0], origin[1], origin[2], g_sectorName[sector])
return PLUGIN_HANDLED
}
/* ---------- players ---------- */
public client_disconnected(id)
{
g_nextSplat[id] = 0.0
g_aliveBefore[id] = false
for (new other = 1; other <= MaxClients; other++)
{
g_bulletTime[id][other] = g_bulletTime[other][id] = 0.0
g_hitTime[id][other] = g_hitTime[other][id] = 0.0
}
}
/* The shooter (what Paintball Gun 1.1 passes) or the shooter's own paintball entity. */
bool:is_paint_inflictor(inflictor, attacker)
{
if (inflictor == attacker)
return true
if (is_player(inflictor) || is_nullent(inflictor) || get_entvar(inflictor, var_owner) != attacker)
return false
new classname[16]
get_entvar(inflictor, var_classname, classname, charsmax(classname))
return equal(classname, BALL_CLASS) || equal(classname, SPLAT_CLASS)
}
bool:is_player(id)
{
return 1 <= id <= MaxClients
}
side_of(id)
{
switch (TeamName:get_member(id, m_iTeam))
{
case TEAM_TERRORIST: return SIDE_T
case TEAM_CT: return SIDE_CT
}
return -1
}