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