-
Notifications
You must be signed in to change notification settings - Fork 0
/
hns_stats.sma
217 lines (175 loc) · 5.78 KB
/
hns_stats.sma
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#include <amxmodx>
#include <reapi>
#include <xs>
#include <hns_mode_main>
forward hns_ownage(iToucher, iTouched);
#define TASK_TIMER 54345
enum _: PLAYER_STATS {
PLR_STATS_KILLS,
PLR_STATS_DEATHS,
PLR_STATS_ASSISTS,
PLR_STATS_STABS,
PLR_STATS_DMG_CT,
PLR_STATS_DMG_TT,
Float:PLR_STATS_AVG_SPEED,
Float:PLR_STATS_RUNNED,
Float:PLR_STATS_RUNTIME,
Float:PLR_STATS_FLASHTIME,
Float:PLR_STATS_SURVTIME,
PLR_STATS_OWNAGES,
}
new g_StatsRound[MAX_PLAYERS + 1][PLAYER_STATS];
new iLastAttacker[MAX_PLAYERS + 1];
new Float:last_position[MAX_PLAYERS+ 1][3];
public plugin_init() {
register_plugin("HNS: Stats", "1.0", "OpenHNS"); // Garey
RegisterHookChain(RG_CBasePlayer_Killed, "rgPlayerKilled", true);
RegisterHookChain(RG_CBasePlayer_TakeDamage, "rgPlayerTakeDamage", false);
RegisterHookChain(RG_CBasePlayer_PreThink, "rgPlayerPreThink", true);
RegisterHookChain(RG_CSGameRules_FlPlayerFallDamage, "rgPlayerFallDamage", true);
RegisterHookChain(RG_CSGameRules_OnRoundFreezeEnd, "rgRoundFreezeEnd", true);
RegisterHookChain(RG_CSGameRules_RestartRound, "rgRestartRound", true);
}
public plugin_natives() {
register_native("hns_get_stats_kills", "native_get_stats_kills");
register_native("hns_get_stats_deaths", "native_get_stats_deaths");
register_native("hns_get_stats_assists", "native_get_stats_assists");
register_native("hns_get_stats_stabs", "native_get_stats_stabs");
register_native("hns_get_stats_dmgct", "native_get_stats_dmgct");
register_native("hns_get_stats_dmgtt", "native_get_stats_dmgtt");
register_native("hns_get_stats_run", "native_get_stats_run");
register_native("hns_get_stats_flashtime", "native_get_stats_flashtime");
register_native("hns_get_stats_surv", "native_get_stats_surv");
register_native("hns_get_stats_ownages", "native_get_stats_ownages");
}
public native_get_stats_kills(amxx, params) {
enum { id = 1 };
return g_StatsRound[get_param(id)][PLR_STATS_KILLS];
}
public native_get_stats_deaths(amxx, params) {
enum { id = 1 };
return g_StatsRound[get_param(id)][PLR_STATS_DEATHS];
}
public native_get_stats_assists(amxx, params) {
enum { id = 1 };
return g_StatsRound[get_param(id)][PLR_STATS_ASSISTS];
}
public native_get_stats_stabs(amxx, params) {
enum { id = 1 };
return g_StatsRound[get_param(id)][PLR_STATS_STABS];
}
public native_get_stats_dmgct(amxx, params) {
enum { id = 1 };
return g_StatsRound[get_param(id)][PLR_STATS_DMG_CT];
}
public native_get_stats_dmgtt(amxx, params) {
enum { id = 1 };
return g_StatsRound[get_param(id)][PLR_STATS_DMG_TT];
}
public Float:native_get_stats_run(amxx, params) {
enum { id = 1 };
return g_StatsRound[get_param(id)][PLR_STATS_RUNNED];
}
public Float:native_get_stats_flashtime(amxx, params) {
enum { id = 1 };
return g_StatsRound[get_param(id)][PLR_STATS_FLASHTIME];
}
public Float:native_get_stats_surv(amxx, params) {
enum { id = 1 };
return g_StatsRound[get_param(id)][PLR_STATS_SURVTIME];
}
public native_get_stats_ownages(amxx, params) {
enum { id = 1 };
return g_StatsRound[get_param(id)][PLR_STATS_OWNAGES];
}
public hns_ownage(iToucher, iTouched) {
g_StatsRound[iToucher][PLR_STATS_OWNAGES]++;
}
public rgPlayerKilled(victim, attacker) {
if (is_user_connected(attacker) && victim != attacker) {
g_StatsRound[attacker][PLR_STATS_KILLS]++;
}
if (iLastAttacker[victim] && iLastAttacker[victim] != attacker) {
g_StatsRound[iLastAttacker[victim]][PLR_STATS_ASSISTS]++;
iLastAttacker[victim] = 0;
}
}
public rgPlayerTakeDamage(iVictim, iWeapon, iAttacker, Float:fDamage) {
if (is_user_alive(iAttacker) && iVictim != iAttacker) {
new Float:fHealth; get_entvar(iVictim, var_health, fHealth);
if (fDamage < fHealth) {
iLastAttacker[iVictim] = iAttacker;
}
g_StatsRound[iAttacker][PLR_STATS_STABS]++;
}
}
public rgPlayerFallDamage(id) {
new dmg = floatround(Float:GetHookChainReturn(ATYPE_FLOAT));
if (rg_get_user_team(id) == TEAM_TERRORIST) {
g_StatsRound[id][PLR_STATS_DMG_TT] += dmg;
} else {
g_StatsRound[id][PLR_STATS_DMG_CT] += dmg;
}
}
public PlayerBlind(const index, const inflictor, const attacker, const Float:fadeTime, const Float:fadeHold, const alpha) {
g_StatsRound[attacker][PLR_STATS_FLASHTIME] += fadeHold;
}
public rgPlayerPreThink(id) {
static Float:origin[3];
static Float:velocity[3];
static Float:last_updated[MAX_PLAYERS + 1];
static Float:frametime;
get_entvar(id, var_origin, origin);
get_entvar(id, var_velocity, velocity);
frametime = get_gametime() - last_updated[id];
if (frametime > 1.0) {
frametime = 1.0;
}
if (is_user_alive(id)) {
if (rg_get_user_team(id) == TEAM_TERRORIST) {
if (vector_length(velocity) * frametime >= get_distance_f(origin, last_position[id])) {
velocity[2] = 0.0;
if (vector_length(velocity) > 125.0) {
g_StatsRound[id][PLR_STATS_RUNNED] += vector_length(velocity) * frametime;
g_StatsRound[id][PLR_STATS_RUNTIME] += frametime;
if (g_StatsRound[id][PLR_STATS_RUNTIME]) {
g_StatsRound[id][PLR_STATS_AVG_SPEED] = g_StatsRound[id][PLR_STATS_RUNNED] / g_StatsRound[id][PLR_STATS_RUNTIME];
}
}
}
}
}
last_updated[id] = get_gametime();
xs_vec_copy(origin, last_position[id]);
}
public rgRoundFreezeEnd() {
set_task(0.25, "taskRoundEvent", .id = TASK_TIMER, .flags = "b");
}
public rgRestartRound() {
remove_task(TASK_TIMER);
}
public taskRoundEvent() {
new iPlayers[MAX_PLAYERS], iNum;
get_players(iPlayers, iNum, "ech", "TERRORIST");
for (new i = 0; i < iNum; i++)
{
new id = iPlayers[i];
if (is_user_alive(id))
{
g_StatsRound[id][PLR_STATS_SURVTIME] += 0.25;
}
}
}
public hns_round_end() {
remove_task(TASK_TIMER);
}
public hns_round_start() {
new iPlayers[MAX_PLAYERS], iNum;
get_players(iPlayers, iNum, "ch");
for (new i = 0; i < iNum; i++) {
new id = iPlayers[i];
arrayset(g_StatsRound[id], 0, PLAYER_STATS);
arrayset(last_position[id], 0, 3);
iLastAttacker[id] = 0;
}
}