-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathefrag_ranking_core.sp
More file actions
321 lines (271 loc) · 9.6 KB
/
efrag_ranking_core.sp
File metadata and controls
321 lines (271 loc) · 9.6 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#include <sourcemod>
#include <cstrike>
#include <sdktools>
#include <sdkhooks>
#include <clientprefs>
#include <geoip>
#include <eranks>
int MIN_PLAYERS_FOR_RANKING_TO_WORK = 4;
int g_iOffset = -1;
public Plugin myinfo = {
name = "EFRAG [Ranking]",
author = "zwolof",
description = "Full ranking system for eFrag.eu",
version = "1.0",
url = "www.efrag-community.com"
};
public void OnPluginStart()
{
// HUD Text
if(isValidRef(g_iHnsClientHud))
AcceptEntityInput(g_iHnsClientHud, "Kill");
// Connect to database
Database.Connect(SQL_ConnectCallback, SQL_CONNECTION);
// Commands
RegConsoleCmd("sm_rank", Command_eRank);
//RegConsoleCmd("sm_etest", Command_eTest);
RegConsoleCmd("sm_top", Command_eTop);
RegConsoleCmd("sm_ranks", Command_eRanks);
RegConsoleCmd("sm_rs", Command_eResetScore);
RegConsoleCmd("sm_resetscore", Command_eResetScore);
RegConsoleCmd("sm_formatquery", Command_eTestQuery);
//RegConsoleCmd("sm_testranking", Command_eTestRanking);
//RegConsoleCmd("sm_connect", Command_eConnect);
// Events
HookEvent("player_disconnect", Event_OnPlayerDisconnect_Pre, EventHookMode_Pre);
HookEvent("player_death", Event_OnPlayerDeath, EventHookMode_Pre);
HookEvent("round_end", Event_OnRoundEnd, EventHookMode_Post);
g_iOffset = FindSendPropInfo("CCSPlayerResource", "m_iCompetitiveRanking");
// ConVar hHostname = FindConVar("hostname");
// char sHost[128];
// hHostname.GetString(sHost, sizeof(sHost));
// if(StrContains(sHost, "retake", false) != -1) {
// FormatEx(SERVER, sizeof(SERVER), "retakes");
// }
// else if(StrContains(sHost, "competi", false) != -1) {
// FormatEx(SERVER, sizeof(SERVER), "competitive");
// }
// else if(StrContains(sHost, "hns", false) != -1) {
// FormatEx(SERVER, sizeof(SERVER), "hnspre");
// FormatEx(SERVER, sizeof(SERVER), "hnspre");
// }
FormatEx(SERVER, sizeof(SERVER), "awpwars");
}
public void OnMapStart() {
SDKHook(GetPlayerResourceEntity(), SDKHook_ThinkPost, OnThinkPost);
}
public void OnPluginEnd() {
if(isValidRef(g_iHnsClientHud)) {
AcceptEntityInput(g_iHnsClientHud, "Kill");
}
}
public Action Command_eResetScore(int client, int iArgs)
{
if(IsValidClient(client))
{
SetEntProp(client, Prop_Data, "m_iFrags", 0);
SetEntProp(client, Prop_Data, "m_iDeaths", 0);
CS_SetMVPCount(client, 0);
CS_SetClientAssists(client, 0);
CS_SetClientContributionScore(client, 0);
PrintToChat(client, "%s Your score has been reset!", PREFIX);
}
return Plugin_Handled;
}
public Action Command_eTestQuery(int client, int iArgs)
{
char szQuery[512];
FormatUpdateQuery(client, szQuery, sizeof(szQuery));
PrintToConsoleAll(szQuery);
return Plugin_Handled;
}
public Action Command_eRanks(int client, int iArgs)
{
if(iArgs > 1) return Plugin_Handled;
if(IsValidClient(client))
{
CreateRanksMenu(client, 0);
}
return Plugin_Handled;
}
public Action Event_OnPlayerDisconnect_Pre(Handle hEvent, const char[] szName, bool bDontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(hEvent, "userid"));
// Is the leaving client valid? Update their stats
if(IsValidClient(client))
{
if(g_Session[client].stats[Stats_Points] < 0) {
g_Session[client].stats[Stats_Points] *= -1
}
SQL_UpdateStats(client);
}
return Plugin_Continue;
}
public Action Event_OnRoundEnd(Handle hEvent, const char[] szName, bool bDontBroadcast)
{
int iWinner = GetEventInt(hEvent, "winner");
// Is it a valid roundend? Did CT or T win?
if(__GetTotalPlayers() >= MIN_PLAYERS_FOR_RANKING_TO_WORK)
{
// Loop all clients
for(int i = 1; i <= MaxClients; i++)
{
if((0 < i <= MaxClients) && IsClientInGame(i) && !IsFakeClient(i))
{
// Is the client valid and are they in the winners team?
if(GetClientTeam(i) == iWinner)
{
// Increment points by 5 for round win!
PrintToChat(i, "%s \x08You got \x10+3 points\x08 for winning the round!", PREFIX);
g_Session[i].AddPoints(3);
// Increment round wins
g_Session[i].stats[Stats_Roundswon]++;
}
else {
if(GetClientTeam(i) != CS_TEAM_SPECTATOR) {
PrintToChat(i, "%s \x08You lost \x102 points\x08 for losing the round!", PREFIX);
g_Session[i].RemovePoints(2);
}
}
// if(GetClientTeam(i) == CS_TEAM_CT || GetClientTeam(i) == CS_TEAM_T) {
//PrintToChat(i, "%s \x08You have \x10%d\x08 points! [\x10%d\x08 kills | \x10%d\x08 deaths]",
//PREFIX, g_Rank[i].stats[Stats_Points], g_Rank[i].stats[Stats_Kills], g_Rank[i].stats[Stats_Deaths]);
//PrintToChat(i, "%s \x08Current rank: \x10%s\x08", PREFIX, g_sRanks[g_Rank[i].stats[Stats_Rank]][0]);
//}
//g_iLastPoints[i] = g_Session[i].iPoints;
}
}
}
return Plugin_Continue;
}
public Action Event_OnPlayerDeath(Handle hEvent, const char[] szName, bool bDontBroadcast)
{
// Initialize variables
int ATTACKER = GetClientOfUserId(GetEventInt(hEvent, "attacker"));
int VICTIM = GetClientOfUserId(GetEventInt(hEvent, "userid"));
int ASSISTER = GetClientOfUserId(GetEventInt(hEvent, "assister"));
//int iWeapon = GetEntPropEnt(ATTACKER, Prop_Data, "m_hActiveWeapon");
// Is it a headshot?
bool bHeadshot = GetEventBool(hEvent, "headshot");
// Get The weapon name
char sWeapon[16];
GetEventString(hEvent, "weapon", sWeapon, sizeof(sWeapon));
// Get points before doing anything
int points = g_Session[ATTACKER].stats[Stats_Points];
if(__GetTotalPlayers() >= MIN_PLAYERS_FOR_RANKING_TO_WORK) {
if(IsValidClient(VICTIM) && IsValidClient(ATTACKER)) {
char sWeapon[32];
GetClientWeapon(ATTACKER, sWeapon, sizeof(sWeapon));
// Make sure attacker != victim, so they dont kill themselves
if(ATTACKER != VICTIM) {
g_Session[ATTACKER].stats[Stats_Kills]++;
g_Session[VICTIM].stats[Stats_Deaths]++;
/////////////////////////////////////////////////////////
// Increment Headshots
if(bHeadshot) g_Session[ATTACKER].stats[Stats_Headshot]++;
// Is the assister valid?
if(ASSISTER && IsValidClient(ASSISTER))
{
// Increment Assists
//g_Rank[ATTACKER].iAssists++;
g_Session[ASSISTER].stats[Stats_Assists]++;
// Give assister points
g_Session[ASSISTER].AddPoints(1);
PrintToChat(ASSISTER, "%s \x08You got \x10+1 point\x08 for \x0Fassist\x08.", PREFIX);
}
// Print message to attacker,
if(StrEqual(sWeapon, "weapon_awp", true) && !GetEntProp(ATTACKER, Prop_Send, "m_bIsScoped") || StrEqual(sWeapon, "weapon_ssg08", true) && !GetEntProp(ATTACKER, Prop_Send, "m_bIsScoped")) {
g_Session[ATTACKER].AddPoints(bHeadshot ? 4 : 3);
PrintToChat(ATTACKER, "%s \x08You got \x10+%d points\x08 for killing \x03%N\x08 with a noscope%s.", PREFIX, bHeadshot ? 4: 3, VICTIM, bHeadshot ? " headshot" : "");
}
else {
int pointsForKill = bHeadshot ? 3 : 2;
g_Session[ATTACKER].AddPoints(pointsForKill);
PrintToChat(ATTACKER, "%s \x08You got \x10+%d points\x08 for killing \x03%N\x08%s.", PREFIX, pointsForKill, VICTIM, bHeadshot ? " with a headshot" : "");
}
g_Session[VICTIM].RemovePoints(2);
PrintToChat(VICTIM, "%s \x08You lost \x102 point\x08 for \x0Fdying\x08.", PREFIX);
}
//if(g_bUserHasBeenLoaded[ATTACKER] && g_bUserHasBeenLoaded[VICTIM])
//{
// SQL_UpdateStats(ATTACKER);
// SQL_UpdateStats(VICTIM);
//}
// Check if the client has ranked up or down
CheckRank(ATTACKER);
CheckRank(VICTIM);
}
}
return Plugin_Continue;
}
// When client is put into the server, aka joins
public void OnClientPutInServer(int client)
{
if(IsValidClient(client))
{
// Reset variables to 0
g_Rank[client].id = client;
g_Session[client].id = client;
g_Session[client].Reset();
// Create Timer to fetch data after 5.0s
//PrintToChat(client, PREFIX..."\x08Loading your rank..");
RequestFrame(GetStats_Callback, GetClientUserId(client));
}
}
// Timer Fetch userinfo
public void GetStats_Callback(any data)
{
int client = GetClientOfUserId(data);
// Is the client valid?
if(IsValidClient(client)) {
SQL_FetchUserData(client);
}
}
public Action Command_eTest(int client, int iArgs)
{
if(iArgs > 0) return Plugin_Handled;
int iTest = 322359;
int iLast = iTest % 10;
if(IsValidClient(client)) {
PrintToChat(client, "%s \x10%d", PREFIX, iLast);
}
return Plugin_Handled;
}
public Action Command_eRank(int client, int iArgs)
{
if(iArgs > 0) return Plugin_Handled;
if(IsValidClient(client)) {
SQL_GetRank(client);
//PrintToChat(client, "g_Session[client].stats[Stats_Rank] == %d", g_Session[client].stats[Stats_Rank]);
}
return Plugin_Handled;
}
int __GetTotalPlayers() {
int players = 0;
for(int p = 1; p <= MaxClients; p++) {
if(IsValidClient(p)) {
players++;
}
}
return players;
}
public void OnThinkPost(int iEnt)
{
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && 0 < i <= MaxClients && !IsFakeClient(i))
{
SetEntData(iEnt, g_iOffset+(i*4), g_Session[i].stats[Stats_Rank]+1);
}
}
}
public void OnPlayerRunCmdPost(int client, int iButtons)
{
static int iOldButtons[MAXPLAYERS+1];
if(iButtons & IN_SCORE && !(iOldButtons[client] & IN_SCORE))
{
StartMessageOne("ServerRankRevealAll", client, USERMSG_BLOCKHOOKS);
EndMessage();
}
iOldButtons[client] = iButtons;
}