· 8 years ago · Aug 12, 2018, 11:46 AM
1#include <sourcemod>
2
3#pragma semicolon 1
4
5Handle g_hSql = null;
6
7int g_iMonety[MAXPLAYERS+1];
8
9public Plugin myinfo = {
10
11 name = "System ostrzeżeń",
12 description = "",
13 author = "fabko",
14 version = "1.0",
15 url = "fabko.ovh"
16};
17
18public void OnPluginStart()
19{
20 HookEvent("player_death", Event_PlayerDeath, EventHookMode_Post);
21 RegConsoleCmd("sm_monety", LiczMonety);
22 RegConsoleCmd("sm_sklep", CodSklep);
23 RegConsoleCmd("sm_s", CodSklep);
24 RegConsoleCmd("sm_shop", CodSklep);
25 DB_Connect();
26}
27
28public void OnMapEnd()
29{
30 for (int i = 1; i <= MaxClients; i++)
31 {
32 if (IsClientInGame(i))
33 {
34 DB_SaveInfo(i);
35 }
36 }
37}
38
39public void OnClientPutInServer(int client)
40{
41 g_iMonety[client] = 0;
42 DB_LoadInfo(client);
43}
44
45public void OnClientDisconnect(int client)
46{
47 DB_SaveInfo(client);
48}
49
50public Action DB_Connect()
51{
52 if (SQL_CheckConfig("fk_sklep"))
53 {
54 char DBBuffer[512];
55 g_hSql = SQL_Connect("fk_sklep", true, DBBuffer, 512);
56 if (g_hSql == null)
57 {
58 LogError("[FK] Could not connect: %s", DBBuffer);
59 }
60 else
61 {
62 SQL_LockDatabase(g_hSql);
63 SQL_FastQuery(g_hSql, "CREATE TABLE IF NOT EXISTS `fk_userzy` (`auth_data` VARCHAR(64) NOT NULL, `name` VARCHAR(64) NOT NULL, `Monety` INT NOT NULL, UNIQUE KEY `auth_data` (`auth_data`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;", -1);
64 SQL_UnlockDatabase(g_hSql);
65 }
66 }
67 else
68 {
69 SetFailState("Musisz dopisac 'fk_sklep' w cfg!");
70 }
71}
72
73
74public void DB_LoadInfo(int client)
75{
76 char _authid[64];
77 GetClientAuthId(client, AuthId_Steam2, _authid, 63, true);
78 char sQuery[256];
79 Format(sQuery, 256, "SELECT Monety FROM fk_userzy WHERE auth_data = '%s';", _authid);
80 SQL_LockDatabase(g_hSql);
81 Handle hQuery = SQL_Query(g_hSql, sQuery, -1);
82 if (hQuery == null)
83 {
84 char blad[256];
85 SQL_GetError(g_hSql, blad, 255);
86 LogError("Blad: %s", blad);
87 CloseHandle(g_hSql);
88 }
89 else
90 {
91 if (SQL_FetchRow(hQuery))
92 {
93 g_iMonety[client] = SQL_FetchInt(hQuery, 0);
94 }
95 else
96 {
97 g_iMonety[client] = 0;
98 }
99 }
100 CloseHandle(hQuery);
101 SQL_UnlockDatabase(g_hSql);
102}
103
104public void DB_SaveInfo(int client)
105{
106 if (!IsValidClient(client) || IsFakeClient(client))
107 {
108 return;
109 }
110 char authid[64];
111 if (!GetClientAuthId(client, AuthId_Steam2, authid, 64, true))
112 {
113 return;
114 }
115 char nick[64];
116 char EscapedName[64];
117 GetClientName(client, nick, 64);
118 SQL_EscapeString(g_hSql, nick, EscapedName, 64);
119 char sQuery[512];
120 Format(sQuery, sizeof(sQuery), "INSERT INTO `fk_userzy` (auth_data, name, Monety) VALUES ('%s', '%s', %d) ON DUPLICATE KEY UPDATE name=VALUES(name), Monety=VALUES(Monety)", authid, EscapedName, g_iMonety[client]);
121 SQL_TQuery(g_hSql, DB_SaveInfoCallback, sQuery);
122}
123
124public int DB_SaveInfoCallback(Handle owner, Handle query, char[] error, any data)
125{
126 if (query == null)
127 {
128 LogError("[WARNS] Failed to save client info (error: %s)", error);
129 return;
130 }
131}
132
133public Action Event_PlayerDeath(Event event, char[] name, bool DontBroadcast)
134{
135 int client = GetClientOfUserId(event.GetInt("userid", 0));
136 int attacker = GetClientOfUserId(event. GetInt("attacker", 0));
137
138 if(client == attacker)
139 {
140 return;
141 }
142
143 if(IsPlayerVip(attacker))
144 {
145 int randomowa = GetRandomInt(1, 3);
146 switch(randomowa)
147 {
148 case 2:
149 {
150 PrintToChat(attacker, "★ \x07[COD -> Monety] \x05Udało Ci się, \x04znalazłeś monetę\x05!");
151 g_iMonety[attacker]++;
152 }
153 }
154 }
155
156 else
157 {
158 int randomowa = GetRandomInt(1, 4);
159 switch(randomowa)
160 {
161 case 2:
162 {
163 PrintToChat(attacker, "★ \x07[COD -> Monety] \x05Udało Ci się, \x04znalazłeś monetę\x05!");
164 g_iMonety[attacker]++;
165 }
166 }
167 }
168}
169
170public Action CodSklep(int client, int args)
171{
172 Handle menu = CreateMenu(CodSklepHandler);
173 SetMenuTitle(menu, "Sklep ForceGame.pl:");
174 AddMenuItem(menu, "1", "Ulecz życie do pełna [30 monet]");
175 AddMenuItem(menu, "2", "Wylosuj dodatkowe doświadczenie [50 monet]");
176 AddMenuItem(menu, "3", "Wylosuj przedmiot [15 monet]");
177 AddMenuItem(menu, "4", "Napraw przedmiot [10 monet]");
178 DisplayMenu(menu, client, 0);
179
180 return Plugin_Handled;
181}
182
183public CodSklepHandler(Handle handle, MenuAction action, int client, int pos)
184{
185 if(action == MenuAction_Select)
186 {
187 char item[32];
188 GetMenuItem(handle, pos, item, 32);
189 CodSklep(client, 0);
190
191 int hajs = g_iMonety[client];
192
193 if(StrEqual(item, "1"))
194 {
195 if(hajs < 15)
196 {
197 PrintToChat(client, "★ \x07[COD -> Monety] \x05Masz za mało monet!"); //
198 }
199 else
200 {
201 //somethink
202 }
203 }
204 else if(StrEqual(item, "2"))
205 {
206 if(hajs < 15)
207 {
208 PrintToChat(client, "★ \x07[COD -> Monety] \x05Masz za mało monet!");
209 }
210 else
211 {
212 //somethink
213 }
214 }
215
216 else if(StrEqual(item, "3"))
217 {
218 if(hajs < 15)
219 {
220 PrintToChat(client, "★ \x07[COD -> Monety] \x05Masz za mało monet!");
221 }
222 else
223 {
224 //somethink
225 }
226 }
227
228 else if(StrEqual(item, "4"))
229 {
230 if(hajs < 15)
231 {
232 PrintToChat(client, "★ \x07[COD -> Monety] \x05Masz za mało monet!");
233 }
234 else
235 {
236 //somethink
237 }
238 }
239
240 }
241
242 else if(action == MenuAction_End)
243 {
244 CloseHandle(handle);
245 }
246}
247
248public Action LiczMonety(int client, int args)
249{
250 PrintToChatAll("%N ma %i monet!!!", client, g_iMonety[client]);
251}
252
253stock bool IsPlayerVip(int client)
254{
255 if(GetUserFlagBits(client) & ADMFLAG_CUSTOM1)
256 return true;
257 return false;
258}
259
260bool IsValidClient(int client)
261{
262 if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || IsFakeClient(client))
263 {
264 return false;
265 }
266 return true;
267}