· 8 years ago · Feb 26, 2018, 07:03 PM
1#pragma semicolon 1
2
3#define PLUGIN_AUTHOR "Yellon"
4#define PLUGIN_VERSION "1.0.1 <Stable>"
5
6#include <sourcemod>
7#include <sdkhooks>
8#include <sdktools>
9#include <cstrike>
10
11Handle cvar_punkty_za_zabojstwo;
12Handle cvar_punkty_za_zabojstwo_vip;
13Handle cvar_punkty_za_zabojstwo_hs;
14Handle cvar_punkty_za_zabojstwo_hs_vip;
15Handle cvar_punkty_za_win;
16Handle cvar_punkty_za_win_vip;
17Handle cvar_punkty_za_plant;
18Handle cvar_punkty_za_plant_vip;
19Handle cvar_punkty_za_def;
20Handle cvar_punkty_za_def_vip;
21Handle cvar_pokaz_hud;
22#define LoopValidClients(%1) for(int %1 = 1; %1 < MaxClients; %1++) if(IsValidClient(%1))
23int iPunkty[MAXPLAYERS + 1];
24int iRank[MAXPLAYERS + 1];
25
26int Przedzial_Rang[19] =
27{
28 0,
29 100,
30 200,
31 400,
32 800,
33 1300,
34 1800,
35 2700,
36 3700,
37 5000,
38 6500,
39 7500,
40 9000,
41 11000,
42 13000,
43 15000,
44 17000,
45 19000,
46 22000
47};
48char Nazwy_Rang[19][40] = {
49 "Unranked",
50 "Silver I",
51 "Silver II",
52 "Silver III",
53 "Silver IV",
54 "Silver Elite",
55 "Silver Elite Master",
56 "Gold Nova I",
57 "Gold Nova II",
58 "Gold Nova III",
59 "Gold Nova Master",
60 "Master Guardian I",
61 "Master Guardian II",
62 "Master Guardian Elite",
63 "Distinguished Master Guardian",
64 "Legendary Eagle",
65 "Legandary Eagle Master",
66 "Supreme Master First Class",
67 "The Global Elite"
68};
69
70Handle sql;
71int sql_baza = 0;
72
73int Postep[MAXPLAYERS + 1];
74
75int id_gracza_daj;
76int id_gracza_zabierz;
77int id_gracza_ustawrange;
78
79public Plugin myinfo =
80{
81 name = "[DangerZone.PL] System Rang",
82 author = PLUGIN_AUTHOR,
83 description = "",
84 version = PLUGIN_VERSION,
85 url = ""
86};
87
88char nick[MAXPLAYERS + 1][33];
89int use_hud[MAXPLAYERS + 1];
90
91public void OnPluginStart()
92{
93 cvar_punkty_za_zabojstwo = CreateConVar("rangi_kill", "1", "Ile pkt za zabicie");
94 cvar_punkty_za_zabojstwo_vip = CreateConVar("rangi_kill_vip", "2", "Ile pkt za zabicie vip.");
95 cvar_punkty_za_zabojstwo_hs = CreateConVar("rangi_kill_hs", "3", "Ile pkt za zabicie hs.");
96 cvar_punkty_za_zabojstwo_hs_vip = CreateConVar("rangi_kill_hs_vip", "5", "Ile pkt za zabicie hs vip.");
97
98 cvar_punkty_za_win = CreateConVar("wygrana_runda", "2", "Ile pkt za win");
99 cvar_punkty_za_win_vip = CreateConVar("wygrana_runda_vip", "4", "Ile pkt za win vip");
100
101 cvar_punkty_za_plant = CreateConVar("rangi_bomb_planted", "2", "Ile pkt za plant");
102 cvar_punkty_za_plant_vip = CreateConVar("rangi_bomb_planted_vip", "5", "Ile pkt za plant vip");
103 cvar_punkty_za_def = CreateConVar("rangi_bomb_defused", "2", "Ile pkt za def");
104 cvar_punkty_za_def_vip = CreateConVar("rangi_bomb_defused_vip", "5", "Ile pkt za def vip");
105
106 cvar_pokaz_hud = CreateConVar("rangi_pokaz_hud", "0", "Czy ma pokazwac hud");
107
108 HookEvent("bomb_planted", Event_BombPlanted);
109 HookEvent("bomb_defused", Event_BombDefused);
110 HookEvent("round_end", KoniecRundy);
111 HookEvent("player_death", eventPlayerDeath);
112 HookEvent("announce_phase_end", Event_AnnouncePhaseEnd);
113 HookEvent("player_spawn", eventPlayerSpawn);
114
115 RegConsoleCmd("sm_rangi", cmd_Rangi);
116 RegConsoleCmd("sm_ranga", cmd_Rangi);
117 RegConsoleCmd("sm_lvl", cmd_Rangi);
118
119 AutoExecConfig(true, "DZ_Rangi", "sourcemod");
120
121 DataBaseConnect();
122 CreateTimer(1.0, HUD, _, TIMER_REPEAT);
123}
124
125public eventPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
126{
127 new id = GetClientOfUserId(GetEventInt(event, "userid"));
128
129 ZapiszDB(id);
130}
131
132
133public Action:cmd_Rangi(id, args)
134{
135 Rangi(id);
136 return Plugin_Handled;
137}
138
139public OnClientConnected(id)
140{
141 //use_hud[id] = 1;
142 //iRank[id] = 0;
143 //iPunkty[id] = 0;
144 //id_gracza_daj = -1;
145 //id_gracza_zabierz = -1;
146 //id_gracza_ustawrange = -1;
147 //WczytajDB(id);
148}
149
150public OnClientDisconnect(client)
151{
152 ZapiszDB(client);
153}
154
155public OnClientPostAdminCheck(client) {
156 WczytajDB(client);
157}
158
159
160public OnClientPutInServer(client)
161{
162 //WczytajDB(client);
163 GetClientName(client, nick[client], 32);
164 //SDKHook(client, SDKHook_PreThink, Prethink);
165 //WczytajDB(client);
166}
167
168public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float[3] vel, float[3] angles, int &weapon)
169{
170 if (buttons & IN_SCORE)
171 {
172 Handle hBuffer = StartMessageOne("ServerRankRevealAll", client);
173 if (hBuffer)
174 EndMessage();
175 }
176}
177
178public Action Event_AnnouncePhaseEnd(Handle event, char[] name, bool dontBroadcast)
179{
180 Handle hBuffer = StartMessageAll("ServerRankRevealAll");
181 if (hBuffer)
182 EndMessage();
183}
184
185
186public Action HUD(Handle timer)
187{
188 LoopValidClients(client)
189 {
190 if (!IsValidPlayer(client))
191 return;
192
193 int hud = GetConVarInt(cvar_pokaz_hud);
194
195 char sHintText[512];
196
197 if (hud)
198 {
199 if (use_hud[client])
200 {
201 if (IsPlayerAlive(client))
202 {
203 Format(sHintText, 512, "<font face='Stratum2'><font color='#27c45b'> <center> DangerZone.pl </font>\n<font color='#27c45b'> Twoja ranga:</font> <font color='#94ce16'>[ %s ]</font>\n<font color='#27c45b'> Punkty:</font> <font color='#94ce16'>[ %d ]</center></font>\n", Nazwy_Rang[iRank[client]], iPunkty[client]);
204 PrintHintText(client, sHintText);
205 }
206 else
207 {
208 int spect = GetEntProp(client, Prop_Send, "m_iObserverMode");
209 if (spect == 4 || spect == 5)
210 {
211 int target = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
212 if (!(target == -1) && IsValidPlayer(target))
213 {
214 Format(sHintText, 512, "<font face='Stratum2'><font color='#27c45b'> <center> DangerZone.pl </font>\n<font color='#27c45b'> Twoja ranga:</font> <font color='#94ce16'>[ %s ]</font>\n<font color='#27c45b'> Punkty:</font> <font color='#94ce16'>[ %d ]</center></font>\n", Nazwy_Rang[iRank[target]], iPunkty[target]);
215 PrintHintText(client, sHintText);
216 }
217 }
218 }
219 }
220 }
221 }
222}
223public SprawdzRange(int id)
224{
225 new limit_rangi = 18;
226 new bool:zdobyl_range = false;
227
228 while (iPunkty[id] >= Przedzial_Rang[iRank[id] + 1] && iRank[id] < limit_rangi)
229 {
230 iRank[id]++;
231 zdobyl_range = true;
232 }
233
234 Postep[id] = RoundFloat((float(iPunkty[id]) / float(22000)) * 100);
235
236 if (Postep[id] > 100)
237 Postep[id] = 100;
238
239 if (zdobyl_range)
240 {
241 PrintToChatAll("\x01[\x04RANGI\x01]\x03 Gracz\x01 [\x04 %N\x01 ]\x03 zdobyl range\x01 [\x04 %s\x01 ]", id, Nazwy_Rang[iRank[id]]);
242 }
243}
244
245
246public eventPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
247{
248 new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
249 new enemy = GetClientOfUserId(GetEventInt(event, "userid"));
250 bool headshot = GetEventBool(event, "headshot", false);
251
252 if (!IsValidClient(attacker))
253 return;
254
255 if (!IsValidClient(enemy))
256 return;
257
258 if (attacker != enemy)
259 {
260 new punkty_za_zabojstwo = GetConVarInt(cvar_punkty_za_zabojstwo);
261 new punkty_za_zabojstwo_vip = GetConVarInt(cvar_punkty_za_zabojstwo_vip);
262 new punkty_za_zabojstwo_hs = GetConVarInt(cvar_punkty_za_zabojstwo_hs);
263 new punkty_za_zabojstwo_hs_vip = GetConVarInt(cvar_punkty_za_zabojstwo_hs_vip);
264
265 if (GetUserFlagBits(attacker) & ADMFLAG_RESERVATION)
266 {
267 if (headshot)
268 {
269 iPunkty[attacker] += punkty_za_zabojstwo_hs_vip;
270 PrintToChat(attacker, "\x01[\x04RANGI\x01]\x03 Jako\x04 V.I.P\x03 otrzymales\x01 [\x04 %i\x01 ]\x03 punktow za zabojstwo Headshotem", punkty_za_zabojstwo_hs_vip);
271 } else {
272 iPunkty[attacker] += punkty_za_zabojstwo_vip;
273 PrintToChat(attacker, "\x01[\x04RANGI\x01]\x03 Jako\x04 V.I.P\x03 otrzymales\x01 [\x04 %i\x01 ]\x03 punktow za zabojstwo", punkty_za_zabojstwo_vip);
274 }
275 }
276 else
277 {
278 if (headshot)
279 {
280 iPunkty[attacker] += punkty_za_zabojstwo_hs;
281 PrintToChat(attacker, "\x01[\x04RANGI\x01]\x03 Jako Gracz otrzymales\x01 [\x04 %i\x01 ]\x03 punktow za zabojstwo headshotem", punkty_za_zabojstwo_hs);
282 } else {
283 iPunkty[attacker] += punkty_za_zabojstwo;
284 PrintToChat(attacker, "\x01[\x04RANGI\x01]\x03 Jako Gracz otrzymales\x01 [\x04 %i\x01 ]\x03 punktow za zabojstwo", punkty_za_zabojstwo);
285 }
286 }
287
288 // Postep[attacker] = (iPunkty[attacker] / Przedzial_Rang[18]) * 100.0;
289 SprawdzRange(attacker);
290 //ZapiszDB(attacker);
291 }
292}
293
294public Action:KoniecRundy(Handle:event_endround, const String:name[], bool:dontBroadcast)
295{
296 new punkty_za_win = GetConVarInt(cvar_punkty_za_win);
297 new punkty_za_win_vip = GetConVarInt(cvar_punkty_za_win_vip);
298
299 for (new i = 1; i <= MaxClients; i++)
300 {
301 if (!IsClientInGame(i))
302 continue;
303
304 new druzyna = GetEventInt(event_endround, "winner");
305 if (druzyna == 2 && GetClientTeam(i) == CS_TEAM_T || druzyna == 3 && GetClientTeam(i) == CS_TEAM_CT)
306 {
307
308 if (IsPlayerAlive(i))
309 {
310 if (punkty_za_win || punkty_za_win_vip)
311 {
312 if (GetUserFlagBits(i) & ADMFLAG_RESERVATION)
313 {
314 PrintToChat(i, "\x01[\x04RANGI\x01]\x03 Dostales\x01 [\x04 %i\x01 ]\x03 punktow za wygranie rundy jako\x04 V.I.P.", punkty_za_win_vip);
315 iPunkty[i] += punkty_za_win_vip;
316 }
317 else {
318 PrintToChat(i, "\x01[\x04RANGI\x01]\x03 Dostales\x01 [\x04 %i\x01 ]\x03 punktow za wygranie rundy.", punkty_za_win);
319 iPunkty[i] += punkty_za_win;
320 }
321 }
322
323 }
324 }
325
326 SprawdzRange(i);
327 }
328}
329
330public Event_BombPlanted(Handle:event, const String:name[], bool:dontBroadcast)
331{
332 new punkty_za_plant = GetConVarInt(cvar_punkty_za_plant);
333 new punkty_za_plant_vip = GetConVarInt(cvar_punkty_za_plant_vip);
334
335 new client = GetClientOfUserId(GetEventInt(event, "userid"));
336
337 if (GetUserFlagBits(client) & ADMFLAG_RESERVATION)
338 {
339 iPunkty[client] += punkty_za_plant_vip;
340 } else {
341 iPunkty[client] += punkty_za_plant;
342 }
343
344 SprawdzRange(client);
345}
346
347public Event_BombDefused(Handle:event, const String:name[], bool:dontBroadcast)
348{
349 new punkty_za_def = GetConVarInt(cvar_punkty_za_def);
350 new punkty_za_def_vip = GetConVarInt(cvar_punkty_za_def_vip);
351
352 new client = GetClientOfUserId(GetEventInt(event, "userid"));
353
354 if (GetUserFlagBits(client) & ADMFLAG_RESERVATION)
355 {
356 iPunkty[client] += punkty_za_def_vip;
357 } else {
358 iPunkty[client] += punkty_za_def;
359 }
360
361 SprawdzRange(client);
362}
363
364stock IsValidPlayer(client)
365{
366 return (client >= 1 && client <= MaxClients && IsClientConnected(client) && !IsFakeClient(client) && IsClientInGame(client));
367}
368
369public void OnMapStart()
370{
371 //g_MaxClients = GetMaxClients();
372 int iIndex = FindEntityByClassname(65, "cs_player_manager");
373 if (iIndex == -1)
374 {
375 SetFailState("Unable to find cs_player_manager entity");
376 return;
377 }
378 SDKHook(iIndex, SDKHook_ThinkPost, Hook_OnThinkPost);
379}
380
381
382public Action Hook_OnThinkPost(int iEnt)
383{
384 static int iRankOffset = -1;
385 if (iRankOffset == -1)
386 iRankOffset = FindSendPropInfo("CCSPlayerResource", "m_iCompetitiveRanking");
387
388 SetEntDataArray(iEnt, iRankOffset, iRank, 65);
389}
390
391public Rangi(id)
392{
393 new hud = GetConVarInt(cvar_pokaz_hud);
394
395 new Handle:menu = CreateMenu(Rangi_Handled);
396
397 new String:szTitle[128], String:HuD[50];
398 Format(szTitle, sizeof(szTitle), "Witaj, [ %s ]\n", nick[id]);
399 Format(szTitle, sizeof(szTitle), "%sTwoje punkty: [ %d ]\n", szTitle, iPunkty[id]);
400 Format(szTitle, sizeof(szTitle), "%sTwoja ranga: [ %s ]\n \n", szTitle, Nazwy_Rang[iRank[id]]);
401 SetMenuTitle(menu, szTitle);
402
403 AddMenuItem(menu, "MG", "Menu Gracza");
404 AddMenuItem(menu, "SR", "Statystyki Rang");
405
406 if (hud)
407 {
408 Format(HuD, sizeof(HuD), "HUD na srodku ekranu: [ %s ]", use_hud[id] ? "ON" : "OFF");
409 AddMenuItem(menu, "Hnse", HuD);
410 }
411
412 if (GetUserFlagBits(id) & ADMFLAG_ROOT)
413 AddMenuItem(menu, "PA", "Panel Administratora");
414
415 SetMenuExitButton(menu, true);
416 DisplayMenu(menu, id, 90);
417}
418
419public int Rangi_Handled(Menu menu, MenuAction action, int id, int item)
420{
421 if (action == MenuAction_Select)
422 {
423 new String:info[64];
424 GetMenuItem(menu, item, info, sizeof(info));
425
426 if (StrEqual(info, "MG"))
427 {
428 Menu_Gracza(id);
429 }
430 else if (StrEqual(info, "SR"))
431 {
432 FakeClientCommand(id, "say !statyst");
433 }
434 else if (StrEqual(info, "Hnse"))
435 {
436 use_hud[id] = !use_hud[id];
437 PrintToChat(id, "\x01[\x04RANGI\x01]\x04 %s\x03 Hud na srodku ekranu", use_hud[id] ? "Wlaczyles" : "Wylaczyles");
438 Rangi(id);
439 }
440 else if (StrEqual(info, "PA"))
441 {
442 PA(id);
443 }
444
445 } else if (action == MenuAction_Cancel) {
446 }
447 else if (action == MenuAction_End)
448 {
449 CloseHandle(menu);
450 }
451}
452
453public Menu_Gracza(id)
454{
455 new Handle:menu = CreateMenu(Menu_Gracza_Handled);
456
457 new String:szTitle[128];
458 Format(szTitle, sizeof(szTitle), "Menu Gracza");
459 SetMenuTitle(menu, szTitle);
460
461 AddMenuItem(menu, "1", "System Punktow");
462 AddMenuItem(menu, "2", "Rangi i ich punkty");
463 AddMenuItem(menu, "3", "Powrot");
464
465 SetMenuExitButton(menu, true);
466 DisplayMenu(menu, id, 90);
467}
468
469public int Menu_Gracza_Handled(Menu menu, MenuAction action, int id, int item)
470{
471 if (action == MenuAction_Select)
472 {
473 switch (item)
474 {
475 case 0:SystemPunktow(id);
476 case 1:RangiPunkty(id);
477 case 2:Rangi(id);
478 }
479
480 } else if (action == MenuAction_Cancel) {
481 }
482 else if (action == MenuAction_End)
483 {
484 CloseHandle(menu);
485 }
486}
487
488public RangiPunkty(id)
489{
490 new Handle:menu = CreateMenu(RangiPunkty_Handled);
491
492 new String:szTitle[128], String:Ranga[128];
493 Format(szTitle, sizeof(szTitle), "[ Rangi i ich punkty ] -> Opis\n \n");
494 SetMenuTitle(menu, szTitle);
495
496 AddMenuItem(menu, "1", ">> Powrot\n \n");
497
498 for (int i = 1; i < sizeof(Nazwy_Rang); i++)
499 {
500 Format(Ranga, sizeof(Ranga), "%s - [ %d pkt ]", Nazwy_Rang[i], Przedzial_Rang[i]);
501 AddMenuItem(menu, Ranga, Ranga);
502 }
503
504 SetMenuExitButton(menu, true);
505 DisplayMenu(menu, id, 90);
506}
507
508public int RangiPunkty_Handled(Menu menu, MenuAction action, int id, int item)
509{
510 if (action == MenuAction_Select)
511 {
512 switch (item)
513 {
514 case 0:Menu_Gracza(id);
515 }
516 } else if (action == MenuAction_Cancel) {
517 }
518 else if (action == MenuAction_End)
519 {
520 CloseHandle(menu);
521 }
522}
523
524public SystemPunktow(id)
525{
526 new Handle:menu = CreateMenu(SystemPTK_Handled);
527
528 new String:szTitle[128];
529 Format(szTitle, sizeof(szTitle), "[ System Punktow ] -> Wybierz");
530 SetMenuTitle(menu, szTitle);
531
532 AddMenuItem(menu, "1", ">> Zwykly Gracz");
533 AddMenuItem(menu, "2", ">> Gracz V.I.P");
534 AddMenuItem(menu, "3", "Powrot");
535
536 SetMenuExitButton(menu, true);
537 DisplayMenu(menu, id, 90);
538}
539
540public int SystemPTK_Handled(Menu menu, MenuAction action, int id, int item)
541{
542 if (action == MenuAction_Select)
543 {
544 switch (item)
545 {
546 case 0:
547 {
548 new punkty_za_zabojstwo = GetConVarInt(cvar_punkty_za_zabojstwo);
549 new punkty_za_zabojstwo_hs = GetConVarInt(cvar_punkty_za_zabojstwo_hs);
550 new punkty_za_win = GetConVarInt(cvar_punkty_za_win);
551 new punkty_za_plant = GetConVarInt(cvar_punkty_za_plant);
552 new punkty_za_def = GetConVarInt(cvar_punkty_za_def);
553
554
555 new Handle:menu2 = CreateMenu(Gracz_Handled);
556
557 new String:szTitle[1024];
558 Format(szTitle, sizeof(szTitle), "[ System Punktow ] -> Zwykly Gracz\n \n");
559 Format(szTitle, sizeof(szTitle), "%sZabójstwo Przeciwnika: [ %d pkt ]\n", szTitle, punkty_za_zabojstwo);
560 Format(szTitle, sizeof(szTitle), "%sZabójstwo Przeciwnika HeadShotem: [ %d pkt ]\n", szTitle, punkty_za_zabojstwo_hs);
561 Format(szTitle, sizeof(szTitle), "%sWygranie rundy: [ %d pkt ]\n", szTitle, punkty_za_win);
562 Format(szTitle, sizeof(szTitle), "%sPodłożenie bomby: [ %d pkt ]\n", szTitle, punkty_za_plant);
563 Format(szTitle, sizeof(szTitle), "%sRozbrojenie bomby: [ %d pkt ]\n \n", szTitle, punkty_za_def);
564 SetMenuTitle(menu2, szTitle);
565
566 AddMenuItem(menu2, "1", "Powrot");
567
568 SetMenuExitButton(menu2, true);
569 DisplayMenu(menu2, id, 90);
570 }
571 case 1:
572 {
573 new punkty_za_zabojstwo_vip = GetConVarInt(cvar_punkty_za_zabojstwo_vip);
574 new punkty_za_zabojstwo_hs_vip = GetConVarInt(cvar_punkty_za_zabojstwo_hs_vip);
575 new punkty_za_win_vip = GetConVarInt(cvar_punkty_za_win_vip);
576 new punkty_za_plant_vip = GetConVarInt(cvar_punkty_za_plant_vip);
577 new punkty_za_def_vip = GetConVarInt(cvar_punkty_za_def_vip);
578
579
580 new Handle:menu3 = CreateMenu(Gracz_Handled);
581
582 new String:szTitle[1024];
583 Format(szTitle, sizeof(szTitle), "[ System Punktow ] -> Gracz V.I.P\n \n");
584 Format(szTitle, sizeof(szTitle), "%sZabójstwo Przeciwnika: [ %d pkt ]\n", szTitle, punkty_za_zabojstwo_vip);
585 Format(szTitle, sizeof(szTitle), "%sZabójstwo Przeciwnika HeadShotem: [ %d pkt ]\n", szTitle, punkty_za_zabojstwo_hs_vip);
586 Format(szTitle, sizeof(szTitle), "%sWygranie rundy: [ %d pkt ]\n", szTitle, punkty_za_win_vip);
587 Format(szTitle, sizeof(szTitle), "%sPodłożenie bomby: [ %d pkt ]\n", szTitle, punkty_za_plant_vip);
588 Format(szTitle, sizeof(szTitle), "%sRozbrojenie bomby: [ %d pkt ]\n \n", szTitle, punkty_za_def_vip);
589 SetMenuTitle(menu3, szTitle);
590
591 AddMenuItem(menu3, "1", "Powrot");
592
593 SetMenuExitButton(menu3, true);
594 DisplayMenu(menu3, id, 90);
595 }
596 case 2:Rangi(id);
597 }
598
599 } else if (action == MenuAction_Cancel) {
600 }
601 else if (action == MenuAction_End)
602 {
603 CloseHandle(menu);
604 }
605}
606
607public int Gracz_Handled(Menu menu, MenuAction action, int id, int item)
608{
609 if (action == MenuAction_Select)
610 {
611 switch (item)
612 {
613 case 0:SystemPunktow(id);
614 }
615 } else if (action == MenuAction_Cancel) {
616 }
617 else if (action == MenuAction_End)
618 {
619 CloseHandle(menu);
620 }
621}
622
623public PA(id)
624{
625 new Handle:menu = CreateMenu(PA_Handled);
626
627 new String:szTitle[128];
628 Format(szTitle, sizeof(szTitle), "[ Panel Administratora ] -> Wybierz");
629 SetMenuTitle(menu, szTitle);
630
631 AddMenuItem(menu, "1", ">> Dodaj Punkty <<");
632 AddMenuItem(menu, "2", ">> Zabierz Punkty <<");
633 AddMenuItem(menu, "3", ">> Ustaw Range <<");
634 AddMenuItem(menu, "3", ">> Pokaz Punkty Graczy Online <<");
635 AddMenuItem(menu, "3", "> Powrot <");
636
637 SetMenuExitButton(menu, true);
638 DisplayMenu(menu, id, 90);
639}
640
641public int PA_Handled(Menu menu, MenuAction action, int id, int item)
642{
643 if (action == MenuAction_Select)
644 {
645 switch (item)
646 {
647 case 0:DodajPtk(id);
648 case 1:ZabierzPtk(id);
649 case 2:UstawRange(id);
650 case 3:Online(id);
651 case 4:Rangi(id);
652 }
653 } else if (action == MenuAction_Cancel) {
654 }
655 else if (action == MenuAction_End)
656 {
657 CloseHandle(menu);
658 }
659}
660
661public Action:DodajPtk(client)
662{
663 new Handle:menu = CreateMenu(DodajPtk_Handler);
664 SetMenuTitle(menu, "[ Panel Administratora ] -> Dodaj Punkty -> Komu");
665 for (new i = 1; i < GetMaxClients(); i++)
666 {
667 if (!IsClientInGame(i))
668 continue;
669
670 new String:buffer[50];
671 new String:poz[10];
672 Format(buffer, 49, "%s", nick[i]);
673 Format(poz, 9, "%i", i);
674 AddMenuItem(menu, poz, buffer);
675 }
676 SetMenuExitButton(menu, true);
677 DisplayMenu(menu, client, 15);
678
679 return Plugin_Handled;
680}
681
682public DodajPtk_Handler(Handle:menu, MenuAction:action, id, param2)
683{
684 if (action == MenuAction_End)
685 {
686 CloseHandle(menu);
687 }
688 else
689 if (action == MenuAction_Select)
690 {
691 decl String:UserID[4];
692 GetMenuItem(menu, param2, UserID, sizeof(UserID), _, "", 0);
693
694 new id2 = StringToInt(UserID[0]);
695
696 if (IsClientInGame(id2))
697 {
698 id_gracza_daj = id2;
699 DodajPtk2(id);
700 } else PrintToChat(id, "\x01[\x04RANGI\x01]\x03 Gracz sie rozłączył");
701 }
702 return 0;
703}
704
705public DodajPtk2(id)
706{
707 new Handle:menu = CreateMenu(DodajPtk_Handled2);
708
709 new String:szTitle[128];
710 Format(szTitle, sizeof(szTitle), "[ Panel Administratora ] -> Dodaj Punkty -> Ile");
711 SetMenuTitle(menu, szTitle);
712
713 AddMenuItem(menu, "1", ">> 1");
714 AddMenuItem(menu, "2", ">> 10");
715 AddMenuItem(menu, "3", ">> 100");
716 AddMenuItem(menu, "4", ">> 1000");
717 AddMenuItem(menu, "5", "> Powrot <");
718
719 SetMenuExitButton(menu, true);
720 DisplayMenu(menu, id, 90);
721}
722
723public int DodajPtk_Handled2(Menu menu, MenuAction action, int id, int item)
724{
725 if (action == MenuAction_Select)
726 {
727 switch (item)
728 {
729 case 0:iPunkty[id_gracza_daj] += 1;
730 case 1:iPunkty[id_gracza_daj] += 10;
731 case 2:iPunkty[id_gracza_daj] += 100;
732 case 3:iPunkty[id_gracza_daj] += 1000;
733 case 4:PA(id);
734 }
735 } else if (action == MenuAction_Cancel) {
736 }
737 else if (action == MenuAction_End)
738 {
739 CloseHandle(menu);
740 }
741}
742
743public Action:ZabierzPtk(client)
744{
745 new Handle:menu = CreateMenu(ZabierzPtk_Handler);
746 SetMenuTitle(menu, "[ Panel Administratora ] -> Zabierz Punkty -> Komu");
747 for (new i = 1; i < GetMaxClients(); i++)
748 {
749 if (!IsClientInGame(i))
750 continue;
751
752 new String:buffer[50];
753 new String:poz[10];
754 Format(buffer, 49, "%s", nick[i]);
755 Format(poz, 9, "%i", i);
756 AddMenuItem(menu, poz, buffer);
757 }
758 SetMenuExitButton(menu, true);
759 DisplayMenu(menu, client, 15);
760
761 return Plugin_Handled;
762}
763
764public ZabierzPtk_Handler(Handle:menu, MenuAction:action, id, param2)
765{
766 if (action == MenuAction_End)
767 {
768 CloseHandle(menu);
769 }
770 else
771 if (action == MenuAction_Select)
772 {
773 decl String:UserID[4];
774 GetMenuItem(menu, param2, UserID, sizeof(UserID), _, "", 0);
775
776 new id2 = StringToInt(UserID[0]);
777
778 if (IsClientInGame(id2))
779 {
780 id_gracza_zabierz = id2;
781 ZabierzPtk2(id);
782 } else PrintToChat(id, "\x01[\x04RANGI\x01]\x03 Gracz sie rozłączył");
783 }
784 return 0;
785}
786
787public ZabierzPtk2(id)
788{
789 new Handle:menu = CreateMenu(ZabierzPtk_Handled2);
790
791 new String:szTitle[128];
792 Format(szTitle, sizeof(szTitle), "[ Panel Administratora ] -> Zabierz Punkty -> Ile");
793 SetMenuTitle(menu, szTitle);
794
795 AddMenuItem(menu, "1", ">> -1");
796 AddMenuItem(menu, "2", ">> -10");
797 AddMenuItem(menu, "3", ">> -100");
798 AddMenuItem(menu, "4", ">> -1000");
799 AddMenuItem(menu, "5", "> Powrot <");
800
801 SetMenuExitButton(menu, true);
802 DisplayMenu(menu, id, 90);
803}
804
805public int ZabierzPtk_Handled2(Menu menu, MenuAction action, int id, int item)
806{
807 if (action == MenuAction_Select)
808 {
809 switch (item)
810 {
811 case 0:iPunkty[id_gracza_zabierz] -= 1;
812 case 1:iPunkty[id_gracza_zabierz] -= 10;
813 case 2:iPunkty[id_gracza_zabierz] -= 100;
814 case 3:iPunkty[id_gracza_zabierz] -= 1000;
815 case 4:PA(id);
816 }
817 } else if (action == MenuAction_Cancel) {
818 }
819 else if (action == MenuAction_End)
820 {
821 CloseHandle(menu);
822 }
823}
824
825public Action:UstawRange(client)
826{
827 new Handle:menu = CreateMenu(UstawRange_Handler);
828 SetMenuTitle(menu, "[ Panel Administratora ] -> Ustaw Range -> Komu");
829 for (new i = 1; i < GetMaxClients(); i++)
830 {
831 if (!IsClientInGame(i))
832 continue;
833
834 new String:buffer[50];
835 new String:poz[10];
836 Format(buffer, 49, "%s", nick[i]);
837 Format(poz, 9, "%i", i);
838 AddMenuItem(menu, poz, buffer);
839 }
840 SetMenuExitButton(menu, true);
841 DisplayMenu(menu, client, 15);
842
843 return Plugin_Handled;
844}
845
846public UstawRange_Handler(Handle:menu, MenuAction:action, id, param2)
847{
848 if (action == MenuAction_End)
849 {
850 CloseHandle(menu);
851 }
852 else
853 if (action == MenuAction_Select)
854 {
855 decl String:UserID[4];
856 GetMenuItem(menu, param2, UserID, sizeof(UserID), _, "", 0);
857
858 new id2 = StringToInt(UserID[0]);
859
860 if (IsClientInGame(id2))
861 {
862 id_gracza_ustawrange = id2;
863 UstawRange2(id);
864 } else PrintToChat(id, "\x01[\x04RANGI\x01]\x03 Gracz sie rozłączył");
865 }
866 return 0;
867}
868
869public UstawRange2(id)
870{
871 new Handle:menu = CreateMenu(UstawRange_Handled2);
872
873 new String:szTitle[128], String:Ranga[128];
874 Format(szTitle, sizeof(szTitle), "[ Panel Administratora ] -> Ustaw Range -> JakÄ…");
875 SetMenuTitle(menu, szTitle);
876
877 for (int i = 1; i < sizeof(Nazwy_Rang); i++)
878 {
879 Format(Ranga, sizeof(Ranga), "%s", Nazwy_Rang[i]);
880 AddMenuItem(menu, Ranga, Ranga);
881 }
882
883 SetMenuExitButton(menu, true);
884 DisplayMenu(menu, id, 90);
885}
886
887public int UstawRange_Handled2(Menu menu, MenuAction action, int id, int item)
888{
889 if (action == MenuAction_Select)
890 {
891 iRank[id_gracza_ustawrange] = item + 1;
892 iPunkty[id_gracza_ustawrange] = Przedzial_Rang[item + 1];
893 // SprawdzRange(id_gracza_ustawrange);
894 PrintToChat(id_gracza_ustawrange, "\x01[\x04RANGI\x01]\x03 Admin ustawił Ci rangę:\x04 %s", Nazwy_Rang[iRank[id_gracza_ustawrange]]);
895 } else if (action == MenuAction_Cancel) {
896 }
897 else if (action == MenuAction_End)
898 {
899 CloseHandle(menu);
900 }
901}
902
903public Action:Online(client)
904{
905 new Handle:menu = CreateMenu(Online_Handler);
906 SetMenuTitle(menu, "[ Panel Administratora ] -> Gracze Online");
907 for (new i = 1; i < GetMaxClients(); i++)
908 {
909 if (!IsClientInGame(i))
910 continue;
911
912 new String:buffer[50];
913 new String:poz[10];
914 Format(buffer, 49, "%s -> [ %d pkt ]", nick[i], iPunkty[i]);
915 Format(poz, 9, "%i", i);
916 AddMenuItem(menu, poz, buffer);
917 }
918 SetMenuExitButton(menu, true);
919 DisplayMenu(menu, client, 15);
920
921 return Plugin_Handled;
922}
923
924public Online_Handler(Handle:menu, MenuAction:action, id, param2)
925{
926 if (action == MenuAction_End)
927 {
928 CloseHandle(menu);
929 }
930 else
931 if (action == MenuAction_Select)
932 {
933 decl String:UserID[4];
934 GetMenuItem(menu, param2, UserID, sizeof(UserID), _, "", 0);
935
936 // new id2 = StringToInt(UserID[0]);
937 }
938 return 0;
939}
940
941//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
942
943public Action DataBaseConnect()
944{
945 char error[512];
946
947 if (SQL_CheckConfig("Rangi_DZ")) {
948 sql = SQL_Connect("Rangi_DZ", true, error, sizeof(error));
949 } else if (SQL_CheckConfig("Rangi_DZ_SQL")) {
950 sql = SQL_Connect("Rangi_DZ_SQL", true, error, sizeof(error));
951 } else {
952 sql = SQL_Connect("default", true, error, sizeof(error));
953 }
954
955 if (sql == INVALID_HANDLE)
956 {
957 LogError("Could not connect: %s", error);
958 sql_baza = 0;
959 }
960 else if (sql_baza < 1)
961 {
962 sql_baza++;
963 char zapytanie[1024];
964 Format(zapytanie, sizeof(zapytanie), "CREATE TABLE IF NOT EXISTS `Rangi` (`sid` VARCHAR(64) NOT NULL, `Nick` VARCHAR(64), `Punkty` INT(20), `Rank_ID` INT(6),`Postep` INT(20), UNIQUE KEY `sid` (`sid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;");
965
966 SQL_LockDatabase(sql);
967 SQL_FastQuery(sql, zapytanie);
968 SQL_UnlockDatabase(sql);
969 DataBaseConnect();
970 }
971}
972
973public int ZapiszDB(int client)
974{
975 if (!sql_baza)
976 return;
977
978 if (iPunkty[client])
979 {
980 char authid[64], zapytanie[1024];
981
982 if (!GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid)))
983 return;
984
985 Format(zapytanie, sizeof(zapytanie), "INSERT INTO `Rangi` (`sid`, `Nick`, `Punkty`, `Rank_ID`, `Postep`) VALUES ('%s', '%s', '%i', '%i', '%i') ON DUPLICATE KEY UPDATE `Nick`=VALUES(`Nick`), `Punkty`=VALUES(`Punkty`), `Rank_ID`=VALUES(`Rank_ID`), `Postep`=VALUES(`Postep`);", authid, nick[client], iPunkty[client], iRank[client], Postep[client]);
986
987 SQL_TQuery(sql, ZapiszDane_Handler, zapytanie, client);
988 }
989}
990
991public void ZapiszDane_Handler(Handle owner, Handle query, const char[] error, any client)
992{
993 if (query == INVALID_HANDLE)
994 {
995 LogError("[UWAGA UWAGA RANGI NAPOTKAÅY PROBLEM] Save error: %s", error);
996 return;
997 }
998}
999public int WczytajDB(int client)
1000{
1001 if (!IsValidClient(client))
1002 return;
1003
1004 if (!sql_baza)
1005 LogError("Houston, we have a problem. Downloading from a database doesn't work");
1006 else
1007 {
1008 char zapytanie[1024];
1009
1010 char authid[64];
1011 GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid));
1012 Format(zapytanie, sizeof(zapytanie), "SELECT `Punkty`, `Rank_ID` FROM `Rangi` WHERE `sid` = '%s';", authid);
1013
1014 SQL_TQuery(sql, Wczytaj, zapytanie, client);
1015 }
1016}
1017public void Wczytaj(Handle owner, Handle query, const char[] error, any client)
1018{
1019 if (query == INVALID_HANDLE)
1020 {
1021 LogError("Load error: %s", error);
1022 return;
1023 }
1024 if (SQL_GetRowCount(query) > 0)
1025 {
1026 while (SQL_MoreRows(query))
1027 {
1028 while (SQL_FetchRow(query))
1029 {
1030 iPunkty[client] = SQL_FetchInt(query, 0);
1031 iRank[client] = SQL_FetchInt(query, 1);
1032 }
1033 }
1034 }
1035 else
1036 {
1037 iPunkty[client] = 0;
1038 iRank[client] = 0;
1039 }
1040}
1041
1042stock bool:IsValidClient(client, bool:alive = false)
1043{
1044 if (client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && (alive == false || IsPlayerAlive(client)))
1045 {
1046 return true;
1047 }
1048
1049 return false;
1050}