/*
* Clean Sheet (olds.ro workshop card AMX-038)
*
* Paintball: counts the rounds in a row each player survives without a
* confirmed hit from an enemy. /cleansheet shows your streak; from
* olds_clean_minstreak rounds on, a DHUD line shows it at round end.
*
* say /cleansheet your current streak and your best on this map
*
* A confirmed hit: the Paintball mods hurt players through the game's own
* damage, so the plugin reads RG_CBasePlayer_TakeDamage (health before and
* after) and counts a hit only when an enemy player caused it and the
* victim's health actually went down. Paint splats, decals, friendly fire and repeated callbacks for
* the same shot change nothing (a round is either clean or not).
*
* A round counts when the player was alive at its start (round restart),
* is still alive at its end, stayed on the same team and was never hit.
* Dying, being hit, or switching team sets the streak to 0 at round end;
* leaving clears it. A player who joins mid-round is not counted for that
* round (and keeps their streak at 0 until a full round). Streaks live in
* memory only and start over at every map.
*
* Cvar: olds_clean_minstreak 2 (1-50). Command: olds_clean_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 "Clean Sheet"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
const TASK_WATCH = 3811
new g_streak[MAX_PLAYERS + 1]
new g_best[MAX_PLAYERS + 1]
new bool:g_started[MAX_PLAYERS + 1] // alive at the round's start
new TeamName:g_team[MAX_PLAYERS + 1] // team at the round's start
new bool:g_hit[MAX_PLAYERS + 1]
new Float:g_healthBefore[MAX_PLAYERS + 1]
new Float:g_nextUse[MAX_PLAYERS + 1]
new bool:g_roundLive
new g_minStreak
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_cleansheet.txt")
bind_pcvar_num(create_cvar("olds_clean_minstreak", "2", FCVAR_NONE,
"Streak from which the round-end DHUD line is shown (1-50).", true, 1.0, true, 50.0), g_minStreak)
AutoExecConfig(true, "olds_cleansheet")
register_clcmd("say /cleansheet", "cmd_cleansheet")
register_clcmd("say_team /cleansheet", "cmd_cleansheet")
register_concmd("olds_clean_status", "cmd_status", ADMIN_CFG, "- every player's clean-sheet streak")
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_post", true)
RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_pre", false)
RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_post", true)
RegisterHookChain(RG_RoundEnd, "on_round_end_post", true)
set_task(1.0, "task_watch_round_end", TASK_WATCH, _, _, "b")
}
/* ---------- the round ---------- */
/* Players alive right after the restart are the round's participants. */
public on_restart_round_post()
{
for (new id = 1; id <= MaxClients; id++)
{
g_hit[id] = false
g_started[id] = is_user_alive(id) && !is_user_hltv(id)
g_team[id] = g_started[id] ? (TeamName:get_member(id, m_iTeam)) : TEAM_UNASSIGNED
}
g_roundLive = true
return HC_CONTINUE
}
public on_take_damage_pre(victim, inflictor, attacker, Float:damage, damageBits)
{
if (1 <= victim <= MaxClients)
g_healthBefore[victim] = Float:get_entvar(victim, var_health)
return HC_CONTINUE
}
public on_take_damage_post(victim, inflictor, attacker, Float:damage, damageBits)
{
if (!g_roundLive || !(1 <= victim <= MaxClients) || !(1 <= attacker <= MaxClients) || victim == attacker)
return HC_CONTINUE
if (!is_user_connected(attacker) || !is_user_connected(victim))
return HC_CONTINUE
if (TeamName:get_member(attacker, m_iTeam) == TeamName:get_member(victim, m_iTeam))
return HC_CONTINUE
// Confirmed: the game really took health off (not blocked, not zero damage).
if (Float:get_entvar(victim, var_health) < g_healthBefore[victim])
g_hit[victim] = true
return HC_CONTINUE
}
public on_round_end_post(WinStatus:status, ScenarioEventEndRound:event, Float:delay)
{
if (event != ROUND_GAME_COMMENCE && event != ROUND_GAME_RESTART && get_member_game(m_bRoundTerminating))
settle_round()
return HC_CONTINUE
}
/* A round closed by rg_round_end() from another plugin skips RG_RoundEnd. */
public task_watch_round_end()
{
if (g_roundLive && get_member_game(m_bRoundTerminating))
settle_round()
}
settle_round()
{
if (!g_roundLive)
return
g_roundLive = false
for (new id = 1; id <= MaxClients; id++)
{
if (!is_user_connected(id))
continue
if (!g_started[id])
continue // joined mid-round: this round does not count
new bool:clean = !g_hit[id] && is_user_alive(id) && TeamName:get_member(id, m_iTeam) == g_team[id]
g_streak[id] = clean ? g_streak[id] + 1 : 0
if (g_streak[id] > g_best[id])
g_best[id] = g_streak[id]
if (clean && g_streak[id] >= g_minStreak && !is_user_bot(id))
{
set_dhudmessage(110, 220, 255, -1.0, 0.20, 0, 0.0, 4.0, 0.2, 0.6)
show_dhudmessage(id, "%L", id, "CLEAN_HUD", g_streak[id])
}
g_started[id] = false
}
}
/* ---------- /cleansheet ---------- */
public cmd_cleansheet(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
client_print_color(id, print_team_default, "^4[Clean Sheet]^1 %L", id, "CLEAN_STREAK", g_streak[id], g_best[id])
if (g_roundLive && g_started[id] && g_hit[id])
client_print_color(id, print_team_default, "^4[Clean Sheet]^1 %L", id, "CLEAN_HIT_THIS_ROUND")
return PLUGIN_HANDLED
}
public client_putinserver(id)
{
clear(id)
}
public client_disconnected(id)
{
clear(id)
}
clear(id)
{
g_streak[id] = 0
g_best[id] = 0
g_started[id] = false
g_hit[id] = false
g_team[id] = TEAM_UNASSIGNED
g_nextUse[id] = 0.0
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[Clean Sheet] round %s; HUD from %d", g_roundLive ? "live" : "over", g_minStreak)
new players[MAX_PLAYERS], count, name[MAX_NAME_LENGTH]
get_players(players, count, "h")
for (new i = 0; i < count; i++)
{
new p = players[i]
get_user_name(p, name, charsmax(name))
console_print(id, "[Clean Sheet] %s: streak %d, best %d%s%s", name, g_streak[p], g_best[p],
g_started[p] ? "" : ", not counted this round", g_hit[p] ? ", hit" : "")
}
return PLUGIN_HANDLED
}