· 8 years ago · Aug 12, 2018, 11:42 AM
1#include <sourcemod>
2#include <codmod>
3
4#pragma semicolon 1
5
6Handle g_hSql = null;
7
8int g_iMonety[MAXPLAYERS+1];
9
10public Plugin myinfo = {
11
12 name = "System ostrzeżeń",
13 description = "",
14 author = "fabko",
15 version = "1.0",
16 url = "fabko.ovh"
17};
18
19public void OnPluginStart()
20{
21 HookEvent("player_death", Event_PlayerDeath, EventHookMode_Post);
22 RegConsoleCmd("sm_monety", LiczMonety);
23 RegConsoleCmd("sm_sklep", CodSklep);
24 RegConsoleCmd("sm_s", CodSklep);
25 RegConsoleCmd("sm_shop", CodSklep);
26 DB_Connect();
27}
28
29public void OnMapEnd()
30{
31 for (int i = 1; i <= MaxClients; i++)
32 {
33 if (IsClientInGame(i))
34 {
35 DB_SaveInfo(i);
36 }
37 }
38}
39
40public void OnClientPutInServer(int client)
41{
42 g_iMonety[client] = 0;
43 DB_LoadInfo(client);
44}
45
46public void OnClientDisconnect(int client)
47{
48 DB_SaveInfo(client);
49}
50
51public Action DB_Connect()
52{
53 if (SQL_CheckConfig("fk_sklep"))
54 {
55 char DBBuffer[512];
56 g_hSql = SQL_Connect("fk_sklep", true, DBBuffer, 512);
57 if (g_hSql == null)
58 {
59 LogError("[FK] Could not connect: %s", DBBuffer);
60 }
61 else
62 {
63 SQL_LockDatabase(g_hSql);
64 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);
65 SQL_UnlockDatabase(g_hSql);
66 }
67 }
68 else
69 {
70 SetFailState("Musisz dopisac 'fk_sklep' w cfg!");
71 }
72}
73
74
75public void DB_LoadInfo(int client)
76{
77 char _authid[64];
78 GetClientAuthId(client, AuthId_Steam2, _authid, 63, true);
79 char sQuery[256];
80 Format(sQuery, 256, "SELECT Monety FROM fk_userzy WHERE auth_data = '%s';", _authid);
81 SQL_LockDatabase(g_hSql);
82 Handle hQuery = SQL_Query(g_hSql, sQuery, -1);
83 if (hQuery == null)
84 {
85 char blad[256];
86 SQL_GetError(g_hSql, blad, 255);
87 LogError("Blad: %s", blad);
88 CloseHandle(g_hSql);
89 }
90 else
91 {
92 if (SQL_FetchRow(hQuery))
93 {
94 g_iMonety[client] = SQL_FetchInt(hQuery, 0);
95 }
96 else
97 {
98 g_iMonety[client] = 0;
99 }
100 }
101 CloseHandle(hQuery);
102 SQL_UnlockDatabase(g_hSql);
103}
104
105public void DB_SaveInfo(int client)
106{
107 if (!IsValidClient(client) || IsFakeClient(client))
108 {
109 return;
110 }
111 char authid[64];
112 if (!GetClientAuthId(client, AuthId_Steam2, authid, 64, true))
113 {
114 return;
115 }
116 char nick[64];
117 char EscapedName[64];
118 GetClientName(client, nick, 64);
119 SQL_EscapeString(g_hSql, nick, EscapedName, 64);
120 char sQuery[512];
121 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]);
122 SQL_TQuery(g_hSql, DB_SaveInfoCallback, sQuery);
123}
124
125public int DB_SaveInfoCallback(Handle owner, Handle query, char[] error, any data)
126{
127 if (query == null)
128 {
129 LogError("[WARNS] Failed to save client info (error: %s)", error);
130 return;
131 }
132}
133
134public Action Event_PlayerDeath(Event event, char[] name, bool DontBroadcast)
135{
136 int client = GetClientOfUserId(event.GetInt("userid", 0));
137 int attacker = GetClientOfUserId(event. GetInt("attacker", 0));
138
139 if(client == attacker)
140 {
141 return;
142 }
143
144 if(IsPlayerVip(attacker))
145 {
146 int randomowa = GetRandomInt(1, 3);
147 switch(randomowa)
148 {
149 case 2:
150 {
151 PrintToChat(attacker, "★ \x07[COD -> Monety] \x05Udało Ci się, \x04znalazłeś monetę\x05!");
152 g_iMonety[attacker]++;
153 }
154 }
155 }
156
157 else
158 {
159 int randomowa = GetRandomInt(1, 4);
160 switch(randomowa)
161 {
162 case 2:
163 {
164 PrintToChat(attacker, "★ \x07[COD -> Monety] \x05Udało Ci się, \x04znalazłeś monetę\x05!");
165 g_iMonety[attacker]++;
166 }
167 }
168 }
169}
170
171public Action CodSklep(int client, int args)
172{
173 if(!cod_get_user_class(client))
174 {
175 PrintToChat(client, "★ \x07[COD -> Monety] \x05Wybierz klasę, aby skorzystać ze sklepu!");
176 }
177 else
178 {
179 Handle menu = CreateMenu(CodSklepHandler);
180 SetMenuTitle(menu, "Sklep ForceGame.pl:");
181 AddMenuItem(menu, "1", "Ulecz życie do pełna [30 monet]");
182 AddMenuItem(menu, "2", "Wylosuj dodatkowe doświadczenie [50 monet]");
183 AddMenuItem(menu, "3", "Wylosuj przedmiot [15 monet]");
184 AddMenuItem(menu, "4", "Napraw przedmiot [10 monet]");
185 DisplayMenu(menu, client, 0);
186 }
187
188 return Plugin_Handled;
189}
190
191public CodSklepHandler(Handle handle, MenuAction action, int client, int pos)
192{
193 if(action == MenuAction_Select)
194 {
195 char item[32];
196 GetMenuItem(handle, pos, item, 32);
197 CodSklep(client, 0);
198
199 int hajs = g_iMonety[client];
200
201 if(StrEqual(item, "1"))
202 {
203 if(hajs < 30)
204 {
205 PrintToChat(client, "★ \x07[COD -> Monety] \x05Masz za mało monet!");
206 }
207 else
208 {
209 int graczz = GetClientHealth(client);
210 int zdrowie = cod_get_user_maks_health(client);
211 if(!IsPlayerAlive(client) || graczz == zdrowie)
212 {
213 PrintToChat(client, "★ \x07[COD -> Monety] \x05Masz maksymalną liczbę życia!");
214 }
215 else
216 {
217 SetEntityHealth(client, zdrowie);
218 PrintToChat(client, "★ \x07[COD -> Monety] \x05Zostałeś uleczony!");
219 g_iMonety[client] = g_iMonety[client] - 30;
220 }
221 }
222 }
223 else if(StrEqual(item, "2"))
224 {
225 if(hajs < 50)
226 {
227 PrintToChat(client, "★ \x07[COD -> Monety] \x05Masz za mało monet!");
228 }
229 else
230 {
231 int losowyexp = GetRandomInt(1, 4);
232 int ilosc;
233 switch(losowyexp)
234 {
235 case 1:
236 {
237 ilosc = 250;
238 }
239 case 2:
240 {
241 ilosc = 500;
242 }
243 case 3:
244 {
245 ilosc = 750;
246 }
247 case 4:
248 {
249 ilosc = 1000;
250 }
251 default:
252 {
253
254 }
255 }
256
257 cod_set_user_xp(client, cod_get_user_xp(client)+ilosc);
258 PrintToChat(client, "★ \x07[COD -> Monety] \x05Dostałeś %i dodatkowego doświadczenia!", losowyexp);
259 g_iMonety[client] = g_iMonety[client] - 50;
260 }
261 }
262
263 else if(StrEqual(item, "3"))
264 {
265 if(hajs < 15)
266 {
267 PrintToChat(client, "★ \x07[COD -> Monety] \x05Masz za mało monet!");
268 }
269 else
270 {
271 char itemek[64];
272 cod_set_user_item(client, -1, -1, -1);
273 cod_get_item_name(cod_get_user_item(client), itemek, sizeof(itemek));
274 PrintToChat(client, "★ \x07[COD -> Monety] \x05Ze sklepu otrzymałeś \x04%s\x05!", itemek);
275 g_iMonety[client] = g_iMonety[client] - 15;
276 }
277 }
278
279 else if(StrEqual(item, "4"))
280 {
281 if(hajs < 10)
282 {
283 PrintToChat(client, "★ \x07[COD -> Monety] \x05Masz za mało monet!");
284 }
285 else
286 {
287 int itemg = cod_get_user_item(client);
288 int items = cod_get_user_item_stamina(client);
289 int itemm = GetConVarInt(FindConVar("cod_item_max_stamina"));
290
291 if(!itemg)
292 {
293 PrintToChat(client, "★ \x07[COD -> Monety] \x05Nie masz żadnego przedmiotu!");
294 }
295 else if(itemm <= items)
296 {
297 PrintToChat(client, "★ \x07[COD -> Monety] \x05Twój przedmiot ma maksymalną wytrzymałość!");
298 }
299 else
300 {
301 cod_set_user_item(client, itemg, cod_get_user_item_skill(client), itemm);
302 PrintToChat(client, "★ \x07[COD -> Monety] \x05Naprawiłeś swój przedmiot!");
303 g_iMonety[client] = g_iMonety[client] - 10;
304 }
305 }
306 }
307 }
308
309 else if(action == MenuAction_End)
310 {
311 CloseHandle(handle);
312 }
313}
314
315public Action LiczMonety(int client, int args)
316{
317 PrintToChatAll("%N ma %i monet!!!", client, g_iMonety[client]);
318}
319
320stock bool IsPlayerVip(int client)
321{
322 if(GetUserFlagBits(client) & ADMFLAG_CUSTOM1)
323 return true;
324 return false;
325}