Sunucu tanitimi
csb-round-summary / addons / amxmodx / scripting / csb_round_summary.sma
151 lines 3.8 KiB Pawn Raw Permalink History
/*
 * CSB Round Summary
 * Copyright (C) 2026 counter-strike-boost.com
 *
 * At the end of each round it prints a short summary in a HUD sync channel and in
 * chat: which team won, the running score, the round MVP (most kills this round),
 * the top damage dealer and how many players survived. Per-round kills and damage
 * are tracked live (DeathMsg for kills, Ham_TakeDamage for damage) and reset when
 * the next round starts.
 *
 * 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. It 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 <https://www.gnu.org/licenses/> for details.
 */

#include <amxmodx>
#include <hamsandwich>

new const PLUGIN[] = "CSB Round Summary"
new const VERSION[] = "1.0.0"
new const AUTHOR[]  = "counter-strike-boost.com"

new g_iKills[33]
new Float:g_fDamage[33]
new g_iScoreT, g_iScoreCT
new g_iSync
new g_pEnabled

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)

    g_pEnabled = register_cvar("csb_summary_enabled", "1")

    g_iSync = CreateHudSyncObj()

    RegisterHam(Ham_TakeDamage, "player", "hamTakeDamage", 0)

    register_event("DeathMsg", "eventDeath", "a", "1>0")
    register_logevent("eventRoundStart", 2, "1=Round_Start")

    register_event("TextMsg", "eventTerWin", "a", "2&#Terrorists_Win")
    register_event("TextMsg", "eventCtWin",  "a", "2&#CTs_Win")
    register_event("TextMsg", "eventDraw",   "a", "2&#Round_Draw")
}

public hamTakeDamage(victim, inflictor, attacker, Float:damage, damagebits)
{
    if (attacker < 1 || attacker > 32 || attacker == victim)
        return HAM_IGNORED

    if (damage > 0.0)
        g_fDamage[attacker] += damage

    return HAM_IGNORED
}

public eventDeath()
{
    new killer = read_data(1)

    if (killer >= 1 && killer <= 32)
        g_iKills[killer]++
}

public eventRoundStart()
{
    for (new i = 1; i <= 32; i++)
    {
        g_iKills[i]   = 0
        g_fDamage[i]  = 0.0
    }
}

public eventTerWin()
{
    g_iScoreT++
    showSummary("Terrorists")
}

public eventCtWin()
{
    g_iScoreCT++
    showSummary("Counter-Terrorists")
}

public eventDraw()
{
    showSummary("Nobody (draw)")
}

showSummary(const winner[])
{
    if (!get_pcvar_num(g_pEnabled))
        return

    new mvp = 0, mvpKills = 0
    new dmgTop = 0
    new Float:dmgTopVal = 0.0
    new alive = 0

    new players[32], num
    get_players(players, num, "ch")

    for (new i = 0; i < num; i++)
    {
        new pl = players[i]

        if (g_iKills[pl] > mvpKills)
        {
            mvpKills = g_iKills[pl]
            mvp = pl
        }

        if (g_fDamage[pl] > dmgTopVal)
        {
            dmgTopVal = g_fDamage[pl]
            dmgTop = pl
        }

        if (is_user_alive(pl))
            alive++
    }

    new mvpName[32], dmgName[32]

    if (mvp)
        get_user_name(mvp, mvpName, charsmax(mvpName))
    else
        copy(mvpName, charsmax(mvpName), "-")

    if (dmgTop)
        get_user_name(dmgTop, dmgName, charsmax(dmgName))
    else
        copy(dmgName, charsmax(dmgName), "-")

    set_hudmessage(0, 220, 120, -1.0, 0.24, 0, 0.0, 5.0, 0.2, 0.4, -1)
    ShowSyncHudMsg(0, g_iSync,
        "%s win!  T %d - %d CT^nMVP: %s (%d kills)^nTop damage: %s (%d)^nSurvivors: %d",
        winner, g_iScoreT, g_iScoreCT,
        mvpName, mvpKills,
        dmgName, floatround(dmgTopVal),
        alive)

    client_print(0, print_chat,
        "[CSB] %s win  |  Score T %d - %d CT  |  MVP: %s (%d)  |  Top dmg: %s (%d)",
        winner, g_iScoreT, g_iScoreCT, mvpName, mvpKills, dmgName, floatround(dmgTopVal))
}