Daemon666 / CSB Session Stats Herkese açık

In-memory session summary: kills, deaths, headshots, damage, rounds won, best streak and time played.

v1.0.0 148 indirme GPL-3.0 Son güncelleme Aug 24, 2026
csb_session_stats.sma v1.0.0 191 satır · 4.8 KB Ham
1 /*
2 * CSB Session Stats
3 * Copyright (C) 2026 counter-strike-boost.com
4 *
5 * Keeps a per-slot, in-memory summary of the current session: kills, deaths,
6 * headshots, damage dealt, rounds won, time played and best killstreak. Shows
7 * it on say /session, on disconnect (to the AMXX log) and a short line at round
8 * end. Nothing is persisted - it resets when the player leaves.
9 *
10 * This program is free software: you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License as published by the Free Software
12 * Foundation, either version 3 of the License, or (at your option) any later
13 * version. It is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See <https://www.gnu.org/licenses/> for details.
16 */
17
18 #include <amxmodx>
19 #include <amxmisc>
20 #include <hamsandwich>
21
22 new const PLUGIN[] = "CSB Session Stats"
23 new const VERSION[] = "1.0.0"
24 new const AUTHOR[] = "counter-strike-boost.com"
25
26 new g_iKills[33]
27 new g_iDeaths[33]
28 new g_iHs[33]
29 new g_iDamage[33]
30 new g_iRoundsWon[33]
31 new g_iStreak[33]
32 new g_iBestStreak[33]
33 new g_iJoinTime[33]
34
35 new g_pEnabled, g_pRoundLine
36
37 public plugin_init()
38 {
39 register_plugin(PLUGIN, VERSION, AUTHOR)
40
41 g_pEnabled = register_cvar("csb_session_enabled", "1")
42 g_pRoundLine = register_cvar("csb_session_roundline", "1")
43
44 register_event("DeathMsg", "eventDeath", "a", "1>0")
45 register_event("SendAudio", "eventWin", "a")
46 register_logevent("eventRoundEnd", 2, "1=Round_End")
47
48 RegisterHam(Ham_TakeDamage, "player", "hamTakeDamage")
49
50 register_clcmd("say /session", "cmdSession")
51 register_clcmd("say_team /session", "cmdSession")
52 }
53
54 public client_putinserver(id)
55 {
56 resetPlayer(id)
57 g_iJoinTime[id] = get_systime()
58 }
59
60 public client_disconnected(id)
61 {
62 if (g_iKills[id] || g_iDeaths[id])
63 {
64 new name[32]
65 get_user_name(id, name, charsmax(name))
66 log_amx("[CSB Session] %s left - %d kills, %d deaths, %d hs, %d dmg, best streak %d",
67 name, g_iKills[id], g_iDeaths[id], g_iHs[id], g_iDamage[id], g_iBestStreak[id])
68 }
69
70 resetPlayer(id)
71 }
72
73 resetPlayer(id)
74 {
75 g_iKills[id] = 0
76 g_iDeaths[id] = 0
77 g_iHs[id] = 0
78 g_iDamage[id] = 0
79 g_iRoundsWon[id] = 0
80 g_iStreak[id] = 0
81 g_iBestStreak[id] = 0
82 g_iJoinTime[id] = get_systime()
83 }
84
85 public hamTakeDamage(victim, inflictor, attacker, Float:damage, damagebits)
86 {
87 if (attacker < 1 || attacker > 32 || attacker == victim)
88 return HAM_IGNORED
89
90 g_iDamage[attacker] += floatround(damage)
91 return HAM_IGNORED
92 }
93
94 public eventDeath()
95 {
96 new killer = read_data(1)
97 new victim = read_data(2)
98 new hs = read_data(3)
99
100 if (victim >= 1 && victim <= 32)
101 {
102 g_iDeaths[victim]++
103 g_iStreak[victim] = 0
104 }
105
106 if (killer >= 1 && killer <= 32 && killer != victim)
107 {
108 g_iKills[killer]++
109 g_iStreak[killer]++
110
111 if (g_iStreak[killer] > g_iBestStreak[killer])
112 g_iBestStreak[killer] = g_iStreak[killer]
113
114 if (hs)
115 g_iHs[killer]++
116 }
117 }
118
119 public eventWin()
120 {
121 new audio[48]
122 read_data(2, audio, charsmax(audio))
123
124 new winTeam = 0
125
126 if (containi(audio, "terwin") != -1)
127 winTeam = 1
128 else if (containi(audio, "ctwin") != -1)
129 winTeam = 2
130
131 if (!winTeam)
132 return
133
134 new players[32], num, pid
135 get_players(players, num, "ae")
136
137 for (new i = 0; i < num; i++)
138 {
139 pid = players[i]
140
141 if (get_user_team(pid) == winTeam)
142 g_iRoundsWon[pid]++
143 }
144 }
145
146 public eventRoundEnd()
147 {
148 if (!get_pcvar_num(g_pRoundLine))
149 return
150
151 new players[32], num, pid
152 get_players(players, num, "c")
153
154 for (new i = 0; i < num; i++)
155 {
156 pid = players[i]
157
158 if (g_iKills[pid] || g_iDeaths[pid])
159 printSummary(pid, pid, true)
160 }
161 }
162
163 public cmdSession(id)
164 {
165 if (!get_pcvar_num(g_pEnabled))
166 return PLUGIN_HANDLED
167
168 printSummary(id, id, false)
169 return PLUGIN_HANDLED
170 }
171
172 printSummary(id, target, bool:shortLine)
173 {
174 new mins = (get_systime() - g_iJoinTime[target]) / 60
175
176 if (shortLine)
177 {
178 client_print(id, print_chat, "[CSB] Session: %d-%d, %d hs, best streak %d.",
179 g_iKills[target], g_iDeaths[target], g_iHs[target], g_iBestStreak[target])
180 return
181 }
182
183 new Float:kdr = g_iDeaths[target] ? float(g_iKills[target]) / float(g_iDeaths[target]) : float(g_iKills[target])
184
185 client_print(id, print_chat, "[CSB] --- Your session so far ---")
186 client_print(id, print_chat, "[CSB] Kills: %d | Deaths: %d | K/D: %.2f | Headshots: %d",
187 g_iKills[target], g_iDeaths[target], kdr, g_iHs[target])
188 client_print(id, print_chat, "[CSB] Damage: %d | Rounds won: %d | Best streak: %d | Time: %d min",
189 g_iDamage[target], g_iRoundsWon[target], g_iBestStreak[target], mins)
190 }
191