· 6 years ago · Jul 29, 2019, 08:06 PM
1/*========ZMIANY W PLUGINIE========
2
3 1.0 - Wydanie i opublikowanie pluginu
4
5====================================*/
6#pragma semicolon 1
7
8#define DEBUG
9
10#define TAG " \x04// \x02Only AWP + LvL \x04//\x01"
11#define aTAG " \x04// \x04// \x04// \x04// \x04// \x04// \x04// \x04// \x04// \x04// \x04// \x04// \x04// \x04// \x04// \x04// \x04// \x04// \x04// \x04//"
12
13#include <sourcemod>
14#include <sdktools>
15#include <sdkhooks>
16#include <cstrike>
17
18#pragma newdecls required
19
20char g_sWeaponsCanUse [][] =
21{
22 "weapon_knife",
23 "weapon_awp",
24};
25
26char awp_levels[20][32] =
27{
28 "1",
29 "2",
30 "3",
31 "4",
32 "5",
33 "6",
34 "7",
35 "8",
36 "9",
37 "10",
38 "11",
39 "12",
40 "13",
41 "14",
42 "15",
43 "16",
44 "17",
45 "18",
46 "19",
47 "20"
48};
49
50int awp_requirements[20] =
51{
52 0, // 1
53 500, // 2
54 1200, // 3
55 2000, // 4
56 3000, // 5
57 4300, // 6
58 6600, // 7
59 8800, // 8
60 10300, // 9
61 12000, // 10
62 14000, // 11
63 17000, // 12
64 21000, // 13
65 26000, // 14
66 33000, // 15
67 42000, // 16
68 50000, // 17
69 65000, // 18
70 80000, // 19
71 100000 // 20
72};
73
74int awp_lvl[65];
75int awp_exp[65];
76int awp_punktylv[65];
77int awp_zycie[65];
78int awp_grawitacja[65];
79int awp_predkosc[65];
80int awp_dmg[65];
81int awp_timer[65];
82
83// Pod baze danych
84
85int g_iBazaSql = 0;
86int g_iIsDataLoaded[65];
87
88bool g_bSaveData[65];
89
90Handle DB;
91
92// ===============
93
94public Plugin myinfo =
95{
96 name = "[DSH] Only AWP + LvL",
97 author = "Deshayiere",
98 description = "Plugin dodaje na serwer tryb Only AWP + LvL",
99 version = "1.0",
100 url = "https://steamcommunity.com/id/deszableble/"
101};
102
103public void OnPluginStart()
104{
105 HookEvent("player_spawn", Event_PlayerSpawn);
106 CreateTimer(1.0, timerhud, _, TIMER_REPEAT);
107 CreateTimer(300.0, timerautor, _, TIMER_REPEAT);
108 HookEvent("player_death", Event_PlayerDeath);
109 RegConsoleCmd("sm_poziom", awp_poziom);
110 RegConsoleCmd("sm_lvl", awp_poziom);
111 RegConsoleCmd("sm_level", awp_poziom);
112 RegConsoleCmd("sm_givepoints", awp_givepoints);
113 DatabaseConnect();
114 for(int i = 1; i <= MaxClients; i ++)
115 if(IsValidClient(i))
116 OnClientPutInServer(i);
117}
118
119public Action timerautor(Handle timer, int client)
120{
121 PrintToChatAll("%s Autorem paczki AWP + LVL jest Deshayiere.", TAG);
122}
123
124public void OnClientPutInServer(int client)
125{
126 SDKHook(client, SDKHook_WeaponCanUse, WeaponCanUse);
127 awp_lvl[client] = 1;
128 awp_exp[client] = 0;
129 awp_punktylv[client] = 0;
130 awp_zycie[client] = 0;
131 awp_grawitacja[client] = 0;
132 awp_predkosc[client] = 0;
133 awp_dmg[client] = 0;
134 awp_timer[client] = 0;
135 PrepareLoad(client);
136}
137
138public void OnMapEnd()
139{
140 for(int i = 1; i <= MaxClients; i++)
141 if(IsValidClient(i))
142 PrzygotujZapisanieDanych(i);
143}
144
145public Action PrzygotujZapisanieDanych(int client)
146{
147 if(!IsValidClient(client))
148 {
149 return;
150 }
151 if (g_bSaveData[client])
152 {
153 SaveAll(client);
154 g_bSaveData[client] = true;
155 }
156}
157
158public void OnClientDisconnect(int client)
159{
160 SDKUnhook(client, SDKHook_WeaponCanUse, WeaponCanUse);
161 SaveAll(client);
162}
163
164public void OnMapStart()
165{
166 ServerCommand("sv_gravity 800");
167 ServerCommand("mp_maxmoney 0");
168 ServerCommand("mp_freezetime 3");
169 ServerCommand("mp_timelimit 30");
170 ServerCommand("mp_roundtime 3");
171 ServerCommand("mp_buytime 0");
172 ServerCommand("mp_warmuptime 3");
173 ServerCommand("mp_t_default_secondary 0");
174 ServerCommand("mp_ct_default_secondary 0");
175}
176
177public Action WeaponCanUse(int client, int weapon)
178{
179 if(!IsValidClient(client) || !IsPlayerAlive(client))
180 return Plugin_Continue;
181
182 char weapons[32];
183 GetEdictClassname(weapon, weapons, sizeof(weapons));
184
185 for(int i = 0; i < sizeof(g_sWeaponsCanUse); i ++)
186 {
187 if(StrEqual(g_sWeaponsCanUse[i], weapons))
188 return Plugin_Continue;
189 }
190
191 return Plugin_Handled;
192}
193
194public Action awp_givepoints(int client, int args)
195{
196 if (GetUserFlagBits(client) && ADMFLAG_ROOT)
197 {
198 awp_punktylv[client] += 40;
199 SaveAll(client);
200 }
201}
202
203public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
204{
205 int client = GetClientOfUserId(GetEventInt(event, "userid"));
206 GivePlayerItem(client, "weapon_awp");
207 SetEntProp(client, Prop_Send, "m_ArmorValue", 100);
208 SetEntProp(client, Prop_Send, "m_bHasHelmet", 1);
209 if (IsValidClient(client))
210 {
211 SetEntityHealth(client, GetClientHealth(client)+(1 * awp_zycie[client]));
212 SetEntityGravity(client, GetGravity(client));
213 SetEntPropFloat(client, Prop_Send, "m_flLaggedMovementValue", GetSpeed(client));
214 CreateTimer(1.0, Timer_CheckSetGravity, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
215 }
216 char buffer[32];
217 Format(buffer, sizeof(buffer), "[ Poziom %i ]", awp_lvl[client]);
218 CS_SetClientClanTag(client, buffer);
219}
220
221float GetSpeed(int client)
222{
223 float fGetSpeed;
224 fGetSpeed = (1 + (0.02*awp_predkosc[client]));
225 return fGetSpeed;
226}
227
228float GetGravity(int client)
229{
230 float fGetGravity;
231 fGetGravity = (1 - (0.02*awp_grawitacja[client]));
232 return fGetGravity;
233}
234
235public Action Timer_CheckSetGravity(Handle event, int iUserid)
236{
237 int client = GetClientOfUserId(iUserid);
238 if (awp_timer[client] == 0)
239 {
240 if (GetEntityGravity(client) != GetGravity(client))
241 {
242 SetEntityGravity(client, GetGravity(client));
243 }
244 }
245 return Plugin_Continue;
246}
247
248public Action timerhud(Handle timer, int client)
249{
250 for (int i = 1; i <= MaxClients; i++)
251 {
252 if (IsClientInGame(i) && !IsFakeClient(i))
253 {
254 PrintHintText(i, "<font color='#00ff12'>//</font> <font color='#ff0000'>Only AWP + LvL</font> <font color='#00ff12'>//</font>\n<font color='#00c0ff'>» <font color='#ff9c00'>Poziom: %i\n<font color='#00c0ff'>» <font color='#ff9c00'>Doswiadczenie: %i", awp_lvl[i], awp_exp[i]);
255 }
256 }
257}
258
259public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
260{
261 char weapons[65];
262 char NoScopeHSInfo[256];
263 char NoScopeInfo[256];
264 char KnifeInfo[256];
265
266 bool hs = GetEventBool(event, "headshot");
267
268 int attacker = GetClientOfUserId(event.GetInt("attacker"));
269 int victim = GetClientOfUserId(event.GetInt("userid"));
270 int scope = GetEntProp(attacker, Prop_Send, "m_bIsScoped");
271
272 GetEventString(event, "weapon", weapons, sizeof(weapons));
273 if(StrEqual(weapons, "awp"))
274 {
275 if(hs && !scope)
276 {
277 if(GetUserFlagBits(attacker) & ADMFLAG_CUSTOM1 || ADMFLAG_ROOT)
278 {
279 awp_exp[attacker] += 50;
280 PrintToChat(attacker, "%s Dostajesz 40+10 EXPa za \x02zabicie HS + NS \x01gracza \x04%N \x02[ \x04Poziom %i \x02]", TAG, victim, awp_lvl[victim]);
281 Format(NoScopeHSInfo, sizeof(NoScopeHSInfo), "%s Gracz %N \x02[ \x04Poziom %i \x02]\x01 zabił gracza %N \x02[ \x04Poziom %i \x02]\x01 używając \x02HS + NS.", TAG, attacker, awp_lvl[attacker], victim, awp_lvl[victim]);
282 PrintToChatAll(NoScopeHSInfo);
283 LvlUp(attacker);
284 PrepareSaveData(attacker);
285 SaveAll(attacker);
286 }
287 else
288 {
289 awp_exp[attacker] += 40;
290 PrintToChat(attacker, "%s Dostajesz 40 EXPa za \x02zabicie HS + NS \x01gracza \x04%N \x02[ \x04Poziom %i \x02]", TAG, victim, awp_lvl[victim]);
291 Format(NoScopeHSInfo, sizeof(NoScopeHSInfo), "%s Gracz %N \x02[ \x04Poziom %i \x02]\x01 zabił gracza %N \x02[ \x04Poziom %i \x02]\x01 używając \x02HS + NS.", TAG, attacker, awp_lvl[attacker], victim, awp_lvl[victim]);
292 PrintToChatAll(NoScopeHSInfo);
293 LvlUp(attacker);
294 PrepareSaveData(attacker);
295 SaveAll(attacker);
296 }
297 }
298 else if(!hs && !scope)
299 {
300 if(GetUserFlagBits(attacker) & ADMFLAG_CUSTOM1 || ADMFLAG_ROOT)
301 {
302 awp_exp[attacker] += 40;
303 PrintToChat(attacker, "%s Dostajesz 30+10 EXPa za \x02zabicie NS \x01gracza \x04%N \x02[ \x04Poziom %i \x02]", TAG, victim, awp_lvl[victim]);
304 Format(NoScopeInfo, sizeof(NoScopeInfo), "%s Gracz %N \x02[ \x04Poziom %i \x02]\x01 zabił gracza %N \x02[ \x04Poziom %i \x02]\x01 używając \x02NS.", TAG, attacker, awp_lvl[attacker], victim, awp_lvl[victim]);
305 PrintToChatAll(NoScopeInfo);
306 LvlUp(attacker);
307 PrepareSaveData(attacker);
308 SaveAll(attacker);
309 }
310 else
311 {
312 awp_exp[attacker] += 30;
313 PrintToChat(attacker, "%s Dostajesz 30 EXPa za \x02zabicie NS \x01gracza \x04%N \x02[ \x04Poziom %i \x02]", TAG, victim, awp_lvl[victim]);
314 Format(NoScopeInfo, sizeof(NoScopeInfo), "%s Gracz %N \x02[ \x04Poziom %i \x02]\x01 zabił gracza %N \x02[ \x04Poziom %i \x02]\x01 używając \x02NS.", TAG, attacker, awp_lvl[attacker], victim, awp_lvl[victim]);
315 PrintToChatAll(NoScopeInfo);
316 LvlUp(attacker);
317 PrepareSaveData(attacker);
318 SaveAll(attacker);
319 }
320 }
321 else if(scope && !hs)
322 {
323 if(GetUserFlagBits(attacker) & ADMFLAG_CUSTOM1 || ADMFLAG_ROOT)
324 {
325 awp_exp[attacker] += 30;
326 PrintToChat(attacker, "%s Dostajesz 20+10 EXPa za \x02zabicie \x01gracza \x04%N \x02[ \x04Poziom %i \x02]", TAG, victim, awp_lvl[victim]);
327 LvlUp(attacker);
328 PrepareSaveData(attacker);
329 SaveAll(attacker);
330 }
331 else
332 {
333 awp_exp[attacker] += 20;
334 PrintToChat(attacker, "%s Dostajesz 20 EXPa za \x02zabicie \x01gracza \x04%N \x02[ \x04Poziom %i \x02]", TAG, victim, awp_lvl[victim]);
335 LvlUp(attacker);
336 PrepareSaveData(attacker);
337 SaveAll(attacker);
338 }
339 }
340 else if(scope && hs)
341 {
342 if(GetUserFlagBits(attacker) & ADMFLAG_CUSTOM1 || ADMFLAG_ROOT)
343 {
344 awp_exp[attacker] += 40;
345 PrintToChat(attacker, "%s Dostajesz 30+10 EXPa za \x02zabicie HS \x01gracza \x04%N \x02[ \x04Poziom %i \x02]", TAG, victim, awp_lvl[victim]);
346 LvlUp(attacker);
347 PrepareSaveData(attacker);
348 SaveAll(attacker);
349 }
350 else
351 {
352 awp_exp[attacker] += 30;
353 PrintToChat(attacker, "%s Dostajesz 30 EXPa za \x02zabicie HS \x01gracza \x04%N \x02[ \x04Poziom %i \x02]", TAG, victim, awp_lvl[victim]);
354 LvlUp(attacker);
355 PrepareSaveData(attacker);
356 SaveAll(attacker);
357 }
358 }
359 }
360 if (StrEqual(weapons, "knife_default_ct") || StrEqual(weapons, "knife_default_t") || StrEqual(weapons, "knife_t") || StrEqual(weapons, "knife_ct") || StrEqual(weapons, "knifegg") || StrEqual(weapons, "knife_flip") || StrEqual(weapons, "knife_gut") || StrEqual(weapons, "knife_karambit") || StrEqual(weapons, "bayonet") || StrEqual(weapons, "knife_m9_bayonet") || StrEqual(weapons, "knife_butterfly") || StrEqual(weapons, "knife_tactical") || StrEqual(weapons, "knife_falchion") || StrEqual(weapons, "knife_push") || StrEqual(weapons, "knife") || StrEqual(weapons, "knife_survival_bowie"))
361 {
362 if(GetUserFlagBits(attacker) & ADMFLAG_CUSTOM1 || ADMFLAG_ROOT)
363 {
364 awp_exp[attacker] += 45;
365 PrintToChat(attacker, "%s Dostajesz 35+10 EXPa za \x02zabicie nozem \x01gracza \x04%N \x02[ \x04Poziom %i \x02]", TAG, victim, awp_lvl[victim]);
366 Format(KnifeInfo, sizeof(KnifeInfo), "%s Gracz %N \x02[ \x04Poziom %i \x02]\x01 zabił gracza %N \x02[ \x04Poziom %i \x02]\x01 używając \x02noża.", TAG, attacker, awp_lvl[attacker], victim, awp_lvl[victim]);
367 PrintToChatAll(KnifeInfo);
368 LvlUp(attacker);
369 PrepareSaveData(attacker);
370 SaveAll(attacker);
371 }
372 else
373 {
374 awp_exp[attacker] += 35;
375 PrintToChat(attacker, "%s Dostajesz 35 EXPa za \x02zabicie nozem \x01gracza \x04%N \x02[ \x04Poziom %i \x02]", TAG, victim, awp_lvl[victim]);
376 Format(KnifeInfo, sizeof(KnifeInfo), "%s Gracz %N \x02[ \x04Poziom %i \x02]\x01 zabił gracza %N \x02[ \x04Poziom %i \x02]\x01 używając \x02noża.", TAG, attacker, awp_lvl[attacker], victim, awp_lvl[victim]);
377 PrintToChatAll(KnifeInfo);
378 LvlUp(attacker);
379 PrepareSaveData(attacker);
380 SaveAll(attacker);
381 }
382 }
383}
384
385public Action LvlUp(int client)
386{
387 char LvlUpInfo[256];
388 if (awp_exp[client] >= awp_requirements[awp_lvl[client]] && awp_lvl[client] < 20 )
389 {
390 awp_lvl[client]++;
391 PrintToChat(client, "%s Gratulacje! Awansowałeś do %i poziomu.", TAG, awp_lvl[client]);
392 Format(LvlUpInfo, sizeof(LvlUpInfo), "%s Gracz %N osiągnął %i poziom!", TAG, client, awp_lvl[client]);
393 PrintToChatAll(LvlUpInfo);
394 awp_punktylv[client] += 2;
395 PrepareSaveData(client);
396 SaveAll(client);
397 }
398}
399
400public Action awp_poziom(int client, int args)
401{
402 Menu poziom = new Menu(poziom_Handler);
403
404 char buffer[512];
405 FormatEx(buffer, 512, "Poziomy - OnlyAWP + LvL");
406 Format(buffer, 512, "%s\n » Poziom: %i", buffer, awp_lvl[client]);
407 Format(buffer, 512, "%s\n » EXP: %i", buffer, awp_exp[client]);
408 Format(buffer, 512, "%s\n » Wymagany EXP na nastepny LvL: %i", buffer, awp_requirements[awp_lvl[client]]);
409 Format(buffer, 512, "%s\n » Dostepne punkty ulepszen: %i", buffer, awp_punktylv[client]);
410
411 poziom.SetTitle(buffer);
412 poziom.AddItem("1", "Rozdaj punkty umiejetnosci");
413 poziom.AddItem("2", "Wyjdz");
414 poziom.ExitButton = false;
415 poziom.Display(client, 60);
416 return Plugin_Handled;
417}
418
419public int poziom_Handler(Menu menu, MenuAction action, int client, int position)
420{
421 if(action == MenuAction_Select)
422 {
423 char Item[32];
424 GetMenuItem(menu, position, Item, sizeof(Item));
425
426 if(StrEqual(Item, "1"))
427 awp_upgrade(client, 0);
428 }
429 else if(action == MenuAction_End)
430 CloseHandle(menu);
431}
432
433public Action awp_upgrade(int client, int args)
434{
435 Menu poziomx = new Menu(poziomx_Handler);
436
437 char sBuffer[512];
438 Format(sBuffer, sizeof(sBuffer), "Ulepszenia - OnlyAWP + LvL");
439 Format(sBuffer, sizeof(sBuffer), "%s\n » Kazde ulepszenie zycia dodaje +1 punkt", sBuffer);
440 Format(sBuffer, sizeof(sBuffer), "%s\n » Kazde ulepszenie grawitacji zmniejsza ja o -0,02", sBuffer);
441 Format(sBuffer, sizeof(sBuffer), "%s\n » Kazde ulepszenie predkosci zwieksza ja o +0,02", sBuffer);
442 Format(sBuffer, sizeof(sBuffer), "%s\n » Kazde ulepszenie obrazen zwieksza je o +1%", sBuffer);
443
444 poziomx.SetTitle(sBuffer);
445 Format(sBuffer, sizeof(sBuffer), "Ulepsz zycie! [%i/10]", awp_zycie[client]);
446 poziomx.AddItem("1", sBuffer, awp_zycie[client] != 10 ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED);
447 Format(sBuffer, sizeof(sBuffer), "Ulepsz grawitacje! [%i/10]", awp_grawitacja[client]);
448 poziomx.AddItem("2", sBuffer, awp_grawitacja[client] != 10 ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED);
449 Format(sBuffer, sizeof(sBuffer), "Ulepsz predkosc! [%i/10]", awp_predkosc[client]);
450 poziomx.AddItem("3", sBuffer, awp_predkosc[client] != 10 ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED);
451 Format(sBuffer, sizeof(sBuffer), "Ulepsz DMG! [%i/10]", awp_dmg[client]);
452 poziomx.AddItem("4", sBuffer, awp_dmg[client] != 10 ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED);
453 poziomx.AddItem("5", "Wyjdz");
454 poziomx.ExitButton = false;
455 poziomx.Display(client, 60);
456 return Plugin_Handled;
457}
458
459public int poziomx_Handler(Menu menu, MenuAction action, int client, int position)
460{
461 if(action == MenuAction_Select)
462 {
463 char Item[32];
464 GetMenuItem(menu, position, Item, sizeof(Item));
465
466 if(StrEqual(Item, "1"))
467 awp_healthup(client, 0);
468 else if(StrEqual(Item, "2"))
469 awp_gravityup(client, 0);
470 else if(StrEqual(Item, "3"))
471 awp_speedup(client, 0);
472 else if(StrEqual(Item, "4"))
473 awp_dmgup(client, 0);
474 }
475 else if(action == MenuAction_End)
476 CloseHandle(menu);
477}
478
479public Action awp_healthup(int client, int args)
480{
481 if (awp_zycie[client] < 10 && awp_punktylv[client] > 0)
482 {
483 awp_zycie[client]++;
484 PrintToChat(client, "%s", aTAG);
485 PrintToChat(client, "%s Pomyslnie ulepszyles zycie. Pozostale punkty umiejetnosci: %i", TAG, awp_punktylv[client]);
486 PrintToChat(client, "%s", aTAG);
487 awp_punktylv[client]--;
488 PrepareSaveData(client);
489 SaveAll(client);
490 awp_upgrade(client, 0);
491 }
492 else
493 {
494 PrintToChat(client, "%s", aTAG);
495 PrintToChat(client, "%s Nie spelniasz wymagan!", TAG);
496 PrintToChat(client, "%s", aTAG);
497 }
498}
499
500public Action awp_gravityup(int client, int args)
501{
502 if (awp_grawitacja[client] < 10 && awp_punktylv[client] > 0)
503 {
504 awp_grawitacja[client]++;
505 PrintToChat(client, "%s", aTAG);
506 PrintToChat(client, "%s Pomyslnie ulepszyles grawitacje. Pozostale punkty umiejetnosci: %i", TAG, awp_punktylv[client]);
507 PrintToChat(client, "%s", aTAG);
508 awp_punktylv[client]--;
509 PrepareSaveData(client);
510 SaveAll(client);
511 awp_upgrade(client, 0);
512 }
513 else
514 {
515 PrintToChat(client, "%s", aTAG);
516 PrintToChat(client, "%s \x02Nie spelniasz wymagan!", TAG);
517 PrintToChat(client, "%s", aTAG);
518 }
519}
520
521public Action awp_speedup(int client, int args)
522{
523 if (awp_predkosc[client] < 10 && awp_punktylv[client] > 0)
524 {
525 awp_predkosc[client]++;
526 PrintToChat(client, "%s", aTAG);
527 PrintToChat(client, "%s Pomyslnie ulepszyles predkosc. Pozostale punkty umiejetnosci: %i", TAG, awp_punktylv[client]);
528 PrintToChat(client, "%s", aTAG);
529 awp_punktylv[client]--;
530 PrepareSaveData(client);
531 SaveAll(client);
532 awp_upgrade(client, 0);
533 }
534 else
535 {
536 PrintToChat(client, "%s", aTAG);
537 PrintToChat(client, "%s \x02Nie spelniasz wymagan!", TAG);
538 PrintToChat(client, "%s", aTAG);
539 }
540}
541
542public Action awp_dmgup(int client, int args)
543{
544 if(awp_dmg[client] < 10 && awp_punktylv[client] > 0)
545 {
546 awp_dmg[client]++;
547 PrintToChat(client, "%s", aTAG);
548 PrintToChat(client, "%s Pomyslnie ulepszyles DMG. Pozostale punkty umiejetnosci: %i", TAG, awp_punktylv[client]);
549 PrintToChat(client, "%s", aTAG);
550 awp_punktylv[client]--;
551 PrepareSaveData(client);
552 SaveAll(client);
553 awp_upgrade(client, 0);
554 }
555 else
556 {
557 PrintToChat(client, "%s", aTAG);
558 PrintToChat(client, "%s \x02Nie spelniasz wymagan!", TAG);
559 PrintToChat(client, "%s", aTAG);
560 }
561}
562
563// ================= Baza Danych ================= //
564public Action DatabaseConnect()
565{
566 char error[512];
567 DB = SQL_Connect("AWPLVL", true, error, sizeof(error));
568 if(DB == INVALID_HANDLE)
569 {
570 LogError("Could not connect: %s", error);
571 g_iBazaSql = 0;
572 }
573 else if(g_iBazaSql < 1)
574 {
575 g_iBazaSql++;
576 char zapytanie[1024];
577 Format(zapytanie, sizeof(zapytanie), "CREATE TABLE IF NOT EXISTS `AWPLVL` (`sid` VARCHAR(64) NOT NULL, `EXP` INT NOT NULL, `Level` INT NOT NULL, `PunktyUm` INT NOT NULL, `HealthPointsAdded` INT NOT NULL, `GravityPointsAdded` INT NOT NULL, `SpeedPointsAdded` INT NOT NULL, `DMGPointsAdded` INT NOT NULL, UNIQUE KEY `sid` (`sid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;");
578
579 SQL_LockDatabase(DB);
580 SQL_FastQuery(DB, zapytanie);
581 SQL_UnlockDatabase(DB);
582 DatabaseConnect();
583 }
584}
585
586public void PrepareLoad(int client)
587{
588 if(!IsValidClient(client))
589 return;
590
591 if(!g_iBazaSql)
592 return;
593
594 char zapytanie[1024], authid[64];
595 GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid));
596
597 Format(zapytanie, sizeof(zapytanie), "SELECT `EXP`, `Level`, `PunktyUm`, `HealthPointsAdded`, `GravityPointsAdded`, `SpeedPointsAdded`, `DMGPointsAdded` FROM `AWPLVL` WHERE `sid` LIKE '%s';", authid);
598 SQL_TQuery(DB, Load, zapytanie, client);
599}
600
601public void Load(Handle owner, Handle query, const char[] error, any client)
602{
603 if(query == INVALID_HANDLE)
604 {
605 LogError("Load error: %s", error);
606 return;
607 }
608 if(SQL_GetRowCount(query))
609 {
610 while(SQL_MoreRows(query))
611 {
612 while(SQL_FetchRow(query))
613 {
614 awp_exp[client] = SQL_FetchInt(query, 0);
615 awp_lvl[client] = SQL_FetchInt(query, 1);
616 awp_punktylv[client] = SQL_FetchInt(query, 2);
617 awp_zycie[client] = SQL_FetchInt(query, 3);
618 awp_grawitacja[client] = SQL_FetchInt(query, 4);
619 awp_predkosc[client] = SQL_FetchInt(query, 5);
620 awp_dmg[client] = SQL_FetchInt(query, 6);
621 }
622 }
623 }
624 else
625 {
626 if(!IsValidClient(client))
627 return;
628
629 char zapytanie[1024], authid[64];
630 GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid));
631
632 Format(zapytanie, sizeof(zapytanie), "INSERT INTO `AWPLVL` (`sid`, `EXP`, `Level`, `PunktyUm`, `HealthPointsAdded`, `GravityPointsAdded`, `SpeedPointsAdded`, `DMGPointsAdded`) VALUES ('%s', '%i', '%i', '%i', '%i', '%i', '%i', '%i');", authid, awp_exp[client], awp_lvl[client], awp_punktylv[client], awp_zycie[client], awp_grawitacja[client], awp_predkosc[client], awp_dmg[client]);
633 SQL_TQuery(DB, SaveData_Handler, zapytanie, client);
634 }
635 g_iIsDataLoaded[client] = true;
636}
637
638public Action PrepareSaveData(int client)
639{
640 if(!IsValidClient(client))
641 {
642 return;
643 }
644 if (g_bSaveData[client])
645 {
646 SaveData(client);
647 g_bSaveData[client] = true;
648 }
649}
650
651public Action SaveData(int client)
652{
653 if(!g_iBazaSql) return;
654 if(!IsValidClient(client)) return;
655 if(g_iIsDataLoaded[client]) return;
656
657 char authid[64], zapytanie[1024];
658 GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid));
659
660 Format(zapytanie, sizeof(zapytanie), "INSERT INTO `AWPLVL` (`sid`, `EXP`, `Level`, `PunktyUm`, `HealthPointsAdded`, `GravityPointsAdded`, `SpeedPointsAdded`, `DMGPointsAdded`) VALUES ('%s', '%i', '%i', '%i', '%i', '%i', '%i', '%i') ON DUPLICATE KEY UPDATE `EXP`=VALUES(`EXP`), `Level`=VALUES(`Level`), `PunktyUm`=VALUES(`PunktyUm`), `HealthPointsAdded`=VALUES(`HealthPointsAdded`), `GravityPointsAdded`=VALUES(`GravityPointsAdded`), `SpeedPointsAdded`=VALUES(`SpeedPointsAdded`), `DMGPointsAdded`=VALUES(`DMGPointsAdded`);", authid, awp_exp[client], awp_lvl[client], awp_punktylv[client], awp_zycie[client], awp_grawitacja[client], awp_predkosc[client], awp_dmg[client]);
661 SQL_TQuery(DB, SaveData_Handler, zapytanie, client);
662}
663
664public Action SaveAll(int client)
665{
666 if(!g_iBazaSql) return;
667 if(!IsValidClient(client)) return;
668
669 char authid[64], zapytanie[1024];
670 GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid));
671
672 Format(zapytanie, 1024, "UPDATE `AWPLVL` SET `EXP`='%i', `Level`='%i', `PunktyUm`='%i', `HealthPointsAdded`='%i', `GravityPointsAdded`='%i', `SpeedPointsAdded`='%i', `DMGPointsAdded`='%i' WHERE `sid`='%s';", awp_exp[client], awp_lvl[client], awp_punktylv[client], awp_zycie[client], awp_grawitacja[client], awp_predkosc[client], awp_dmg[client], authid);
673 SQL_TQuery(DB, SaveData_Handler, zapytanie, client);
674}
675
676public void SaveData_Handler(Handle owner, Handle query, const char[] error, any client)
677{
678 if(query == INVALID_HANDLE)
679 {
680 LogError("Save error: %s", error);
681 return;
682 }
683}
684
685stock bool IsValidClient(int client)
686{
687 if(client <= 0 ) return false;
688 if(client > MaxClients) return false;
689 if(!IsClientConnected(client)) return false;
690 if(IsFakeClient(client)) return false;
691 return IsClientInGame(client);
692}