· 6 years ago · Jun 28, 2019, 12:58 AM
1#include <sourcemod>
2
3#pragma semicolon 1
4#pragma newdecls required
5
6#define MOD_TAG "\x01\x0B★ \x07[» How2kill.pl «]\x04 "
7
8Handle g_hSql;
9
10int g_iAccountID[MAXPLAYERS+1];
11int g_iNsCounter[MAXPLAYERS+1];
12int g_iHsNscounter[MAXPLAYERS+1];
13
14public Plugin myinfo =
15{
16 name = "NoScope Detector",
17 author = "Pierwotnie jakiś idiota, New Version: Ch W.",
18 description = "",
19 version = "2.0",
20 url = ""
21}
22
23public void OnPluginStart()
24{
25 HookEvent("player_death", Event_PlayerDeath);
26
27 RegConsoleCmd("sm_ns", CMD_ns, "");
28 RegConsoleCmd("sm_nz", CMD_ns, "");
29 RegConsoleCmd("sm_topns", CMD_TopNS, "");
30 RegConsoleCmd("sm_topnz", CMD_TopNS, "");
31
32 DB_Connect();
33}
34
35public void OnClientAuthorized(int client, const char[] auth)
36{
37 if(!IsFakeClient(client))
38 DB_LoadInfo(client);
39}
40
41public void DB_Connect()
42{
43 char DBBuffer[512];
44 if(SQL_CheckConfig("noscope_detector"))
45 {
46 g_hSql = SQL_Connect("noscope_detector", true, DBBuffer, sizeof(DBBuffer));
47
48 if(g_hSql == INVALID_HANDLE)
49 PrintToServer("Could not connect: %s", DBBuffer);
50 else
51 {
52 SQL_LockDatabase(g_hSql);
53 SQL_FastQuery(g_hSql, "CREATE TABLE IF NOT EXISTS NsDetector (id INT(11) NOT NULL AUTO_INCREMENT, auth_data VARCHAR(48) NOT NULL, nick varchar(64) NOT NULL default '', noscope INT NOT NULL default 0, noscope_hs INT NOT NULL default 0, noscope_all INT NOT NULL default 0, PRIMARY KEY (`id`), UNIQUE KEY `auth_data` (`auth_data`));");
54 SQL_UnlockDatabase(g_hSql);
55 }
56 }
57 else
58 SetFailState("Nie mozna odnalezc konfiguracji 'noscope_detector' w databases.cfg.");
59}
60
61public void DB_LoadInfo(int client)
62{
63 if(g_hSql != INVALID_HANDLE)
64 {
65 char _authid[64];
66 GetClientAuthId(client, AuthId_Steam2, _authid, 63);
67
68 char sQuery[512];
69 Format(sQuery, sizeof(sQuery), "SELECT id, noscope, noscope_hs FROM NsDetector WHERE auth_data = '%s';", _authid);
70
71 SQL_LockDatabase(g_hSql);
72 Handle hQuery = SQL_Query(g_hSql, sQuery);
73
74 if(hQuery == INVALID_HANDLE)
75 {
76 char blad[255];
77 SQL_GetError(g_hSql, blad, sizeof(blad));
78 LogError("Nie mozna odszukac z tabeli. (blad: %s)", blad);
79 CloseHandle(g_hSql);
80 }
81 else if(SQL_FetchRow(hQuery))
82 {
83 g_iAccountID[client] = SQL_FetchInt(hQuery, 0);
84 g_iNsCounter[client] = SQL_FetchInt(hQuery, 1);
85 g_iHsNscounter[client] = SQL_FetchInt(hQuery, 2);
86 }
87 else
88 {
89 g_iAccountID[client] = -1;
90 g_iNsCounter[client] = 0;
91 g_iHsNscounter[client] = 0;
92 }
93
94 CloseHandle(hQuery);
95 SQL_UnlockDatabase(g_hSql);
96 }
97}
98
99public void DB_SaveInfo(int client)
100{
101 if(!IsValidClient(client) || IsFakeClient(client))
102 return;
103
104 char authid[64];
105 if(!GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid)))
106 return;
107
108 char nick[32];
109 char EscapedName[64];
110
111 GetClientName(client, nick, sizeof(nick));
112 SQL_EscapeString(g_hSql, nick, EscapedName, sizeof(nick));
113
114 char query[512];
115 Format(query, sizeof(query), "INSERT INTO `NsDetector` (auth_data, nick, noscope, noscope_hs, noscope_all) VALUES ('%s', '%s', %d, '%d', '%d') ON DUPLICATE KEY UPDATE nick=VALUES(nick), noscope=VALUES(noscope), noscope_hs=VALUES(noscope_hs), noscope_all=VALUES(noscope_all)", authid, EscapedName, g_iNsCounter[client], g_iHsNscounter[client], (g_iNsCounter[client] + g_iHsNscounter[client]));
116 SQL_TQuery(g_hSql, DB_SaveInfoCallback, query);
117}
118
119public int DB_SaveInfoCallback(Handle owner, Handle query, const char[] error, any data)
120{
121 if(query == INVALID_HANDLE)
122 {
123 LogError("Failed to save client info (error: %s)", error);
124 return;
125 }
126}
127
128public void OnClientDisconnect(int client)
129{
130 DB_SaveInfo(client);
131}
132
133public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
134{
135 char weapon[32];
136 GetEventString(event, "weapon", weapon, sizeof(weapon));
137
138 if(StrEqual(weapon, "weapon_awp") || StrEqual(weapon, "weapon_ssg08") || StrEqual(weapon, "weapon_scar20"))
139 {
140 int attacker = GetClientOfUserId(event.GetInt("attacker"));
141 int iIsScope = GetEntProp(attacker, Prop_Send, "m_bIsScoped");
142 bool bIsHeadShot = GetEventBool(event, "headshot");
143
144 if(!iIsScope)
145 {
146 if(bIsHeadShot)
147 {
148 g_iHsNscounter[attacker]++;
149 PrintToChatAll("%s Właśnie \x07%N \x04zrobił \x07Noscope + Heashot\x04 to już jego \x07 %i Noscope + Heashot", MOD_TAG, attacker, g_iHsNscounter[attacker]);
150 PrintToChat(attacker, "%s To jest twój \x07 %i \x04 Noscope + Heashot", MOD_TAG, g_iHsNscounter[attacker]);
151 }
152 else
153 {
154 g_iNsCounter[attacker]++;
155 PrintToChatAll("%s Właśnie \x07%N \x04zrobił \x07Noscope\x04 to już jego \x07 %i Noscope", MOD_TAG, attacker, g_iNsCounter[attacker]);
156 PrintToChat(attacker, "%s To jest twój \x07 %i \x04 Noscope", MOD_TAG, g_iNsCounter[attacker]);
157 }
158 }
159 }
160}
161
162public Action CMD_ns(int client, int args)
163{
164 PrintToChat(client, "%s Twoja liczba noscope to \x07%i", MOD_TAG, g_iNsCounter[client]);
165 PrintToChat(client, "%s Twoja liczba noscope + headshot to \x07%i", MOD_TAG, g_iHsNscounter[client]);
166}
167
168public Action CMD_TopNS(int client, int args)
169{
170 if(g_hSql != INVALID_HANDLE)
171 {
172 char buffer[200];
173 Format(buffer, sizeof(buffer), "SELECT auth_data, nick, noscope_all FROM ruletka ORDER BY noscope_all DESC");
174 SQL_TQuery(g_hSql, TopNSCallback, buffer, client);
175 }
176
177 return Plugin_Handled;
178}
179
180public int TopNSCallback(Handle owner, Handle hndl, char [] error, any client)
181{
182 if(hndl == INVALID_HANDLE)
183 {
184 LogError(error);
185 return;
186 }
187
188 Menu menu = CreateMenu(MenuHandler);
189 menu.SetTitle("Top NoScope");
190
191 int order = 0;
192 char name[MAX_NAME_LENGTH];
193 int iAllNoScope;
194 char steamid[128];
195 char textbuffer[128];
196
197 if(SQL_HasResultSet(hndl))
198 {
199 while (SQL_FetchRow(hndl))
200 {
201 order++;
202 SQL_FetchString(hndl, 0, steamid, sizeof(steamid));
203 SQL_FetchString(hndl, 1, name, sizeof(name));
204 iAllNoScope = SQL_FetchInt(hndl, 2);
205
206 Format(textbuffer,128, "%s zrobił %d", name, iAllNoScope);
207 menu.AddItem(steamid, textbuffer);
208 }
209 }
210
211 if(order < 1)
212 menu.AddItem("empty", "Ranking jest pusty!");
213
214 menu.ExitButton = true;
215 menu.ExitBackButton = false;
216 menu.Display(client,MENU_TIME_FOREVER);
217}
218
219public int MenuHandler(Menu menu, MenuAction action, int client, int itemNum)
220{
221 if(action == MenuAction_End)
222 {
223 CloseHandle(menu);
224 }
225}
226
227stock bool IsValidClient(int client)
228{
229 if(client >= 1 && client <= MaxClients && IsClientInGame(client))
230 return true;
231 return false;
232}