· 7 years ago · Feb 21, 2019, 04:12 PM
1#pragma semicolon 1
2
3#define DEBUG
4
5#define PLUGIN_AUTHOR "Eylon.A (AuToPrO)"
6#define PLUGIN_VERSION "1.00"
7#define PREFIX " \x05[Gamers-IL]\x01"
8#define MENUPREFIX "[Gamers-IL]"
9
10#define ForceMinCredits 1
11#define ForceMaxCredits 5
12
13#define GangPrice 10000
14#define FreeSlots 3
15
16#include <sourcemod>
17#include <sdktools>
18#include <cstrike>
19#include <sdkhooks>
20#include <smlib>
21#include <geoip>
22#include <storestock>
23
24/*TODO:
25* [x] Player Skins
26* [x] Nade Skins
27* [x] Trails
28* [x] Name colors
29* [x] Chat colors
30* [x] Chat tags
31* [x] Case opening
32* [x] Game achievements
33* [x] Daily Spin
34* [x] Store VIP
35* [x] Chat games
36* [x] Store Chat Reveralls
37* [x] Coin flip
38* [x] Jackpot
39* [x] Gamble
40* [x] Store logs
41*/
42
43char defaultArms[][] = {
44 "models/weapons/t_arms.mdl",
45 "models/weapons/ct_arms.mdl"
46};
47
48Database DB = null;
49
50bool playerload[MAXPLAYERS + 1] = false;
51int credits[MAXPLAYERS + 1];
52
53// players_items[client][itemnum][0] - itemid
54// players_items[client][itemnum][1] - itemcount
55// players_items[client][itemnum][2] - equip
56int pmaxitems[MAXPLAYERS + 1] = 0;
57int players_items[MAXPLAYERS + 1][256][3];
58
59char items[256][9][256];
60int itemscount = 0;
61
62char ach[50][8][256];
63int achcount = 0;
64
65int timecode = 0, killcode = 0, headkillcode = 0, knifekillcode = 0, buycode = 0, sellcode = 0, spinnercode = 0, gamblecode = 0, gamecode = 0;
66
67int adminscount = 0;
68char storeadmin[32][2][32];
69
70char playeraction[MAXPLAYERS + 1][2][32];
71
72bool playervip[MAXPLAYERS + 1] = false;
73int endtime[MAXPLAYERS + 1] = 0;
74int vipgiftcredits[MAXPLAYERS + 1] = 0;
75
76char sPlayerTrail[MAXPLAYERS + 1][256], cPlayerTrail[MAXPLAYERS + 1][256];
77Handle hPlayerTrail[MAXPLAYERS + 1] = INVALID_HANDLE;
78
79int jackpot[MAXPLAYERS + 1] = -1;
80int jackpotc = 0;
81
82int lastdaily[MAXPLAYERS + 1] = 0, dailyplayerspot[MAXPLAYERS + 1] = 0;
83Handle dailydisplay[MAXPLAYERS + 1] = INVALID_HANDLE;
84
85Handle timeupdate[MAXPLAYERS + 1] = INVALID_HANDLE;
86int timeunixupdate[MAXPLAYERS + 1] = 0;
87
88int cfplayerspot[MAXPLAYERS + 1] = 0, cfcoinflipcount[MAXPLAYERS + 1] = 0, cfplayerend[MAXPLAYERS + 1];
89Handle cfplayerdisplay[MAXPLAYERS + 1] = INVALID_HANDLE;
90bool cfplayerstatus[MAXPLAYERS + 1] = false;
91
92char sendgiftitemid[MAXPLAYERS + 1][256];
93
94bool mirrorstatus[MAXPLAYERS + 1] = false;
95
96bool isbounty[MAXPLAYERS + 1] = false;
97int bountyowner[MAXPLAYERS + 1] = -1, bountycredits[MAXPLAYERS + 1];
98Handle bountytime[MAXPLAYERS + 1][2];
99
100char groups[256][6][32];
101int groupscount = 0;
102int groupitemscount[256] = 0;
103char groupitems[256][32][3][32];
104int groupuserscount[256] = 0;
105char groupusers[256][64][2][32];
106
107int groupid[MAXPLAYERS + 1];
108bool Bganginvite[256] = false;
109Handle invitetimer[256] = INVALID_HANDLE;
110int Iganginvite[MAXPLAYERS + 1] = -1;
111
112char Sgangshop[][][] =
113{
114 { "MemberSlot", "2500", "Member Slot", "Unlimited", "ITEMDRAW_IGNORE" },
115 { "BountySys", "5000", "Bounty System", "1", "ITEMDRAW_DEFAULT" },
116 { "CreditBoost", "1500", "Credits Boost", "5", "ITEMDRAW_IGNORE" }
117};
118
119char DailySounds[][] =
120{
121 "gamers/daily/daily_sound.mp3",
122 "gamers/daily/daily_select_sound.mp3"
123};
124
125/*----Game-Val----*/
126
127char GamesList[][] = {
128 "ChatGame_None",
129 "Math Question",
130 "Translate",
131 "Missing Letter",
132 "Max Chat Games"
133};
134
135enum( += 1)
136{
137 ChatGame_Off = 0,
138 ChatGame_Math,
139 ChatGame_Translate,
140 ChatGame_MissingLetter,
141 MAX_CHAT_GAMES
142};
143
144char caseitems[][][] = {
145 { "V.I.P Case", "10000", "vip", "vip" },
146 { "Chat Stuff Case", "7000", "normal", "cstuff" },
147 { "Player Skins Case", "5000", "normal", "pskins" },
148 { "Nade Skins Case", "1000", "normal", "nskins" },
149 { "Trails Case", "500", "normal", "trails" }
150};
151
152int ChatGameType;
153Handle StopGame = INVALID_HANDLE;
154int gamecredits;
155int mathquest = -1;
156char translateans[3][50];
157char missingletterans[2][50];
158char wordsfile[64];
159int wordsfilelinecount = 0;
160
161/*----------------*/
162
163public Plugin myinfo =
164{
165 name = "Gamers-IL Store",
166 author = PLUGIN_AUTHOR,
167 description = "Store System",
168 version = PLUGIN_VERSION,
169 url = "https://forums.alliedmods.net/member.php?u=273439"
170};
171
172public void OnPluginStart()
173{
174 Store_DBConnect();
175
176 RegConsoleCmd("sm_gamble", cmd_gamble);
177 RegConsoleCmd("sm_jackpot", cmd_jackpot);
178 RegConsoleCmd("sm_coinflip", cmd_coinflip);
179 RegConsoleCmd("sm_daily", cmd_daily);
180 RegConsoleCmd("sm_ach", cmd_ach);
181 RegConsoleCmd("sm_case", cmd_case);
182 RegConsoleCmd("sm_mirror", cmd_mirror);
183 //RegConsoleCmd("sm_gang", cmd_gang);
184
185 RegConsoleCmd("sm_items", cmd_items);
186
187 RegConsoleCmd("sm_store", cmd_store);
188 RegConsoleCmd("sm_credits", cmd_credits);
189 RegConsoleCmd("sm_vip", cmd_vip);
190 //RegConsoleCmd("sm_game", cmd_test);
191
192 RegConsoleCmd("sm_givecredits", cmd_givecredits);
193 RegConsoleCmd("sm_gift", cmd_gift);
194
195 HookEvent("player_spawn", Store_PlayerSpawn);
196 HookEvent("player_death", Store_PlayerDeath);
197 HookEvent("round_end", Store_RoundEnd);
198
199 AddCommandListener(Store_PlayerSay, "say");
200 AddCommandListener(Store_PlayerSay, "say_team");
201
202 ChatGameType = ChatGame_Off;
203
204 BuildPath(Path_SM, wordsfile, sizeof(wordsfile), "data/gamet.ini");
205 wordsfilelinecount = GetFileMaxLines(wordsfile);
206
207 CreateTimer(300.0, ForceCredits, INVALID_HANDLE, TIMER_REPEAT);
208 CreateTimer(600.0, ChatQuestGenerate, INVALID_HANDLE, TIMER_REPEAT);
209 CreateTimer(180.0, UpdateGroupData, INVALID_HANDLE, TIMER_REPEAT);
210 //CreateTimer(300.0, ChatMessages, INVALID_HANDLE);
211 //RegConsoleCmd("sm_testb", cmd_testb);
212}
213
214/*public Action cmd_testb(int client, int args)
215{
216 int GroupArrayID = ArrayIDFromGroupID(groupid[client]);
217
218 LoadGroupPlayerCount(groupid[client], GroupArrayID);
219 LoadGroupPlayerList(groupid[client], GroupArrayID);
220
221 return Plugin_Handled;
222}*/
223
224public Action cmd_items(int client, int args)
225{
226 if (playerload[client])
227 {
228 char[] sAuthID64 = new char[32];
229 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
230 char name[32];
231 if (IsStoreAdmin(sAuthID64, name, sizeof(name)))
232 {
233 PrintToConsole(client, "-----------------------");
234 for (int i = 0; i < itemscount; i++)
235 {
236 PrintToConsole(client, "-----------------------");
237 PrintToConsole(client, "id - %s", items[i][0]);
238 PrintToConsole(client, "name - %s", items[i][1]);
239 PrintToConsole(client, "price - %s", items[i][2]);
240 PrintToConsole(client, "type - %s", items[i][3]);
241 PrintToConsole(client, "team - %s", items[i][4]);
242 PrintToConsole(client, "vip - %s", items[i][5]);
243 PrintToConsole(client, "status - %s", items[i][6]);
244 }
245 PrintToConsole(client, "-----------------------");
246 } else
247 PrintToChat(client, "%s You are not store admin!", PREFIX);
248 } else
249 PrintToChat(client, "%s You are not login to store system.", PREFIX);
250
251 return Plugin_Handled;
252}
253
254public Action cmd_mirror(int client, int args)
255{
256 if (playerload[client])
257 {
258 if (IsPlayerAlive(client))
259 {
260 if (mirrorstatus[client])
261 {
262 SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", -1);
263 SetEntProp(client, Prop_Send, "m_iObserverMode", 0);
264 SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 1);
265 SetEntProp(client, Prop_Send, "m_iFOV", 90);
266 char valor[6];
267 GetConVarString(FindConVar("mp_forcecamera"), valor, 6);
268 SendConVarValue(client, FindConVar("mp_forcecamera"), valor);
269 PrintToChat(client, "%s You disabled mirror mod", PREFIX);
270 } else
271 {
272 SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", 0);
273 SetEntProp(client, Prop_Send, "m_iObserverMode", 1);
274 SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 0);
275 SetEntProp(client, Prop_Send, "m_iFOV", 120);
276 SendConVarValue(client, FindConVar("mp_forcecamera"), "1");
277 PrintToChat(client, "%s You enabled mirror mod", PREFIX);
278 }
279 mirrorstatus[client] = !mirrorstatus[client];
280 } else
281 PrintToChat(client, "This command resserved for alive players");
282 } else
283 PrintToChat(client, "%s You are not login to store system.", PREFIX);
284 return Plugin_Handled;
285}
286
287/* public Action cmd_test(int client, int args)
288{
289 ChatGameType = GetRandomInt(ChatGame_Off + 1, MAX_CHAT_GAMES - 1);
290 if (args == 1)
291 {
292 char sarg[32];
293 GetCmdArg(1, sarg, sizeof(sarg));
294 ChatGameType = StringToInt(sarg);
295 }
296 PrintToChatAll("%s %s start.", PREFIX, GamesList[ChatGameType]);
297 gamecredits = GetRandomInt(1, 20);
298 float gametime = GetRandomFloat(10.0, 20.0);
299 if (ChatGameType == ChatGame_Math)
300 {
301 int quest = GetRandomInt(1, 3);
302 int x = GetRandomInt(1, 999);
303 int b = GetRandomInt(1, 999);
304 if (quest == 1)
305 mathquest = x + b;
306 if (quest == 2)
307 mathquest = x - b;
308 if (quest == 3)
309 mathquest = x * b;
310
311 //for (int i = 1; i <= 5; i++)
312 PrintToChatAll("%s %d %s %d = ? (%d credits)", PREFIX, x, quest == 1 ? "+" : quest == 2 ? "-" : "*", b, gamecredits);
313 }
314 if (ChatGameType == ChatGame_Translate)
315 StartTranslateGame();
316 if (ChatGameType == ChatGame_MissingLetter)
317 StartMissingLetter();
318 StopGame = CreateTimer(gametime, EndGame, INVALID_HANDLE);
319} */
320
321public Action PlayTimeUpdate(Handle Timer, any client)
322{
323 float sendtime = (GetTime() - timeunixupdate[client]) / 3600.0;
324 UpdateAch(client, sendtime, timecode);
325 timeunixupdate[client] = GetTime();
326}
327
328public Action ChatMessages(Handle Timer)
329{
330 int chat = GetRandomInt(1, 3);
331 if (chat == 1)
332 PrintToChatAll("%s Buy VIP - !vip / csgo.gamers-israel.co.il/store", PREFIX);
333 else if (chat == 2)
334 PrintToChatAll("%s Try our new free daily spin, Use the command /daily.", PREFIX);
335 else
336 PrintToChatAll("%s Try our new achievements system, Use the command /ach.", PREFIX);
337 //Send Random Time For The Next Message
338 float nextmessage = GetRandomFloat(200.0, 600.0);
339 CreateTimer(nextmessage, ChatMessages, INVALID_HANDLE);
340}
341
342public Action Store_PlayerSay(int client, const char[] command, int args)
343{
344 if (ChatGameType == ChatGame_MissingLetter)
345 {
346 char arg1[50];
347 GetCmdArg(1, arg1, sizeof(arg1));
348 if (StrEqual(arg1, missingletterans[1]))
349 {
350 ChatGameType = ChatGame_Off;
351 KillTimer(StopGame);
352 PrintToChatAll("%s %N won the missingletter game (%d credits)", PREFIX, client, gamecredits);
353 UpdatePlayer(client, credits[client] + gamecredits);
354
355 UpdateAch(client, 1.0, gamecode);
356 }
357 }
358 if (ChatGameType == ChatGame_Translate)
359 {
360 char arg1[50];
361 GetCmdArg(1, arg1, sizeof(arg1));
362 if (StrEqual(arg1, translateans[2]) || StrEqual(arg1, translateans[1]))
363 {
364 ChatGameType = ChatGame_Off;
365 KillTimer(StopGame);
366 PrintToChatAll("%s %N won the translate game (%d credits)", PREFIX, client, gamecredits);
367 UpdatePlayer(client, credits[client] + gamecredits);
368
369 UpdateAch(client, 1.0, gamecode);
370 }
371 }
372 if (ChatGameType == ChatGame_Math)
373 {
374 char arg1[32];
375 GetCmdArg(1, arg1, sizeof(arg1));
376 int number = StringToInt(arg1);
377 if (number == mathquest)
378 {
379 ChatGameType = ChatGame_Off;
380 KillTimer(StopGame);
381 PrintToChatAll("%s %N won the math question (%d credits)", PREFIX, client, gamecredits);
382 UpdatePlayer(client, credits[client] + gamecredits);
383
384 UpdateAch(client, 1.0, gamecode);
385 }
386 }
387}
388
389public Action cmd_daily(int client, int args)
390{
391 if (playerload[client])
392 {
393 int dealytime = GetTime() - lastdaily[client];
394 if (dealytime >= 86400)
395 {
396 //Update LastDaily
397 char[] sAuthID = new char[32];
398 GetClientAuthId(client, AuthId_SteamID64, sAuthID, 32);
399
400 char[] sQuery = new char[256];
401 FormatEx(sQuery, 256, "UPDATE `storedaily` SET `lastdaily` = '%d' WHERE `steamid` = '%s';", GetTime(), sAuthID);
402
403 DB.Query(SQL_UpdatePlayer, sQuery);
404
405 lastdaily[client] = GetTime();
406
407 //DispalyDaily
408 dailyplayerspot[client] = 0;
409 dailydisplay[client] = CreateTimer(0.15, dailydisplaycb, client);
410
411 } else
412 PrintToChat(client, "%s You need to wait %d hours %d min for the next daily spin.", PREFIX, (86400 - dealytime) / 3600, (86400 - dealytime) % 3600 / 60);
413 } else
414 PrintToChat(client, "%s You are not login to store system.", PREFIX);
415
416 return Plugin_Handled;
417}
418
419public Action dailydisplaycb(Handle Timer, any client)
420{
421 dailyplayerspot[client]++;
422
423 char command[128];
424 if (dailyplayerspot[client] <= 8)
425 {
426 ClientCommand(client, "play *%s", DailySounds[0]);
427 Format(command, sizeof(command), "r_screenoverlay \"gamers/daily/daily_%d.vmt\"", dailyplayerspot[client]);
428 dailydisplay[client] = CreateTimer((0.15 + dailyplayerspot[client] / 10.5), dailydisplaycb, client);
429 }
430 else
431 {
432 int realspot = dailyplayerspot[client] % 8;
433 if (realspot == 0)
434 realspot = 8;
435
436 if ((realspot % 2 == 0 && GetRandomInt(1, 100) <= dailyplayerspot[client] / 10.0) || (realspot % 2 != 0 && GetRandomInt(1, 100) <= dailyplayerspot[client] * 1.5))
437 {
438 ClientCommand(client, "play *%s", DailySounds[1]);
439 Format(command, sizeof(command), "r_screenoverlay \"gamers/daily/daily_select_%d.vmt\"", realspot);
440 dailydisplay[client] = CreateTimer(4.0, removedailyview, client);
441
442 if (realspot % 2 != 0)
443 {
444 int rgive = GetRandomInt(1, 250);
445 UpdatePlayer(client, credits[client] + rgive);
446 PrintToChat(client, "%s You got %d credits from the daily spin", PREFIX, rgive);
447 char winlog[128];
448 Format(winlog, sizeof(winlog), "\x06won\x01 %d credits from the daily spin", rgive);
449 SendLog(client, winlog);
450 } else
451 {
452 int sumall = 0;
453 int vitems[256][2];
454 int maxvitems = 0;
455 if (realspot == 2)
456 {
457 for (int i = 0; i < itemscount; i++)
458 {
459 if (StrEqual(items[i][3], "playerskin") && StringToInt(items[i][5]) == 0)
460 {
461 vitems[maxvitems][0] = i;
462 vitems[maxvitems][1] = StringToInt(items[i][2]);
463 maxvitems++;
464 sumall += StringToInt(items[i][2]);
465 }
466 }
467 }
468 else if (realspot == 4)
469 {
470 for (int i = 0; i < itemscount; i++)
471 {
472 if (StrEqual(items[i][3], "trail") && StringToInt(items[i][5]) == 0)
473 {
474 vitems[maxvitems][0] = i;
475 vitems[maxvitems][1] = StringToInt(items[i][2]);
476 maxvitems++;
477 sumall += StringToInt(items[i][2]);
478 }
479 }
480 } else if (realspot == 6)
481 {
482 for (int i = 0; i < itemscount; i++)
483 {
484 if ((StrEqual(items[i][3], "grenadeskin") || StrEqual(items[i][3], "smokeskin") || StrEqual(items[i][3], "flashskin")) && StringToInt(items[i][5]) == 0)
485 {
486 vitems[maxvitems][0] = i;
487 vitems[maxvitems][1] = StringToInt(items[i][2]);
488 maxvitems++;
489 sumall += StringToInt(items[i][2]);
490 }
491 }
492 }
493 else if (realspot == 8)
494 {
495 for (int i = 0; i < itemscount; i++)
496 {
497 if ((StrEqual(items[i][3], "namecolor") || StrEqual(items[i][3], "chattag") || StrEqual(items[i][3], "chatcolor") || StrEqual(items[i][3], "chattagcolor")))
498 {
499 vitems[maxvitems][0] = i;
500 vitems[maxvitems][1] = StringToInt(items[i][2]);
501 maxvitems++;
502 sumall += StringToInt(items[i][2]);
503 }
504 }
505 }
506
507 int breaker = 0;
508 int parsents[100] = 0;
509 for (int i = 0; i < maxvitems - 1; i++)
510 {
511 if (breaker >= 99)break;
512
513 int chance = 100 - (vitems[i][1] * 100 / sumall);
514 for (int j = 1; j <= chance; j++)
515 {
516 parsents[breaker] = vitems[i][0];
517 breaker++;
518 }
519 }
520
521 int jumpwon = parsents[GetRandomInt(0, breaker - 1)];
522
523 //5000
524 //150 - 3%
525 //2500 - 50%
526 //500 - 10%
527 //1850 - 37%
528
529 int count = 1;
530 char[] sAuthID64 = new char[32];
531 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
532 char id[32];
533 Format(id, sizeof(id), "%s|%s", items[jumpwon][0], sAuthID64);
534
535 char[] sQuery = new char[512];
536 FormatEx(sQuery, 512, "INSERT INTO `players_items` (`id`, `itemid`, `steamid`, `itemcount`) VALUES ('%s', '%d', '%s', '%d') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` + %d;", id, StringToInt(items[jumpwon][0]), sAuthID64, count, count);
537 DB.Query(SQL_WINItem, sQuery, GetClientSerial(client), DBPrio_High);
538
539 PrintToChat(client, "%s You got %s [%s] from the daily spin", PREFIX, items[jumpwon][1], items[jumpwon][3]);
540
541 char winlog[128];
542 Format(winlog, sizeof(winlog), "won %s [%s] in daily spin", items[jumpwon][1], items[jumpwon][3]);
543 SendLog(client, winlog);
544 }
545 }
546 else
547 {
548 ClientCommand(client, "play *%s", DailySounds[0]);
549 Format(command, sizeof(command), "r_screenoverlay \"gamers/daily/daily_%d.vmt\"", realspot);
550 dailydisplay[client] = CreateTimer((0.15 + dailyplayerspot[client] / 10.5), dailydisplaycb, client);
551 }
552 }
553
554 ClientCommand(client, command);
555}
556
557public void SQL_WINItem(Database db, DBResultSet results, const char[] error, any data)
558{
559 int client = GetClientFromSerial(data);
560 if (results == null)
561 {
562
563 if (client == 0)
564 {
565 LogError("Store error! Failed to insert a disconnected player's data to the table. Reason: %s", error);
566 }
567
568 else
569 {
570 LogError("Store error! Failed to insert \"%N\"'s data to the table. Reason: %s", client, error);
571 }
572
573 return;
574 }
575 LoadPlayerItems(client);
576}
577
578public Action removedailyview(Handle Timer, any client)
579{
580 ClientCommand(client, "r_screenoverlay \"\"");
581
582 dailydisplay[client] = INVALID_HANDLE;
583
584 UpdateAch(client, 1.0, spinnercode);
585}
586
587public Action cmd_jackpot(int client, int args)
588{
589 if (playerload[client])
590 {
591 if (args == 1)
592 {
593 char sCredits[32];
594 GetCmdArg(1, sCredits, sizeof(sCredits));
595 int jCredits = StringToInt(sCredits);
596 if (jCredits)
597 {
598 if (jCredits >= 15)
599 {
600 if (jCredits <= 250000)
601 {
602 if (jackpot[client] == -1)
603 {
604 if (jCredits <= credits[client])
605 {
606 UpdatePlayer(client, credits[client] - jCredits);
607
608 jackpot[client] = jCredits;
609 jackpotc += jCredits;
610
611 PrintToChatAll("%s %N has spend \x0C%d\x01 credits (%.2f%s)", PREFIX, client, jCredits, (jackpot[client] * 100.0 / jackpotc), "%");
612 } else
613 PrintToChat(client, "%s You do not have %d credits.", PREFIX, jCredits);
614 } else
615 PrintToChat(client, "%s You already in jackpot.", PREFIX);
616 } else
617 PrintToChat(client, "%s You can`t deposit more than 250000 credits.", PREFIX);
618 } else
619 PrintToChat(client, "%s You can jackpot only 15+ credits.", PREFIX);
620 } else
621 PrintToChat(client, "%s You can jackpot only a positve number of credits.", PREFIX);
622 } else
623 {
624 if (jackpot[client] == -1)
625 PrintToChat(client, "%s Usage: sm_jackpot <credits>", PREFIX);
626 else
627 PrintToChat(client, "%s Jackpot \x0C%d\x01 credits (%.2f%s)", PREFIX, jackpotc, (jackpot[client] * 100.0 / jackpotc), "%");
628 }
629 } else
630 PrintToChat(client, "%s You are not login to store system.", PREFIX);
631
632 return Plugin_Handled;
633}
634
635public Action cmd_coinflip(int client, int args)
636{
637 if (playerload[client])
638 {
639 if (args == 2)
640 {
641 char sCredits[32];
642 GetCmdArg(1, sCredits, sizeof(sCredits));
643 char sTeam[32];
644 GetCmdArg(2, sTeam, sizeof(sTeam));
645 int gCredits = StringToInt(sCredits);
646 if (StrEqual(sTeam, "g") || StrEqual(sTeam, "i"))
647 {
648 if (gCredits)
649 {
650 if (gCredits >= 25)
651 {
652 if (gCredits <= credits[client])
653 {
654 int wins = GetRandomInt(1, 100);
655 if (wins <= 25)
656 {
657 if (StrEqual(sTeam, "g"))cfplayerend[client] = 9;
658 if (StrEqual(sTeam, "i"))cfplayerend[client] = 1;
659
660 cfplayerstatus[client] = true;
661 } else
662 {
663 if (StrEqual(sTeam, "g"))cfplayerend[client] = 1;
664 if (StrEqual(sTeam, "i"))cfplayerend[client] = 9;
665
666 cfplayerstatus[client] = false;
667 }
668 cfcoinflipcount[client] = gCredits;
669 cfplayerspot[client] = 0;
670 cfplayerdisplay[client] = CreateTimer(0.1, coinflipdisplay, client);
671 } else
672 PrintToChat(client, "%s You do not have %d credits.", PREFIX, gCredits);
673 } else
674 PrintToChat(client, "%s You can coinflip only 25+ credits.", PREFIX);
675 } else
676 PrintToChat(client, "%s You can coinflip only a positve number of credits.", PREFIX);
677 } else
678 PrintToChat(client, "%s Usage: sm_coinflip <credits> <g/i>", PREFIX);
679 } else
680 PrintToChat(client, "%s Usage: sm_coinflip <credits> <g/i>", PREFIX);
681 } else
682 PrintToChat(client, "%s You are not login to store system.", PREFIX);
683
684 return Plugin_Handled;
685}
686
687public Action coinflipdisplay(Handle Timer, any client)
688{
689 cfplayerspot[client]++;
690 int mod = cfplayerspot[client] % 16;
691 if (mod == 0)
692 mod = 16;
693 char command[128];
694 if (cfplayerspot[client] <= 48)
695 {
696 Format(command, sizeof(command), "r_screenoverlay \"gamers/coinflip/coinflip_%d.vmt\"", mod);
697 cfplayerdisplay[client] = CreateTimer(0.01, coinflipdisplay, client);
698 } else
699 {
700 if (mod == cfplayerend[client])
701 {
702 Format(command, sizeof(command), "r_screenoverlay \"gamers/coinflip/coinflip_%d.vmt\"", mod);
703 cfplayerdisplay[client] = CreateTimer(2.5, coinflipwindisplay, client);
704
705 if (cfplayerstatus[client])
706 {
707 PrintToChat(client, "%s Congratulation, You \x06Won\x01 coinflip (%d credits).", PREFIX, cfcoinflipcount[client]);
708 UpdatePlayer(client, credits[client] + cfcoinflipcount[client]);
709 } else
710 {
711 PrintToChat(client, "%s Damn, You \x07Lose\x01 coinflip (%d credits).", PREFIX, cfcoinflipcount[client]);
712 UpdatePlayer(client, credits[client] - cfcoinflipcount[client]);
713 }
714 }
715 else
716 {
717 Format(command, sizeof(command), "r_screenoverlay \"gamers/coinflip/coinflip_%d.vmt\"", mod);
718 cfplayerdisplay[client] = CreateTimer(0.01, coinflipdisplay, client);
719 }
720 }
721
722 ClientCommand(client, command);
723}
724
725public Action coinflipwindisplay(Handle Timer, any client)
726{
727 ClientCommand(client, "r_screenoverlay \"\"");
728 cfplayerdisplay[client] = INVALID_HANDLE;
729 cfcoinflipcount[client] = 0;
730 cfplayerspot[client] = 0;
731 cfplayerend[client] = 0;
732 cfplayerstatus[client] = false;
733}
734
735public Action cmd_case(int client, int args)
736{
737 if (playerload[client])
738 {
739 if (args == 0)
740 {
741 /*
742 char sCredits[32];
743 GetCmdArg(1, sCredits, sizeof(sCredits));
744 int gCredits = StringToInt(sCredits);
745 if (gCredits)
746 {
747 if (gCredits >= 50)
748 {
749 if (gCredits <= credits[client])
750 {
751 if (GetRandomInt(1, 100) <= 25)
752 {
753 UpdatePlayer(client, credits[client] + gCredits);
754 PrintToChat(client, "%s You gamble %d credits and won.", PREFIX, gCredits);
755
756 UpdateAch(client, 1.0, gamblecode);
757 } else
758 {
759 UpdatePlayer(client, credits[client] - gCredits);
760 PrintToChat(client, "%s You gamble %d credits and lose.", PREFIX, gCredits);
761 }
762 } else
763 PrintToChat(client, "%s You do not have %d credits.", PREFIX, gCredits);
764 } else
765 PrintToChat(client, "%s You can gamble only 50+ credits.", PREFIX);
766 } else
767 PrintToChat(client, "%s You can gamble only a positve number of credits.", PREFIX);*/
768
769
770 Menu casemenu = new Menu(casemenucb);
771
772 char title[32], fitem[128];
773 Format(title, sizeof(title), "Case Opening [%d credits]", credits[client]);
774 casemenu.SetTitle(title);
775
776 int vipstyle = ITEMDRAW_DISABLED;
777 if (playervip[client])
778 vipstyle = ITEMDRAW_DEFAULT;
779
780 for (int i = 0; i < sizeof(caseitems); i++)
781 {
782 Format(fitem, sizeof(fitem), "%s [%d Credits]", caseitems[i][0], StringToInt(caseitems[i][1]));
783 char sended[16];
784 IntToString(i, sended, sizeof(sended));
785 if (StringToInt(caseitems[i][1]) <= credits[client])
786 {
787 if (StrEqual(caseitems[i][2], "vip"))
788 casemenu.AddItem(sended, fitem, vipstyle);
789 else
790 casemenu.AddItem(sended, fitem);
791 } else
792 casemenu.AddItem(sended, fitem, ITEMDRAW_DISABLED);
793 }
794
795 casemenu.ExitButton = true;
796 casemenu.Display(client, MENU_TIME_FOREVER);
797
798 } else
799 PrintToChat(client, "%s Usage: sm_case", PREFIX);
800 } else
801 PrintToChat(client, "%s You are not login to store system.", PREFIX);
802
803 return Plugin_Handled;
804}
805
806/*
807char caseitems[][][] = {
808 { "Player Skins Case", "3500", "normal", "pskins" },
809 { "Nade Skins Case", "1000", "normal", "nskins" },
810 { "Trails Case", "500", "normal", "trails" },
811 { "Chat Stuff Case", "100", "normal", "cstuff" },
812 { "V.I.P Case", "500", "vip", "vip" }
813};
814*/
815
816public int casemenucb(Menu casemenu, MenuAction action, int client, int item)
817{
818 if (action == MenuAction_Select)
819 {
820 char sitem[32];
821 casemenu.GetItem(item, sitem, sizeof(sitem));
822 int iItem = StringToInt(sitem);
823 if (StringToInt(caseitems[iItem][2]) <= credits[client])
824 {
825 UpdatePlayer(client, credits[client] - StringToInt(caseitems[iItem][1]));
826 int sumall = 0;
827 int vitems[256][2];
828 int maxvitems = 0;
829 if (StrEqual(caseitems[iItem][3], "pskins") || StrEqual(caseitems[iItem][3], "vip"))
830 {
831 for (int i = 0; i < itemscount; i++)
832 {
833 if (StrEqual(items[i][3], "playerskin") && StringToInt(items[i][5]) == 0)
834 {
835 vitems[maxvitems][0] = i;
836 vitems[maxvitems][1] = StringToInt(items[i][2]);
837 maxvitems++;
838 sumall += StringToInt(items[i][2]);
839 }
840 }
841 }
842 else if (StrEqual(caseitems[iItem][3], "trails") || StrEqual(caseitems[iItem][3], "vip"))
843 {
844 for (int i = 0; i < itemscount; i++)
845 {
846 if (StrEqual(items[i][3], "trail") && StringToInt(items[i][5]) == 0)
847 {
848 vitems[maxvitems][0] = i;
849 vitems[maxvitems][1] = StringToInt(items[i][2]);
850 maxvitems++;
851 sumall += StringToInt(items[i][2]);
852 }
853 }
854 } else if (StrEqual(caseitems[iItem][3], "nskins") || StrEqual(caseitems[iItem][3], "vip"))
855 {
856 for (int i = 0; i < itemscount; i++)
857 {
858 if ((StrEqual(items[i][3], "grenadeskin") || StrEqual(items[i][3], "smokeskin") || StrEqual(items[i][3], "flashskin")) && StringToInt(items[i][5]) == 0)
859 {
860 vitems[maxvitems][0] = i;
861 vitems[maxvitems][1] = StringToInt(items[i][2]);
862 maxvitems++;
863 sumall += StringToInt(items[i][2]);
864 }
865 }
866 }
867 else if (StrEqual(caseitems[iItem][3], "cstuff") || StrEqual(caseitems[iItem][3], "vip"))
868 {
869 for (int i = 0; i < itemscount; i++)
870 {
871 if ((StrEqual(items[i][3], "namecolor") || StrEqual(items[i][3], "chattag") || StrEqual(items[i][3], "chatcolor") || StrEqual(items[i][3], "chattagcolor")))
872 {
873 vitems[maxvitems][0] = i;
874 vitems[maxvitems][1] = StringToInt(items[i][2]);
875 maxvitems++;
876 sumall += StringToInt(items[i][2]);
877 }
878 }
879 }
880
881 //Added nothing
882 for (int i = 1; i < 50; i++)
883 {
884 vitems[maxvitems][0] = -10;
885 vitems[maxvitems][1] = 1;
886 maxvitems++;
887 sumall += 1;
888 }
889 /*
890 int breaker = 0, tempsumall = 0;
891 int[] parsents = new int[sumall];
892 for (int i = 0; i < maxvitems - 1; i++)
893 {
894 if (breaker >= sumall)
895 {
896 //PrintToConsole(client, "broke! sumall - %d | breaker - %d", breaker, sumall);
897 break;
898 }
899 //int chance = 100 - (vitems[i][1] * 100 / sumall);
900 int chance = vitems[i][1]; //(sumall - tempsumall) - vitems[i][1];
901 tempsumall += chance;
902 //PrintToConsole(client, "maxvitems - %d | chance - %d | tempsumall - %d | sumall - %d | vitems - %d | sumnow - %d", maxvitems, chance, tempsumall, sumall, vitems[i][1], sumall - tempsumall);
903 for (int j = 1; j <= chance; j++)
904 {
905 //PrintToConsole(client, "Added %d - %d | breaker - %d", vitems[i][0], vitems[i][1], breaker);
906 parsents[breaker] = vitems[i][0];
907 breaker++;
908 }
909
910 //PrintToConsole(client, "Next Item");
911
912 }
913 */
914
915 int jumpwon = vitems[GetRandomInt(0, maxvitems - 1)][0];
916
917 if (jumpwon == -10)
918 {
919 PrintToChat(client, "%s You got nothing from the case opening", PREFIX);
920 //Store_PrintToChatAll(client, "got nothing from the case opening");
921 char winlog[128];
922 Format(winlog, sizeof(winlog), "won nothing in case opening");
923 SendLog(client, winlog);
924 }
925 else
926 {
927 //5000
928 //150 - 3%
929 //2500 - 50%
930 //500 - 10%
931 //1850 - 37%
932
933 //1000 - 5500 - 0
934 //2000 - 4500 - 1000
935 //3500 - 3000 - 3000
936 //6500 - 13000
937
938 int count = 1;
939 char[] sAuthID64 = new char[32];
940 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
941 char id[32];
942 Format(id, sizeof(id), "%s|%s", items[jumpwon][0], sAuthID64);
943
944 char[] sQuery = new char[512];
945 FormatEx(sQuery, 512, "INSERT INTO `players_items` (`id`, `itemid`, `steamid`, `itemcount`) VALUES ('%s', '%d', '%s', '%d') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` + %d;", id, StringToInt(items[jumpwon][0]), sAuthID64, count, count);
946 DB.Query(SQL_WINItem, sQuery, GetClientSerial(client), DBPrio_High);
947
948 PrintToChat(client, "%s You got %s [%s] from the case opening", PREFIX, items[jumpwon][1], items[jumpwon][3]);
949
950 char winlog[128];
951 Format(winlog, sizeof(winlog), "\x06Won\x01 %s [%s] in case opening", items[jumpwon][1], items[jumpwon][3]);
952 SendLog(client, winlog);
953 }
954 }
955 }
956}
957
958public Action cmd_gamble(int client, int args)
959{
960 if (playerload[client])
961 {
962 if (args == 1)
963 {
964 char sCredits[32];
965 GetCmdArg(1, sCredits, sizeof(sCredits));
966 int gCredits = StringToInt(sCredits);
967 if (gCredits)
968 {
969 if (gCredits >= 50)
970 {
971 if (gCredits <= credits[client])
972 {
973 if (GetRandomInt(1, 100) <= 25)
974 {
975 UpdatePlayer(client, credits[client] + gCredits);
976 PrintToChat(client, "%s You gamble %d credits and \x06Won", PREFIX, gCredits);
977
978 UpdateAch(client, 1.0, gamblecode);
979 } else
980 {
981 UpdatePlayer(client, credits[client] - gCredits);
982 PrintToChat(client, "%s You gamble %d credits and \x07Lose", PREFIX, gCredits);
983 }
984 } else
985 PrintToChat(client, "%s You do not have %d credits.", PREFIX, gCredits);
986 } else
987 PrintToChat(client, "%s You can gamble only 50+ credits.", PREFIX);
988 } else
989 PrintToChat(client, "%s You can gamble only a positve number of credits.", PREFIX);
990 } else
991 PrintToChat(client, "%s Usage: sm_gamble <credits>", PREFIX);
992 } else
993 PrintToChat(client, "%s You are not login to store system.", PREFIX);
994
995 return Plugin_Handled;
996}
997
998public Action cmd_ach(int client, int args)
999{
1000 if (playerload[client])
1001 {
1002 char[] sAuthID = new char[32];
1003 GetClientAuthId(client, AuthId_SteamID64, sAuthID, 32);
1004 //char url[128];
1005 //Format(url, sizeof(url), "http://csgo.gamers-israel.co.il/redirect.php?url=http://csgo.gamers-israel.co.il/pstats/?steamid=%s", sAuthID);
1006 //ShowMOTDPanel(client, "GamersAchievement", url, MOTDPANEL_TYPE_URL);
1007 PrintToChat(client, "%s http://csgo.gamers-israel.co.il/pstats/?steamid=%s", PREFIX, sAuthID);
1008 } else
1009 PrintToChat(client, "%s You are not login to store system.", PREFIX);
1010
1011 return Plugin_Handled;
1012}
1013
1014public Action cmd_vip(int client, int args)
1015{
1016 if (playerload[client])
1017 {
1018 if (playervip[client])
1019 {
1020 if (endtime[client] > GetTime())
1021 {
1022 int define = endtime[client] - GetTime();
1023 int days = define / 86400;
1024 define = define % 86400;
1025 int hours = define / 3600;
1026 define = define % 3600;
1027 int mins = define / 60;
1028 define = define % 60;
1029 int secs = define;
1030 Menu showvip = new Menu(showvipcb);
1031 char mitem[64], sitem[16];
1032 Format(mitem, sizeof(mitem), "%N Vip Time: ", client);
1033 showvip.SetTitle(mitem);
1034 Format(mitem, sizeof(mitem), "%d - days", days);
1035 showvip.AddItem("-1", mitem, ITEMDRAW_DISABLED);
1036 Format(mitem, sizeof(mitem), "%d - hours", hours);
1037 showvip.AddItem("-1", mitem, ITEMDRAW_DISABLED);
1038 Format(mitem, sizeof(mitem), "%d - minutes", mins);
1039 showvip.AddItem("-1", mitem, ITEMDRAW_DISABLED);
1040 Format(mitem, sizeof(mitem), "%d - seconds", secs);
1041 showvip.AddItem("-1", mitem, ITEMDRAW_DISABLED);
1042 Format(mitem, sizeof(mitem), " You have %d VIP credits left to redeem", vipgiftcredits[client]);
1043 IntToString(vipgiftcredits[client], sitem, sizeof(sitem));
1044 if (vipgiftcredits[client] > 0)
1045 showvip.AddItem(sitem, mitem);
1046 else
1047 showvip.AddItem(sitem, mitem, ITEMDRAW_DISABLED);
1048 showvip.ExitButton = true;
1049 showvip.Display(client, MENU_TIME_FOREVER);
1050 } else
1051 PrintToChat(client, "%s You vip expired in the next map!", PREFIX);
1052 } else
1053 {
1054 ShowMOTDPanel(client, "GamersVIP", "http://csgo.gamers-israel.co.il/redirect.php?url=http://csgo.gamers-israel.co.il/store", MOTDPANEL_TYPE_URL);
1055 PrintToChat(client, "%s You are not a vip.", PREFIX);
1056 }
1057 } else
1058 PrintToChat(client, "%s You are not login to store system.", PREFIX);
1059
1060 return Plugin_Handled;
1061}
1062
1063public int showvipcb(Menu showvip, MenuAction action, int client, int item)
1064{
1065 if (action == MenuAction_Select)
1066 {
1067 char sItem[16];
1068 showvip.GetItem(item, sItem, sizeof(sItem));
1069 int gcredits = StringToInt(sItem);
1070 if (gcredits > 0)
1071 {
1072 char[] sAuthID = new char[32];
1073 GetClientAuthId(client, AuthId_SteamID64, sAuthID, 32);
1074
1075 char[] sQuery = new char[256];
1076 FormatEx(sQuery, 256, "UPDATE `storevip` SET `credits` = '0' WHERE `steamid` = '%s';", sAuthID);
1077
1078 DB.Query(SQL_UpdateVIPCACHE, sQuery);
1079
1080 vipgiftcredits[client] = 0;
1081 UpdatePlayer(client, credits[client] + gcredits);
1082
1083 PrintToChat(client, "%s You redeemed your VIP credits (%d)", PREFIX, gcredits);
1084 }
1085 }
1086}
1087
1088public void SQL_UpdateVIPCACHE(Database db, DBResultSet results, const char[] error, any data)
1089{
1090 if (results == null)
1091 {
1092 LogError("Store (cant update vip cache) SQL query failed. Reason: %s", error);
1093
1094 return;
1095 }
1096}
1097
1098public Action cmd_gift(int client, int args)
1099{
1100 if (playerload[client])
1101 {
1102 if (args == 2)
1103 {
1104 char arg1[32], arg2[32];
1105 GetCmdArg(1, arg1, sizeof(arg1));
1106 GetCmdArg(2, arg2, sizeof(arg2));
1107 int target = FindTarget(client, arg1, true, false);
1108 if (IsValidClient(target) && target != -1)
1109 {
1110 if (playerload[target])
1111 {
1112 int gcredits = StringToInt(arg2);
1113 if (gcredits)
1114 {
1115 if (gcredits >= 50)
1116 {
1117 if (gcredits <= credits[client])
1118 {
1119 if (target != client)
1120 {
1121 UpdatePlayer(client, credits[client] - gcredits);
1122 UpdatePlayer(target, credits[target] + gcredits);
1123
1124 PrintToChat(target, "%s %N sent for you %d credits.", PREFIX, client, gcredits);
1125 PrintToChat(client, "%s You sent %d credits for %N.", PREFIX, gcredits, target);
1126
1127 char spawnlog[128];
1128 Format(spawnlog, sizeof(spawnlog), "sent %d credits for %N", gcredits, target);
1129 SendLog(client, spawnlog);
1130 } else
1131 PrintToChat(client, "%s You cant send credits to yourself.", PREFIX);
1132 } else
1133 PrintToChat(client, "%s You do not have %d credits.", PREFIX, gcredits);
1134 } else
1135 PrintToChat(client, "%s You can only send 50+ credits.", PREFIX);
1136 } else
1137 PrintToChat(client, "%s You can give only a positve number of credits.", PREFIX);
1138 } else
1139 PrintToChat(client, "%s Your target are not login to store system.", PREFIX);
1140 } else
1141 PrintToChat(client, "%s Your target are not found.", PREFIX);
1142 } else
1143 PrintToChat(client, "%s Usage: sm_givecredits <target> <count>", PREFIX);
1144 } else
1145 PrintToChat(client, "%s You are not login to store system.", PREFIX);
1146
1147 return Plugin_Handled;
1148}
1149
1150public Action cmd_givecredits(int client, int args)
1151{
1152 if (playerload[client])
1153 {
1154 char[] sAuthID64 = new char[32];
1155 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
1156 char name[32];
1157 if (IsStoreAdmin(sAuthID64, name, sizeof(name)))
1158 {
1159 if (args == 2)
1160 {
1161 char arg1[32], arg2[8];
1162 GetCmdArg(1, arg1, sizeof(arg1));
1163 GetCmdArg(2, arg2, sizeof(arg2));
1164 int target = FindTarget(client, arg1, true, false);
1165 if (IsValidClient(target) && target != -1)
1166 {
1167 if (playerload[target])
1168 {
1169 int gcredits = StringToInt(arg2);
1170 if (gcredits != 0)
1171 {
1172 UpdatePlayer(target, credits[target] + gcredits);
1173 if (target != client)
1174 PrintToChat(target, "%s %N spawned for you %d credits.", PREFIX, client, gcredits);
1175 PrintToChat(client, "%s You spawned %d credits for %N.", PREFIX, gcredits, target);
1176
1177 char spawnlog[128];
1178 Format(spawnlog, sizeof(spawnlog), "spawned %d credits for %N", gcredits, target);
1179 SendLog(client, spawnlog);
1180 } else
1181 PrintToChat(client, "%s You can give only a negative/positve number of credits.", PREFIX);
1182
1183 } else
1184 PrintToChat(client, "%s Your target are not login to store system.", PREFIX);
1185 } else
1186 PrintToChat(client, "%s Your target are not found.", PREFIX);
1187 } else
1188 PrintToChat(client, "%s usage: sm_givecredits <client> <count>", PREFIX);
1189 } else
1190 PrintToChat(client, "%s You are not store admin!", PREFIX);
1191 } else
1192 PrintToChat(client, "%s You are not login to store system.", PREFIX);
1193
1194 return Plugin_Handled;
1195}
1196
1197public void OnEntityCreated(int entity, const char[] class)
1198{
1199 if (StrContains(class, "_projectile", true) != -1)
1200 SDKHook(entity, SDKHook_SpawnPost, NadeSpawn);
1201}
1202
1203public void NadeSpawn(int entity)
1204{
1205 int client = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
1206 if (playerload[client] && IsValidClient(client))
1207 {
1208 char sClass[64], mdl[265];
1209 GetEdictClassname(entity, sClass, sizeof(sClass));
1210
1211 if (HaveNadeSkin(client, sClass, mdl, sizeof(mdl)))
1212 SetEntityModel(entity, mdl);
1213
1214 //PrintToChat(client, "%s %s", PREFIX, sClass);
1215 }
1216}
1217/*storecatagory.AddItem("grenadeskin", "Grenade Skins");
1218 storecatagory.AddItem("smokeskin", "Smoke Skins");
1219 storecatagory.AddItem("flashskin", "Flash Skins");*/
1220
1221stock bool HaveNadeSkin(int client, const char[] class, char[] mdl, int mdlsize)
1222{
1223 char type[32];
1224 Format(type, sizeof(type), "%s", StrEqual(class, "hegrenade_projectile") ? "grenadeskin" : StrEqual(class, "smokegrenade_projectile") ? "smokeskin" : StrEqual(class, "flashbang_projectile") ? "flashskin" : "none");
1225
1226 if (StrEqual(type, "none"))
1227 return false;
1228
1229 int citemid;
1230 for (int i = 0; i < pmaxitems[client]; i++)
1231 {
1232 citemid = GetSItemIDFromItemID(players_items[client][i][0]);
1233 if (players_items[client][i][2] > 0 && players_items[client][i][1] > 0 && StrEqual(items[citemid][3], type) && validitem(citemid, client))
1234 {
1235 strcopy(mdl, mdlsize, items[citemid][7]);
1236 return true;
1237 }
1238 }
1239
1240 return false;
1241}
1242
1243public Action OnChatMessage(int &client, Handle hRecipients, char[] sName, char[] sMessage)
1244{
1245 char sChatTagColor[32], sChatTag[32], sChatColor[32], sNameColor[32];
1246 if (HaveChatStuff(client, sChatTagColor, sizeof(sChatTagColor), sChatTag, sizeof(sChatTag), sChatColor, sizeof(sChatColor), sNameColor, sizeof(sNameColor)))
1247 {
1248 Format(sName, 128, "%s%s%s%s", StrEqual(sChatTagColor, "team") ? " \x03" : StrEqual(sChatTagColor, "white") ? " \x01" : StrEqual(sChatTagColor, "red") ? " \x02" : StrEqual(sChatTagColor, "green") ? " \x04" : StrEqual(sChatTagColor, "lightgreen") ? " \x05" : StrEqual(sChatTagColor, "darkgreen") ? " \x06" : StrEqual(sChatTagColor, "darkred") ? " \x07" : StrEqual(sChatTagColor, "gray") ? " \x08" : StrEqual(sChatTagColor, "yellow") ? " \x09" : StrEqual(sChatTagColor, "orange") ? "\x10" : StrEqual(sChatTagColor, "lightgray") ? " \x0D" : StrEqual(sChatTagColor, "pink") ? " \x0E" : StrEqual(sChatTagColor, "lightred") ? " \x0F" : StrEqual(sChatTagColor, "darkgray") ? " \x0A" : StrEqual(sChatTagColor, "darkblue") ? " \x0B" : StrEqual(sChatTagColor, "blue") ? " \x0C" : " \x03", sChatTag, StrEqual(sNameColor, "team") ? "\x03" : StrEqual(sNameColor, "white") ? "\x01" : StrEqual(sNameColor, "red") ? "\x02" : StrEqual(sNameColor, "green") ? "\x04" : StrEqual(sNameColor, "lightgreen") ? "\x05" : StrEqual(sNameColor, "darkgreen") ? "\x06" : StrEqual(sNameColor, "darkred") ? "\x07" : StrEqual(sNameColor, "gray") ? "\x08" : StrEqual(sNameColor, "yellow") ? "\x09" : StrEqual(sNameColor, "orange") ? "\x10" : StrEqual(sNameColor, "lightgray") ? "\x0D" : StrEqual(sNameColor, "pink") ? "\x0E" : StrEqual(sNameColor, "lightred") ? "\x0F" : StrEqual(sNameColor, "darkgray") ? "\x0A" : StrEqual(sNameColor, "darkblue") ? "\x0B" : StrEqual(sNameColor, "blue") ? "\x0C" : "\x03", sName);
1249
1250 Format(sMessage, 64, "%s%s", StrEqual(sChatColor, "white") ? "\x01" : StrEqual(sChatColor, "team") ? "\x03" : StrEqual(sChatColor, "red") ? "\x02" : StrEqual(sChatColor, "green") ? "\x04" : StrEqual(sChatColor, "lightgreen") ? "\x05" : StrEqual(sChatColor, "darkgreen") ? "\x06" : StrEqual(sChatColor, "darkred") ? "\x07" : StrEqual(sChatColor, "gray") ? "\x08" : StrEqual(sChatColor, "yellow") ? "\x09" : StrEqual(sChatColor, "orange") ? "\x10" : StrEqual(sChatColor, "lightgray") ? "\x0D" : StrEqual(sChatColor, "pink") ? "\x0E" : StrEqual(sChatColor, "lightred") ? "\x0F" : StrEqual(sChatColor, "darkgray") ? "\x0A" : StrEqual(sChatColor, "darkblue") ? "\x0B" : StrEqual(sChatColor, "blue") ? "\x0C" : "\x01", sMessage);
1251 return Plugin_Changed;
1252 }
1253
1254 return Plugin_Continue;
1255}
1256
1257public bool HaveChatStuff(int client, char[] ctc, int ctcsize, char[] ct, int ctsize, char[] cc, int ccsize, char[] nc, int ncsize)
1258{
1259 int c = 0, citemid;
1260 if (playerload[client] && IsValidClient(client))
1261 {
1262 for (int i = 0; i < pmaxitems[client]; i++)
1263 {
1264 citemid = GetSItemIDFromItemID(players_items[client][i][0]);
1265 if (players_items[client][i][2] > 0 && players_items[client][i][1] > 0 && validitem(citemid, client))
1266 {
1267 if (StrEqual(items[citemid][3], "namecolor"))
1268 {
1269 strcopy(nc, ncsize, items[citemid][7]);
1270 c++;
1271 }
1272 if (StrEqual(items[citemid][3], "chattagcolor"))
1273 {
1274 strcopy(ctc, ctcsize, items[citemid][7]);
1275 c++;
1276 }
1277 if (StrEqual(items[citemid][3], "chattag"))
1278 {
1279 Format(ct, ctsize, "%s ", items[citemid][7]);
1280 c++;
1281 }
1282 if (StrEqual(items[citemid][3], "chatcolor"))
1283 {
1284 strcopy(cc, ccsize, items[citemid][7]);
1285 c++;
1286 }
1287 }
1288 }
1289 }
1290 if (c > 0)
1291 return true;
1292 return false;
1293}
1294
1295public Action Store_RoundEnd(Event event, const char[] name, bool dB)
1296{
1297 if (jackpotc > 0)
1298 {
1299 int array[100] = -1;
1300 int input = 0;
1301 for (int i = 1; i <= MaxClients; i++)
1302 {
1303 if (input >= 99)break;
1304 if (IsValidClient(i))
1305 {
1306 if (jackpot[i] != -1)
1307 {
1308 int chance = jackpot[i] * 100 / jackpotc;
1309 for (int j = 1; j <= chance; j++)
1310 {
1311 array[input] = i;
1312 input++;
1313 }
1314 }
1315 }
1316 }
1317 int winner = -1, checktime = 0;
1318 while (!IsValidClient(winner) && checktime < 30)
1319 {
1320 winner = array[GetRandomInt(0, 99)];
1321 checktime++;
1322 }
1323 if (IsValidClient(winner))
1324 {
1325 UpdatePlayer(winner, credits[winner] + jackpotc);
1326 PrintToChatAll("%s %N has won %d credits (%.2f%s)", PREFIX, winner, jackpotc, (jackpot[winner] * 100.0 / jackpotc), "%");
1327 }
1328
1329 //Reset for next jp
1330 for (int i = 1; i <= MaxClients; i++)
1331 if (IsValidClient(i) && jackpot[i] != -1)
1332 jackpot[i] = -1;
1333
1334 jackpotc = 0;
1335 }
1336}
1337
1338public Action Store_PlayerDeath(Event event, const char[] name, bool dB)
1339{
1340 int client = GetClientOfUserId(event.GetInt("userid"));
1341 if (IsValidClient(client) && playerload[client])
1342 {
1343 if (hPlayerTrail[client] != INVALID_HANDLE)
1344 {
1345 KillTimer(hPlayerTrail[client]);
1346 hPlayerTrail[client] = INVALID_HANDLE;
1347 }
1348 int attacker = GetClientOfUserId(event.GetInt("attacker"));
1349 if (IsValidClient(attacker) && playerload[attacker])
1350 {
1351 if (attacker != client)
1352 {
1353 if (playerload[attacker] && playerload[client])
1354 {
1355 //Ach update
1356 UpdateAch(attacker, 1.0, killcode);
1357 if (event.GetBool("headshot"))
1358 UpdateAch(attacker, 1.0, headkillcode);
1359
1360 char sWeaponName[64];
1361 GetEventString(event, "weapon", sWeaponName, 64);
1362
1363 if (StrContains(sWeaponName, "knife") != -1 || StrContains(sWeaponName, "bayonet") != -1)
1364 UpdateAch(attacker, 1.0, knifekillcode);
1365
1366 //Bounty Check
1367 if (isbounty[client] && bountyowner[client] != attacker)
1368 {
1369 UpdatePlayer(attacker, credits[attacker] + bountycredits[client]);
1370 PrintToChatAll("%s %N achieved the bounty of %N (%N-bowner)", PREFIX, attacker, client, bountyowner[client]);
1371 ResetBounty(client);
1372 }
1373 }
1374 }
1375 }
1376
1377 if (mirrorstatus[client])
1378 {
1379 SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", -1);
1380 SetEntProp(client, Prop_Send, "m_iObserverMode", 0);
1381 SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 1);
1382 SetEntProp(client, Prop_Send, "m_iFOV", 90);
1383 char forcevalue[6];
1384 GetConVarString(FindConVar("mp_forcecamera"), forcevalue, sizeof(forcevalue));
1385 SendConVarValue(client, FindConVar("mp_forcecamera"), forcevalue);
1386 SendConVarValue(client, FindConVar("cl_drawhud"), "1");
1387 mirrorstatus[client] = false;
1388 }
1389 }
1390}
1391
1392public Action Store_PlayerSpawn(Event event, const char[] name, bool dB)
1393{
1394 int client = GetClientOfUserId(event.GetInt("userid"));
1395 char SpawnSkin[256];
1396 if (IsValidClient(client) && playerload[client] && IsPlayerAlive(client))
1397 {
1398 //PlayerSkin Settings
1399 if (HaveEquipSkin(client, GetClientTeam(client), SpawnSkin, sizeof(SpawnSkin)))
1400 {
1401 SetEntityModel(client, SpawnSkin);
1402
1403 //Fixing csgo no gloves bug... disabled beacuse !gloves...
1404 /*int glovesTeam = (GetClientTeam(client) == CS_TEAM_T ? 0 : 1);
1405 SetEntPropString(client, Prop_Send, "m_szArmsModel", "");
1406 SetEntPropString(client, Prop_Send, "m_szArmsModel", defaultArms[glovesTeam]);*/
1407 }
1408
1409 //Trail Settings
1410 if (hPlayerTrail[client] != INVALID_HANDLE)
1411 {
1412 KillTimer(hPlayerTrail[client]);
1413 hPlayerTrail[client] = INVALID_HANDLE;
1414 }
1415 if (HaveEquipTrail(client, sPlayerTrail[client], sizeof(sPlayerTrail[]), cPlayerTrail[client], sizeof(cPlayerTrail[])))
1416 hPlayerTrail[client] = CreateTimer(0.3, SetPlayerTrail, client, TIMER_REPEAT);
1417
1418 //Disable mirror
1419 if (mirrorstatus[client])
1420 {
1421 SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", -1);
1422 SetEntProp(client, Prop_Send, "m_iObserverMode", 0);
1423 SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 1);
1424 SetEntProp(client, Prop_Send, "m_iFOV", 90);
1425 char forcevalue[6];
1426 GetConVarString(FindConVar("mp_forcecamera"), forcevalue, sizeof(forcevalue));
1427 SendConVarValue(client, FindConVar("mp_forcecamera"), forcevalue);
1428 SendConVarValue(client, FindConVar("cl_drawhud"), "1");
1429 mirrorstatus[client] = false;
1430 }
1431 }
1432}
1433
1434public Action SetPlayerTrail(Handle Timer, any client)
1435{
1436 float velocity[3];
1437 GetEntPropVector(client, Prop_Data, "m_vecVelocity", velocity);
1438
1439 bool isMoving = !(velocity[0] == 0.0 && velocity[1] == 0.0 && velocity[2] == 0.0);
1440
1441 if (client != 0 && !isMoving && IsPlayerAlive(client))
1442 CreateTrail(client, sPlayerTrail[client], cPlayerTrail[client]);
1443}
1444
1445stock void CreateTrail(int client, const char[] sprite, const char[] sColor)
1446{
1447 int entityToFollow = GetPlayerWeaponSlot(client, 2);
1448 if (entityToFollow == -1)
1449 entityToFollow = client;
1450
1451 int SetSprite = PrecacheModel(sprite);
1452
1453 int color[4];
1454 if (StrEqual(sColor, "rainbow"))
1455 {
1456 color[0] = GetRandomInt(100, 255);
1457 color[1] = GetRandomInt(100, 255);
1458 color[2] = GetRandomInt(1, 100);
1459 } else {
1460 char split[3][16];
1461 int splitcount = ExplodeString(sColor, ",", split, sizeof(split), sizeof(split[]));
1462 for (int i = 0; i < splitcount; i++)color[i] = StringToInt(split[i]);
1463 }
1464 color[3] = 255;
1465 TE_SetupBeamFollow(entityToFollow, SetSprite, 0, 1.0, 7.0, 7.0, 3, color);
1466 TE_SendToAll();
1467}
1468
1469stock bool HaveEquipTrail(int client, char[] mdl, int mdlsize, char[] color, int colorsize)
1470{
1471 int citemid;
1472 for (int i = 0; i < pmaxitems[client]; i++)
1473 {
1474 citemid = GetSItemIDFromItemID(players_items[client][i][0]);
1475 if (players_items[client][i][2] > 0 && players_items[client][i][1] > 0 && StrEqual(items[citemid][3], "trail") && validitem(citemid, client))
1476 {
1477 strcopy(mdl, mdlsize, items[citemid][7]);
1478 strcopy(color, colorsize, items[citemid][8]);
1479 return true;
1480 }
1481 }
1482
1483 return false;
1484}
1485
1486stock bool HaveEquipSkin(int client, int team, char[] mdl, int mdlsize)
1487{
1488 int citemid;
1489 char Steam[32];
1490 Format(Steam, sizeof(Steam), "%s", team == CS_TEAM_CT ? "counterterrorist" : "terrorist");
1491 for (int i = 0; i < pmaxitems[client]; i++)
1492 {
1493 citemid = GetSItemIDFromItemID(players_items[client][i][0]);
1494 if (players_items[client][i][2] > 0 && players_items[client][i][1] > 0 && StrEqual(items[citemid][4], Steam) && StrEqual(items[citemid][3], "playerskin") && validitem(citemid, client))
1495 {
1496 strcopy(mdl, mdlsize, items[citemid][7]);
1497 return true;
1498 }
1499 }
1500
1501 return false;
1502}
1503
1504/*
1505* `items` - Table
1506* ---------
1507* `id` - Primay Key AUTO_INCREMENT INTEGER 16
1508* `name` - VARCHAR 32
1509* `price` - INTEGER 16
1510* `type` - VARCHAR 16
1511* `team` - VARCHAR 16
1512* `vip` - INTEGER 2 (0 all | 1 only vip)
1513* `status` - INTEGER 2 (0 not available | 1 available)
1514* `mdl` - VARCHAR 256
1515*/
1516
1517public Action cmd_credits(int client, int args)
1518{
1519 if (playerload[client])
1520 PrintToChat(client, "%s You have %d credits.", PREFIX, credits[client]);
1521 else
1522 PrintToChat(client, "%s You are not login to store system.", PREFIX);
1523
1524 return Plugin_Handled;
1525}
1526
1527public Action cmd_store(int client, int args)
1528{
1529 if (playerload[client])
1530 {
1531 char title[32];
1532 Menu store = new Menu(storecb);
1533 Format(title, sizeof(title), "Store [%d credits]", credits[client]);
1534 store.SetTitle(title);
1535 store.AddItem("playerskin", "Player Skins");
1536 store.AddItem("nadeskin", "Nade Skins");
1537 store.AddItem("trails", "Trails");
1538 store.AddItem("chatstuff", "Chat Stuff");
1539 store.AddItem("inv", "Inventory");
1540 //store.AddItem("gang", "Gang Panel");
1541 store.ExitButton = true;
1542 store.Display(client, MENU_TIME_FOREVER);
1543 } else
1544 PrintToChat(client, "%s You are not login to store system.", PREFIX);
1545
1546 return Plugin_Handled;
1547}
1548
1549public int storecb(Menu store, MenuAction action, int client, int item)
1550{
1551 if (action == MenuAction_Select)
1552 {
1553 char sitem[32];
1554 store.GetItem(item, sitem, sizeof(sitem));
1555 Format(playeraction[client][0], sizeof(playeraction[][]), "%s", sitem);
1556 Menu storecatagory = new Menu(storecatagorycb);
1557 storecatagory.ExitBackButton = true;
1558 storecatagory.ExitButton = true;
1559 if (StrEqual(sitem, "playerskin"))
1560 {
1561 storecatagory.SetTitle("Player Skins");
1562 storecatagory.AddItem("terrorist", "T`s Skin");
1563 storecatagory.AddItem("counterterrorist", "CT`s Skin");
1564 storecatagory.Display(client, MENU_TIME_FOREVER);
1565 }
1566 if (StrEqual(sitem, "chatstuff"))
1567 {
1568 storecatagory.SetTitle("Chat Stuff");
1569 storecatagory.AddItem("namecolor", "Name Colors");
1570 storecatagory.AddItem("chattag", "Chat Tags");
1571 storecatagory.AddItem("chatcolor", "Chat Colors");
1572 storecatagory.AddItem("chattagcolor", "Chat Tag Colors");
1573 storecatagory.Display(client, MENU_TIME_FOREVER);
1574 }
1575 if (StrEqual(sitem, "nadeskin"))
1576 {
1577 storecatagory.SetTitle("Nade Skins");
1578 storecatagory.AddItem("grenadeskin", "Grenade Skins");
1579 storecatagory.AddItem("smokeskin", "Smoke Skins");
1580 storecatagory.AddItem("flashskin", "Flash Skins");
1581 storecatagory.Display(client, MENU_TIME_FOREVER);
1582 }
1583 if (StrEqual(sitem, "trails"))
1584 {
1585 Format(playeraction[client][0], sizeof(playeraction[][]), "trail");
1586 Format(playeraction[client][1], sizeof(playeraction[][]), "both");
1587 ShowItems(client, "Trails");
1588 }
1589 if (StrEqual(sitem, "inv"))
1590 {
1591 Menu playerinv = new Menu(playerinvcb);
1592 playerinv.SetTitle("Inventory");
1593 char displayitem[128], senditem[32], itemtype[32];
1594 for (int i = 0; i < pmaxitems[client]; i++)
1595 {
1596 if (players_items[client][i][1] > 0)
1597 {
1598 int SitemID = GetSItemIDFromItemID(players_items[client][i][0]);
1599 if (validitem(SitemID, client))
1600 {
1601 Format(itemtype, sizeof(itemtype), "%s ", StrEqual(items[SitemID][4], "counterterrorist") ? "Ct" : "T");
1602 Format(displayitem, sizeof(displayitem), "%s%s (%s%s)", players_items[client][i][2] == 1 ? "[Equipped] " : "", items[SitemID][1], StrEqual(items[SitemID][4], "both") ? "" : itemtype, items[SitemID][3]);
1603 IntToString(i, senditem, sizeof(senditem));
1604 //PrintToChat(client, "You edit %d, senditem %s, and itemid %d", items[SitemID][1], senditem);
1605 playerinv.AddItem(senditem, displayitem);
1606 }
1607 }
1608 }
1609 if (playerinv.ItemCount == 0)
1610 playerinv.AddItem("-1", "Yo do not have any items.", ITEMDRAW_DISABLED);
1611 playerinv.ExitBackButton = true;
1612 playerinv.ExitButton = true;
1613 playerinv.Display(client, MENU_TIME_FOREVER);
1614 }
1615 if (StrEqual(sitem, "gang"))
1616 {
1617 cmd_gang(client, 0);
1618 }
1619 }
1620}
1621
1622public Action cmd_gang(int client, int args)
1623{
1624 if (playerload[client])
1625 {
1626 Menu gangpanel = new Menu(gangpanelcb);
1627 gangpanel.SetTitle("Gang Panel:");
1628 char displayitem[128];
1629 if (groupid[client] == -1)
1630 {
1631 int gangtype = ITEMDRAW_DISABLED;
1632 if (credits[client] >= GangPrice && groupscount < 256)gangtype = ITEMDRAW_DEFAULT;
1633 Format(displayitem, sizeof(displayitem), "Create Gang [%d credits]", GangPrice);
1634 gangpanel.AddItem("create", displayitem, gangtype);
1635 } else {
1636 int grouparray = ArrayIDFromGroupID(groupid[client]);
1637 if (grouparray != -1)
1638 {
1639 int openslots = GetGroupSpecificItemCount(Sgangshop[0][0], groupid[client]) - StringToInt(groups[grouparray][5]);
1640 //int bountysys = GetGroupSpecificItemCount(Sgangshop[1][0], groupid[client]);
1641 int viewtype = ITEMDRAW_DISABLED;
1642 if (IsGroupOwner(client))viewtype = ITEMDRAW_DEFAULT;
1643 gangpanel.AddItem("shop", "Gang Shop", viewtype);
1644 gangpanel.AddItem("inventory", "Inventory");
1645 if (openslots <= 0 || Bganginvite[grouparray])viewtype = ITEMDRAW_DISABLED;
1646 Format(displayitem, sizeof(displayitem), "Invite [%d slots]", openslots);
1647 gangpanel.AddItem("invite", displayitem, viewtype);
1648 gangpanel.AddItem("dep", "Deposit credits");
1649 /*viewtype = ITEMDRAW_IGNORE;
1650 if (bountysys)viewtype = ITEMDRAW_DEFAULT;
1651 gangpanel.AddItem("bount", "Bounty Player", viewtype);*/
1652
1653 if (IsGroupOwner(client))
1654 {
1655 gangpanel.AddItem("manage", "Manage Players");
1656 gangpanel.AddItem("rename", "Rename Gang", ITEMDRAW_IGNORE);
1657 }
1658 else
1659 gangpanel.AddItem("leave", "Leave Gang");
1660 }
1661 }
1662 gangpanel.AddItem("list", "Gangs List");
1663 gangpanel.ExitBackButton = true;
1664 gangpanel.ExitButton = true;
1665 gangpanel.Display(client, MENU_TIME_FOREVER);
1666 } else
1667 PrintToChat(client, "%s You are not login to store system.", PREFIX);
1668}
1669
1670public int ganginventorycb(Menu ganginventory, MenuAction action, int client, int item)
1671{
1672 if (action == MenuAction_Select)
1673 {
1674 char Sitem[32];
1675 ganginventory.GetItem(item, Sitem, sizeof(Sitem));
1676 int ItemID = StringToInt(Sitem);
1677 if (ItemID == 1) //Bouny
1678 {
1679 Menu bountyplay = new Menu(bountyplaycb);
1680 bountyplay.SetTitle("[Bounty] Choose player:");
1681 char displayitem[128], senditem[32];
1682 for (int i = 1; i <= MAXPLAYERS; i++)
1683 {
1684 if (IsValidClient(i) && playerload[i] && i != client && !isbounty[i])
1685 {
1686 Format(displayitem, sizeof(displayitem), "%N", i);
1687 IntToString(i, senditem, sizeof(senditem));
1688 bountyplay.AddItem(senditem, displayitem);
1689 }
1690 }
1691 if (bountyplay.ItemCount == 0)
1692 bountyplay.AddItem("-1", "You cannot use 'bounty' right now.", ITEMDRAW_DISABLED);
1693
1694 bountyplay.ExitBackButton = true;
1695 bountyplay.ExitButton = true;
1696 bountyplay.Display(client, MENU_TIME_FOREVER);
1697 }
1698 }
1699 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)cmd_gang(client, 0);
1700}
1701
1702public int gangpanelcb(Menu gangpanel, MenuAction action, int client, int item)
1703{
1704 if (action == MenuAction_Select)
1705 {
1706 char Sitem[32];
1707 gangpanel.GetItem(item, Sitem, sizeof(Sitem));
1708
1709 if (StrEqual(Sitem, "inventory"))
1710 {
1711 Menu ganginventory = new Menu(ganginventorycb);
1712 ganginventory.SetTitle("Gang Inventory:");
1713 char SendingItem[32];
1714
1715 int viewtype = ITEMDRAW_DISABLED;
1716 for (int i = 0; i < sizeof(Sgangshop); i++)
1717 {
1718 if (StrEqual(Sgangshop[i][4], "ITEMDRAW_DEFAULT"))
1719 {
1720 int itemcount = GetGroupSpecificItemCount(Sgangshop[i][0], groupid[client]);
1721 //Format(DisplayItem, sizeof(DisplayItem), "%s (%s credits) [%d/%s]", Sgangshop[i][2], Sgangshop[i][1], haveitemcount, Sgangshop[i][3]);
1722 if (itemcount > 0)viewtype = ITEMDRAW_DEFAULT;
1723 IntToString(i, SendingItem, sizeof(SendingItem));
1724 ganginventory.AddItem(SendingItem, Sgangshop[i][2], viewtype);
1725 viewtype = ITEMDRAW_DISABLED;
1726 }
1727 } if (ganginventory.ItemCount == 0)ganginventory.AddItem("-1", "Your gang has no items.", ITEMDRAW_DISABLED);
1728
1729 ganginventory.ExitBackButton = true;
1730 ganginventory.ExitButton = true;
1731 ganginventory.Display(client, MENU_TIME_FOREVER);
1732 }
1733
1734 if (StrEqual(Sitem, "manage"))
1735 {
1736 char[] sAuthID64 = new char[32];
1737 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
1738
1739 int GroupArrayID = ArrayIDFromGroupID(groupid[client]);
1740 if (GroupArrayID != -1)
1741 {
1742 Menu gangmemberlist = new Menu(gangmemberlistcb);
1743 gangmemberlist.SetTitle("Member list:");
1744 char Senditem[32];
1745 for (int i = 0; i < groupuserscount[GroupArrayID]; i++)
1746 {
1747 if (!StrEqual(sAuthID64, groupusers[GroupArrayID][i][0]))
1748 {
1749 IntToString(i, Senditem, sizeof(Senditem));
1750 gangmemberlist.AddItem(Senditem, groupusers[GroupArrayID][i][1]);
1751 }
1752 }
1753 if (gangmemberlist.ItemCount == 0)
1754 gangmemberlist.AddItem("Close", "Close Your gang.");
1755
1756 gangmemberlist.ExitBackButton = true;
1757 gangmemberlist.ExitButton = true;
1758 gangmemberlist.Display(client, MENU_TIME_FOREVER);
1759 }
1760 }
1761
1762 if (StrEqual(Sitem, "leave"))
1763 {
1764 int GroupArrayID = ArrayIDFromGroupID(groupid[client]);
1765 if (GroupArrayID != -1)
1766 {
1767 char title[128];
1768 Menu leavegroupcheck = new Menu(leavegroupcheckcb);
1769 Format(title, sizeof(title), "Leave %s gang?", groups[GroupArrayID][3]);
1770 leavegroupcheck.SetTitle(title);
1771 leavegroupcheck.AddItem("no", "No");
1772 leavegroupcheck.AddItem("leave", "Yes, leave!");
1773 leavegroupcheck.ExitButton = false;
1774 leavegroupcheck.Display(client, MENU_TIME_FOREVER);
1775 }
1776 }
1777 if (StrEqual(Sitem, "invite"))
1778 {
1779 Menu invitetgang = new Menu(invitetgangcb);
1780 invitetgang.SetTitle("Invite Players:");
1781
1782 char drawitem[128], Ssenditem[64];
1783
1784 for (int i = 1; i <= MaxClients; i++)
1785 {
1786 if (IsValidClient(i) && playerload[i])
1787 {
1788 IntToString(i, Ssenditem, sizeof(Ssenditem));
1789 int viewtype = ITEMDRAW_DEFAULT;
1790 if (groupid[i] == -1)
1791 Format(drawitem, sizeof(drawitem), "%N", i);
1792 else
1793 {
1794 int GroupArrayID = ArrayIDFromGroupID(groupid[i]);
1795 Format(drawitem, sizeof(drawitem), "%N (%s`s gang)", i, GroupArrayID == -1 ? "Unknown" : groups[GroupArrayID][3]);
1796 }
1797
1798 if (Iganginvite[i] != -1 || groupid[i] != -1)viewtype = ITEMDRAW_DISABLED;
1799
1800 invitetgang.AddItem(Ssenditem, drawitem, viewtype);
1801 }
1802 }
1803
1804 if (invitetgang.ItemCount == 0)
1805 invitetgang.AddItem("-1", "You cannot invite players right now.", ITEMDRAW_DISABLED);
1806
1807 invitetgang.ExitBackButton = true;
1808 invitetgang.ExitButton = true;
1809 invitetgang.Display(client, MENU_TIME_FOREVER);
1810 }
1811
1812 if (StrEqual(Sitem, "dep"))
1813 {
1814 Menu gangdep = new Menu(gangdepcb);
1815 gangdep.SetTitle("Choose deposite count: ");
1816 char senditem[64], displayitem[128];
1817 for (int i = 1; i < 10; i++)
1818 {
1819 int count = 100 * i;
1820 if (credits[client] >= count)
1821 {
1822 Format(displayitem, sizeof(displayitem), "%d Credits", count);
1823 Format(senditem, sizeof(senditem), "%d", count);
1824 gangdep.AddItem(senditem, displayitem);
1825 }
1826 }
1827 for (int i = 1; i < 10; i++)
1828 {
1829 int count = 1000 * i;
1830 if (credits[client] >= count)
1831 {
1832 Format(displayitem, sizeof(displayitem), "%d Credits", count);
1833 Format(senditem, sizeof(senditem), "%d", count);
1834 gangdep.AddItem(senditem, displayitem);
1835 }
1836 }
1837 if (gangdep.ItemCount == 0)
1838 gangdep.AddItem("-1", "You cannot deposite credits right now.", ITEMDRAW_DISABLED);
1839
1840 gangdep.ExitBackButton = true;
1841 gangdep.ExitButton = true;
1842 gangdep.Display(client, MENU_TIME_FOREVER);
1843 }
1844
1845 if (StrEqual(Sitem, "shop"))
1846 {
1847 if (groupid[client] != -1)
1848 {
1849 if (IsGroupOwner(client))
1850 {
1851 int GroupArrayID = ArrayIDFromGroupID(groupid[client]);
1852 if (GroupArrayID != -1)
1853 {
1854 char DisplayItem[128], SendingItem[64];
1855 int groupcredits = StringToInt(groups[GroupArrayID][4]);
1856
1857 Menu gangshop = new Menu(gangshopcb);
1858 Format(DisplayItem, sizeof(DisplayItem), "Gangs Shop: [%d credits]", groupcredits);
1859 gangshop.SetTitle(DisplayItem);
1860
1861 int viewtype = ITEMDRAW_DISABLED;
1862 for (int i = 0; i < sizeof(Sgangshop); i++)
1863 {
1864 int haveitemcount = GetGroupSpecificItemCount(Sgangshop[i][0], groupid[client]);
1865 int maxitemcount = StringToInt(Sgangshop[i][3]);
1866 if (groupcredits >= StringToInt(Sgangshop[i][1]) && (maxitemcount == 0 || haveitemcount < maxitemcount))viewtype = ITEMDRAW_DEFAULT;
1867 Format(DisplayItem, sizeof(DisplayItem), "%s (%s credits) [%d/%s]", Sgangshop[i][2], Sgangshop[i][1], haveitemcount, Sgangshop[i][3]);
1868 IntToString(i, SendingItem, sizeof(SendingItem));
1869 gangshop.AddItem(SendingItem, DisplayItem, viewtype);
1870 viewtype = ITEMDRAW_DISABLED;
1871 }
1872
1873 gangshop.ExitBackButton = true;
1874 gangshop.ExitButton = true;
1875 gangshop.Display(client, MENU_TIME_FOREVER);
1876 }
1877 } else
1878 PrintToChat(client, "%s This feature resserved for gang leader.", PREFIX);
1879 } else
1880 PrintToChat(client, "%s Invalid group id.", PREFIX);
1881 }
1882
1883 if (StrEqual(Sitem, "create"))
1884 {
1885 char title[128];
1886 Menu groupcreatecheck = new Menu(groupcreatecheckcb);
1887 Format(title, sizeof(title), "Create new gang? (%d credits)", GangPrice);
1888 groupcreatecheck.SetTitle(title);
1889 groupcreatecheck.AddItem("no", "No");
1890 groupcreatecheck.AddItem("create", "Yes, create!");
1891 groupcreatecheck.ExitButton = false;
1892 groupcreatecheck.Display(client, MENU_TIME_FOREVER);
1893 }
1894
1895 if (StrEqual(Sitem, "list"))
1896 {
1897 Menu ganglist = new Menu(ganglistcb);
1898 ganglist.SetTitle("Gangs list:");
1899
1900 for (int i = 0; i < groupscount; i++)
1901 ganglist.AddItem(groups[i][0], groups[i][3]);
1902
1903 if (ganglist.ItemCount == 0)
1904 ganglist.AddItem("-1", "No registered gangs.", ITEMDRAW_DISABLED);
1905
1906 ganglist.ExitBackButton = true;
1907 ganglist.ExitButton = true;
1908 ganglist.Display(client, MENU_TIME_FOREVER);
1909 }
1910
1911 /*if (StrEqual(Sitem, "bount"))
1912 {
1913 Menu bountyplay = new Menu(bountyplaycb);
1914 bountyplay.SetTitle("[Bounty] Choose player:");
1915 char displayitem[128], senditem[32];
1916 for (int i = 1; i <= MAXPLAYERS; i++)
1917 {
1918 if (IsValidClient(i) && playerload[i] && i != client && !isbounty[i])
1919 {
1920 Format(displayitem, sizeof(displayitem), "%N", i);
1921 IntToString(i, senditem, sizeof(senditem));
1922 bountyplay.AddItem(senditem, displayitem);
1923 }
1924 }
1925 if (bountyplay.ItemCount == 0)
1926 bountyplay.AddItem("-1", "You cannot use 'bounty' right now.", ITEMDRAW_DISABLED);
1927
1928 bountyplay.ExitBackButton = true;
1929 bountyplay.ExitButton = true;
1930 bountyplay.Display(client, MENU_TIME_FOREVER);
1931 }*/
1932 }
1933 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)FakeClientCommand(client, "sm_store");
1934}
1935
1936public int groupcreatecheckcb(Menu groupcreatecheck, MenuAction action, int client, int item)
1937{
1938 if (action == MenuAction_Select)
1939 {
1940 char Sitem[32];
1941 groupcreatecheck.GetItem(item, Sitem, sizeof(Sitem));
1942 if (StrEqual(Sitem, "create"))
1943 {
1944 if (groupscount < 256)
1945 {
1946 if (credits[client] >= GangPrice)
1947 {
1948 char[] sAuthID64 = new char[32];
1949 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
1950 char[] sName = new char[MAX_NAME_LENGTH];
1951 GetClientName(client, sName, MAX_NAME_LENGTH);
1952
1953 int iLength = ((strlen(sName) * 2) + 1);
1954 char[] sEscapedName = new char[iLength];
1955 DB.Escape(sName, sEscapedName, iLength);
1956
1957 char[] sQuery = new char[512];
1958 FormatEx(sQuery, 512, "INSERT INTO `groups` (`ownerid`, `ownername`, `name`) VALUES ('%s', '%s', '%s');", sAuthID64, sEscapedName, sEscapedName);
1959 DB.Query(SQL_CreateGroup, sQuery, GetClientSerial(client), DBPrio_High);
1960
1961 char createlog[128];
1962 Format(createlog, sizeof(createlog), "create new gang (%d credits)", GangPrice);
1963 SendLog(client, createlog);
1964
1965 FakeClientCommand(client, "sm_store");
1966 } else
1967 PrintToChat(client, "%s You do not have %d credits.", PREFIX, GangPrice);
1968 } else
1969 PrintToChat(client, "%s Failed to create your gang.", PREFIX);
1970 } else
1971 cmd_gang(client, 0);
1972 }
1973}
1974
1975public int kickmembercheckcb(Menu kickmembercheck, MenuAction action, int client, int item)
1976{
1977 if (action == MenuAction_Select)
1978 {
1979 char Sitem[32];
1980 kickmembercheck.GetItem(item, Sitem, sizeof(Sitem));
1981 if (!StrEqual(Sitem, "no"))
1982 {
1983 int player = StringToInt(Sitem);
1984 int GroupArrayID = ArrayIDFromGroupID(groupid[client]);
1985 if (GroupArrayID != -1)
1986 {
1987 char RemovedAuth[32], RemovedName[32];
1988 strcopy(RemovedAuth, sizeof(RemovedAuth), groupusers[GroupArrayID][player][0]);
1989 strcopy(RemovedName, sizeof(RemovedName), groupusers[GroupArrayID][player][1]);
1990 if (RemoveOfflineGroupMember(client, player, groupid[client], GroupArrayID, 1))
1991 {
1992 PrintToChat(client, "%s You kicked %s from gang.", PREFIX, RemovedName);
1993
1994 for (int i = 1; i <= MaxClients; i++)
1995 {
1996 if (playerload[i] && IsValidClient(i))
1997 {
1998 char[] iAuthID = new char[32];
1999 GetClientAuthId(i, AuthId_SteamID64, iAuthID, 32);
2000 if (StrEqual(RemovedAuth, iAuthID))
2001 {
2002 groupid[i] = -1;
2003 PrintToChat(i, "%s %N kicked you from gang.", PREFIX, client);
2004 }
2005 }
2006 }
2007 } else
2008 PrintToChat(client, "%s Failed to kick %s from gang.", PREFIX, groupusers[GroupArrayID][player][1]);
2009 } else
2010 PrintToChat(client, "%s Invalid gang id.", PREFIX);
2011 }
2012 }
2013}
2014
2015public int gangmanagemembercb(Menu gangmanagemember, MenuAction action, int client, int item)
2016{
2017 if (action == MenuAction_Select)
2018 {
2019 char Sitem[32];
2020 gangmanagemember.GetItem(item, Sitem, sizeof(Sitem));
2021 int player = StringToInt(Sitem);
2022 int GroupArrayID = ArrayIDFromGroupID(groupid[client]);
2023 if (GroupArrayID != -1)
2024 {
2025 char title[64];
2026 Menu kickmembercheck = new Menu(kickmembercheckcb);
2027 Format(title, sizeof(title), "Kick %s from gang:", groupusers[GroupArrayID][player][1]);
2028 kickmembercheck.SetTitle(title);
2029 kickmembercheck.AddItem("no", "No.");
2030 kickmembercheck.AddItem(Sitem, "Yes, kick.");
2031 kickmembercheck.ExitButton = false;
2032 kickmembercheck.Display(client, MENU_TIME_FOREVER);
2033 }
2034 }
2035 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)cmd_gang(client, 0);
2036}
2037
2038public int gangmemberlistcb(Menu gangmemberlist, MenuAction action, int client, int item)
2039{
2040 if (action == MenuAction_Select)
2041 {
2042 char Sitem[32];
2043 gangmemberlist.GetItem(item, Sitem, sizeof(Sitem));
2044 if (StrEqual(Sitem, "Close"))
2045 {
2046 int GroupID = groupid[client];
2047 int GroupArrayID = ArrayIDFromGroupID(GroupID);
2048 if (GroupArrayID != -1)
2049 {
2050 char title[128];
2051 Menu closegroupcheck = new Menu(closegroupcheckcb);
2052 Format(title, sizeof(title), "Close %s gang?", groups[GroupArrayID][3]);
2053 closegroupcheck.SetTitle(title);
2054 closegroupcheck.AddItem("no", "No");
2055 closegroupcheck.AddItem("close", "Yes, close!");
2056 closegroupcheck.ExitButton = false;
2057 closegroupcheck.Display(client, MENU_TIME_FOREVER);
2058 }
2059 } else
2060 {
2061 int player = StringToInt(Sitem);
2062 int GroupArrayID = ArrayIDFromGroupID(groupid[client]);
2063 if (GroupArrayID != -1)
2064 {
2065 char title[64];
2066 Menu gangmanagemember = new Menu(gangmanagemembercb);
2067 Format(title, sizeof(title), "Manage %s:", groupusers[GroupArrayID][player][1]);
2068 gangmanagemember.SetTitle(title);
2069 gangmanagemember.AddItem(Sitem, "Kick from gang.");
2070 gangmanagemember.ExitBackButton = true;
2071 gangmanagemember.ExitButton = true;
2072 gangmanagemember.Display(client, MENU_TIME_FOREVER);
2073 }
2074 }
2075 }
2076 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)cmd_gang(client, 0);
2077}
2078
2079public int closegroupcheckcb(Menu closegroupcheck, MenuAction action, int client, int item)
2080{
2081 if (action == MenuAction_Select)
2082 {
2083 int GroupID = groupid[client];
2084 int GroupArrayID = ArrayIDFromGroupID(GroupID);
2085 if (GroupArrayID != -1)
2086 {
2087 char closelog[128];
2088 Format(closelog, sizeof(closelog), "close %s gang.", groups[GroupArrayID][3]);
2089 SendLog(client, closelog);
2090
2091 RemoveOnlineGroupMember(client, GroupID, GroupArrayID, 1);
2092
2093 char[] sQuery = new char[512];
2094 FormatEx(sQuery, 512, "DELETE FROM `groups` WHERE groupid = '%d';", GroupID);
2095 DB.Query(SQL_CloseGroup, sQuery, 0, DBPrio_High);
2096
2097 PrintToChat(client, "%s Your gang was closed.", PREFIX);
2098 }
2099 }
2100}
2101
2102public void SQL_CloseGroup(Database db, DBResultSet results, const char[] error, any data)
2103{
2104 if (results == null)
2105 {
2106 LogError("Store error! Failed to close group (group unknown). Reason: %s", error);
2107
2108 return;
2109 }
2110
2111 char[] sQuery = new char[512];
2112 FormatEx(sQuery, 256, "SELECT * FROM `groups`;");
2113 DB.Query(SQL_LoadGroups, sQuery, 0, DBPrio_High);
2114}
2115
2116public int leavegroupcheckcb(Menu leavegroupcheck, MenuAction action, int client, int item)
2117{
2118 if (action == MenuAction_Select)
2119 {
2120 char Sitem[32];
2121 leavegroupcheck.GetItem(item, Sitem, sizeof(Sitem));
2122 if (StrEqual(Sitem, "leave"))
2123 {
2124 int GroupArrayID = ArrayIDFromGroupID(groupid[client]);
2125 if (GroupArrayID != -1)
2126 {
2127 if (RemoveOnlineGroupMember(client, groupid[client], GroupArrayID, 1))
2128 PrintToChat(client, "%s You left %s gang.", PREFIX, groups[GroupArrayID][3]);
2129 else
2130 PrintToChat(client, "%s You cannot leave %s gang right now.", PREFIX, groups[GroupArrayID][3]);
2131
2132 FakeClientCommand(client, "sm_store");
2133 }
2134 } else
2135 cmd_gang(client, 0);
2136 }
2137}
2138
2139public int invitetgangcb(Menu invitetgang, MenuAction action, int client, int item)
2140{
2141 if (action == MenuAction_Select)
2142 {
2143 char Sitem[32];
2144 invitetgang.GetItem(item, Sitem, sizeof(Sitem));
2145 int target = StringToInt(Sitem);
2146 if (playerload[client] && IsValidClient(client))
2147 {
2148 if (playerload[target] && IsValidClient(target))
2149 {
2150 if (Iganginvite[target] == -1)
2151 {
2152 int grouparray = ArrayIDFromGroupID(groupid[client]);
2153 if (grouparray != -1)
2154 {
2155 Iganginvite[target] = client;
2156 Bganginvite[grouparray] = true;
2157 char Stitle[128];
2158 Menu ganginvite = new Menu(ganginvitecb);
2159 Format(Stitle, sizeof(Stitle), "%N invite you to %s`s gang", client, groups[ArrayIDFromGroupID(groupid[client])][3]);
2160 ganginvite.SetTitle(Stitle);
2161 ganginvite.AddItem("decline", "Decline.");
2162 ganginvite.AddItem("accept", "Accept.");
2163 ganginvite.ExitBackButton = false;
2164 ganginvite.ExitButton = false;
2165 ganginvite.Display(target, 30);
2166 Handle data = CreateDataPack();
2167 WritePackCell(data, client);
2168 WritePackCell(data, target);
2169 WritePackCell(data, grouparray);
2170 invitetimer[grouparray] = CreateTimer(30.0, clearganginvite, target);
2171
2172 PrintToChat(client, "%s An invitation to the gang was sent to %N.", PREFIX, target);
2173 }
2174 } else
2175 PrintToChat(client, "%s You cannot invite %N right now.", PREFIX, target);
2176 } else
2177 PrintToChat(client, "%s Your target are not loggin to store system.", PREFIX);
2178 } else
2179 PrintToChat(client, "%s You are not loggin to store system.", PREFIX);
2180
2181 cmd_gang(client, 0);
2182 }
2183 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)cmd_gang(client, 0);
2184}
2185
2186public int ganginvitecb(Menu ganginvite, MenuAction action, int client, int item)
2187{
2188 if (action == MenuAction_Select)
2189 {
2190 char Sitem[32];
2191 ganginvite.GetItem(item, Sitem, sizeof(Sitem));
2192 int grouparray = ArrayIDFromGroupID(groupid[Iganginvite[client]]);
2193 if (grouparray != -1)
2194 {
2195 if (StrEqual(Sitem, "accept"))
2196 {
2197 if (IsValidClient(Iganginvite[client]) && playerload[Iganginvite[client]])
2198 {
2199 if (AddGroupMember(Iganginvite[client], client, groupid[Iganginvite[client]], grouparray, 1))
2200 {
2201 PrintToChat(client, "%s Gang request accepted.", PREFIX);
2202 PrintToChat(Iganginvite[client], "%s %N Accept your gang request.", PREFIX, client);
2203 } else
2204 {
2205 PrintToChat(client, "%s Failed to accept your gang request.", PREFIX);
2206 PrintToChat(Iganginvite[client], "%s Failed to accept your gang request.", PREFIX);
2207 }
2208 } else
2209 PrintToChat(client, "%s You cannot accept your gang request.", PREFIX);
2210 } else
2211 if (IsValidClient(Iganginvite[client]) && playerload[Iganginvite[client]])PrintToChat(Iganginvite[client], "%s %N decline your gang request.", PREFIX, client);
2212
2213 Iganginvite[client] = -1;
2214 Bganginvite[grouparray] = false;
2215
2216 if (invitetimer[grouparray] != INVALID_HANDLE)
2217 {
2218 KillTimer(invitetimer[grouparray]);
2219 invitetimer[grouparray] = INVALID_HANDLE;
2220 }
2221 }
2222 }
2223}
2224
2225public bool RemoveOfflineGroupMember(int owner, int GroupPlayerArray, int GroupID, int GroupArrayID, int membercount)
2226{
2227 //char[] sQuery = new char[512];
2228
2229 //Update Member slot count
2230 //FormatEx(sQuery, 512, "INSERT INTO `groups_items` (`itemid`, `groupid`, `itemcount`) VALUES ('%s', '%d', '%s') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` + %d;", Sgangshop[0][0], GroupID, 0, membercount);
2231 //DB.Query(SQL_RefreshMemberItemCount, sQuery, GroupID, DBPrio_High);
2232
2233 UpdateOfflinePlayerGroup(groupusers[GroupArrayID][GroupPlayerArray][0], -1);
2234 LoadGroupPlayerCount(GroupID, GroupArrayID);
2235 LoadGroupPlayerList(GroupID, GroupArrayID);
2236
2237 char addlog[128];
2238 Format(addlog, sizeof(addlog), "kicked %s from %s gang", groupusers[GroupArrayID][GroupPlayerArray][1], groups[GroupArrayID][3]);
2239 SendLog(owner, addlog);
2240
2241 return true;
2242}
2243
2244public bool RemoveOnlineGroupMember(int removedMember, int GroupID, int GroupArrayID, int membercount)
2245{
2246 //char[] sQuery = new char[512];
2247
2248 //Update Member slot count
2249 //FormatEx(sQuery, 512, "INSERT INTO `groups_items` (`itemid`, `groupid`, `itemcount`) VALUES ('%s', '%d', '%s') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` + %d;", Sgangshop[0][0], GroupID, 0, membercount);
2250 //DB.Query(SQL_RefreshMemberItemCount, sQuery, GroupID, DBPrio_High);
2251
2252 UpdatePlayerGroup(removedMember, -1);
2253 LoadGroupPlayerCount(GroupID, GroupArrayID);
2254 LoadGroupPlayerList(GroupID, GroupArrayID);
2255
2256 char addlog[128];
2257 Format(addlog, sizeof(addlog), "left %s gang", groups[GroupArrayID][3]);
2258 SendLog(removedMember, addlog);
2259
2260 return true;
2261}
2262
2263public bool AddGroupMember(int Owner, int newMember, int GroupID, int GroupArrayID, int membercount)
2264{
2265 //char[] sQuery = new char[512];
2266
2267 //Update Member slot count
2268 //FormatEx(sQuery, 512, "INSERT INTO `groups_items` (`itemid`, `groupid`, `itemcount`) VALUES ('%s', '%d', '%s') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` - %d;", Sgangshop[0][0], GroupID, -1, membercount);
2269 //DB.Query(SQL_RefreshMemberItemCount, sQuery, GroupID, DBPrio_High);
2270
2271 UpdatePlayerGroup(newMember, GroupID);
2272 LoadGroupPlayerCount(GroupID, GroupArrayID);
2273 LoadGroupPlayerList(GroupID, GroupArrayID);
2274
2275 char addlog[128];
2276 Format(addlog, sizeof(addlog), "joined to %s gang", groups[GroupArrayID][3]);
2277 SendLog(newMember, addlog);
2278
2279 return true;
2280}
2281
2282public void UpdateOfflinePlayerGroup(const char[] sAuthID, int GroupID)
2283{
2284 char[] sQuery = new char[256];
2285 FormatEx(sQuery, 256, "UPDATE `players` SET `groupid` = '%d' WHERE `steamid` = '%s';", GroupID, sAuthID);
2286 DB.Query(SQL_UpdatePlayerGroup, sQuery, 0, DBPrio_High);
2287}
2288
2289public void UpdatePlayerGroup(int client, int GroupID)
2290{
2291 groupid[client] = GroupID;
2292
2293 char[] sQuery = new char[256];
2294
2295 char[] sAuthID = new char[32];
2296 GetClientAuthId(client, AuthId_SteamID64, sAuthID, 32);
2297 FormatEx(sQuery, 256, "UPDATE `players` SET `groupid` = '%d' WHERE `steamid` = '%s';", GroupID, sAuthID);
2298 DB.Query(SQL_UpdatePlayerGroup, sQuery, 0, DBPrio_High);
2299}
2300
2301public void SQL_UpdatePlayerGroup(Database db, DBResultSet results, const char[] error, any data)
2302{
2303 if (results == null)
2304 {
2305 LogError("Store (cant update player group) SQL query failed. Reason: %s", error);
2306
2307 return;
2308 }
2309}
2310/*public void SQL_RefreshMemberItemCount(Database db, DBResultSet results, const char[] error, any data)
2311{
2312 if (results == null)
2313 {
2314 LogError("Store error! Failed to insert a disconnected player's data to the table. Reason: %s", error);
2315
2316 return;
2317 }
2318 LoadGroupItems(data, ArrayIDFromGroupID(data));
2319}*/
2320public Action clearganginvite(Handle Timer, any data)
2321{
2322 ResetPack(data);
2323 int client = ReadPackCell(data);
2324 int target = ReadPackCell(data);
2325 int GroupID = ReadPackCell(data);
2326
2327 int GroupArrayID = ArrayIDFromGroupID(GroupID);
2328 if (GroupArrayID != -1)
2329 {
2330 if (invitetimer[GroupID] != INVALID_HANDLE)
2331 {
2332 KillTimer(invitetimer[GroupID]);
2333 invitetimer[GroupID] = INVALID_HANDLE;
2334 }
2335
2336 Bganginvite[ArrayIDFromGroupID(GroupID)] = false;
2337
2338 if (IsValidClient(target))
2339 {
2340 Iganginvite[target] = -1;
2341 PrintToChat(target, "%s Gang request timeout.", PREFIX);
2342 }
2343 if (IsValidClient(client) && IsValidClient(target))PrintToChat(client, "%s %N Decline your gang request.", PREFIX, target);
2344 }
2345}
2346
2347public int gangdepcb(Menu gangdep, MenuAction action, int client, int item)
2348{
2349 if (action == MenuAction_Select)
2350 {
2351 char Scount[32];
2352 gangdep.GetItem(item, Scount, sizeof(Scount));
2353 int count = StringToInt(Scount);
2354
2355 if (playerload[client])
2356 {
2357 if (groupid[client] != -1)
2358 {
2359 if (credits[client] >= count)
2360 {
2361 int grouparray = ArrayIDFromGroupID(groupid[client]);
2362 if (grouparray != -1)
2363 {
2364 UpdatePlayer(client, credits[client] - count);
2365 int groupcredits = StringToInt(groups[grouparray][4]);
2366 UpdateGroup(groupid[client], groupcredits + count);
2367
2368 char deplog[128];
2369 Format(deplog, sizeof(deplog), "deposit %d credits for %s gang", count, groups[grouparray][3]);
2370 SendLog(client, deplog);
2371
2372 PrintToChat(client, "%s %d credits was deposited in the gang wallet.", PREFIX, count);
2373 }
2374 } else
2375 PrintToChat(client, "%s You do not have enogh credits.", PREFIX);
2376 } else
2377 PrintToChat(client, "%s Invalid group id.", PREFIX);
2378 } else
2379 PrintToChat(client, "%s You are not login to store system.", PREFIX);
2380
2381 cmd_gang(client, 0);
2382 }
2383 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)cmd_gang(client, 0);
2384}
2385
2386public int gangshopcb(Menu gangshop, MenuAction action, int client, int item)
2387{
2388 if (action == MenuAction_Select)
2389 {
2390 char Sitemid[32];
2391 gangshop.GetItem(item, Sitemid, sizeof(Sitemid));
2392 int Iitemid = StringToInt(Sitemid);
2393 GroupBuyCheck(client, Iitemid);
2394 }
2395 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)FakeClientCommand(client, "sm_gang");
2396}
2397
2398public void GroupBuyCheck(int client, int itemsid)
2399{
2400 char title[128];
2401 Menu groupbuymenu = new Menu(groupbuymenucb);
2402 Format(title, sizeof(title), "Buy %s (%s)", Sgangshop[itemsid][2], Sgangshop[itemsid][1]);
2403 groupbuymenu.SetTitle(title);
2404 groupbuymenu.AddItem("no", "No");
2405 char sitemsid[256];
2406 IntToString(itemsid, sitemsid, sizeof(sitemsid));
2407 groupbuymenu.AddItem(sitemsid, "Yes, buy!");
2408 groupbuymenu.ExitButton = false;
2409 groupbuymenu.Display(client, MENU_TIME_FOREVER);
2410}
2411
2412public int groupbuymenucb(Menu groupbuymenu, MenuAction action, int client, int item)
2413{
2414 if (action == MenuAction_Select)
2415 {
2416 char sitem[32];
2417 groupbuymenu.GetItem(item, sitem, sizeof(sitem));
2418
2419 if (!StrEqual(sitem, "no"))
2420 {
2421 if (groupid[client] != -1)
2422 {
2423 if (IsGroupOwner(client))
2424 {
2425 int Iitemid = StringToInt(sitem);
2426 int GroupArrayID = ArrayIDFromGroupID(groupid[client]);
2427 if (GroupArrayID != -1)
2428 {
2429 int groupcredits = StringToInt(groups[GroupArrayID][4]);
2430 if (groupcredits >= StringToInt(Sgangshop[Iitemid][1]))
2431 {
2432 if (DoGroupBuy(client, groupid[client], Sgangshop[Iitemid][0], 1, StringToInt(Sgangshop[Iitemid][1]), groupcredits))PrintToChat(client, "%s You bought %s.", PREFIX, Sgangshop[Iitemid][2]);
2433 else PrintToChat(client, "%s Buy failed, test again.");
2434 } else
2435 PrintToChat(client, "%s Your group dont have enogh credits.", PREFIX);
2436 }
2437 } else
2438 PrintToChat(client, "%s This feature resserved for gang leader.", PREFIX);
2439 } else
2440 PrintToChat(client, "%s Invalid group id.", PREFIX);
2441 }
2442
2443 FakeClientCommand(client, "sm_store");
2444 }
2445}
2446
2447public bool DoGroupBuy(int Buyer, int GroupID, const char[] ItemID, int buycount, int price, int groupcredits)
2448{
2449 char[] sQuery = new char[512];
2450
2451 FormatEx(sQuery, 512, "INSERT INTO `groups_items` (`itemid`, `groupid`, `itemcount`) VALUES ('%s', '%d', '%d') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` + %d;", ItemID, GroupID, buycount, buycount);
2452 DB.Query(SQL_GroupBuyItem, sQuery, GetClientSerial(Buyer), DBPrio_High);
2453
2454 UpdateGroup(GroupID, groupcredits - price);
2455
2456 int GroupArrayID = ArrayIDFromGroupID(GroupID);
2457 if (GroupArrayID != -1)
2458 {
2459 char buylog[128];
2460 Format(buylog, sizeof(buylog), "bought %s (%d credits) for %s gang", ItemID, price, groups[GroupArrayID][3]);
2461 SendLog(Buyer, buylog);
2462 }
2463
2464 return true;
2465}
2466
2467public void SQL_GroupBuyItem(Database db, DBResultSet results, const char[] error, any data)
2468{
2469 int client = GetClientFromSerial(data);
2470 if (results == null)
2471 {
2472
2473 if (client == 0)
2474 {
2475 LogError("Store error! Failed to insert a disconnected player's data to the table. Reason: %s", error);
2476 }
2477
2478 else
2479 {
2480 LogError("Store error! Failed to insert \"%N\"'s data to the table. Reason: %s", client, error);
2481 }
2482
2483 return;
2484 }
2485 int GroupArrayID = ArrayIDFromGroupID(groupid[client]);
2486 if (GroupArrayID != -1)LoadGroupItems(groupid[client], GroupArrayID);
2487}
2488
2489public int ganglistcb(Menu ganglist, MenuAction action, int client, int item)
2490{
2491 if (action == MenuAction_Select)
2492 {
2493 char Sitem[32];
2494 ganglist.GetItem(item, Sitem, sizeof(Sitem));
2495
2496 if (StrEqual(Sitem, "-1"))
2497 cmd_gang(client, 0);
2498 else {
2499 int GroupID = StringToInt(Sitem);
2500 int GroupArrayID = ArrayIDFromGroupID(GroupID);
2501 if (GroupArrayID != -1)
2502 {
2503 Menu gangmemberview = new Menu(gangmemberviewcb);
2504 char Senditem[32], title[128];
2505 Format(title, sizeof(title), "%s Member list (%s credits)", groups[GroupArrayID][3], groups[GroupArrayID][4]);
2506 gangmemberview.SetTitle(title);
2507
2508 for (int i = 0; i < groupuserscount[GroupArrayID]; i++)
2509 {
2510 IntToString(i, Senditem, sizeof(Senditem));
2511 gangmemberview.AddItem(Senditem, groupusers[GroupArrayID][i][1]);
2512 }
2513 if (gangmemberview.ItemCount == 0)
2514 gangmemberview.AddItem("-1", "Cant load member list right now.", ITEMDRAW_DISABLED);
2515
2516 gangmemberview.ExitBackButton = true;
2517 gangmemberview.ExitButton = true;
2518 gangmemberview.Display(client, MENU_TIME_FOREVER);
2519 }
2520 }
2521
2522 }
2523 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)cmd_gang(client, 0);
2524}
2525
2526public int gangmemberviewcb(Menu gangmemberview, MenuAction action, int client, int item)
2527{
2528 if (action == MenuAction_Select)
2529 {
2530 cmd_gang(client, 0);
2531 }
2532 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)cmd_gang(client, 0);
2533}
2534
2535public void SQL_CreateGroup(Database db, DBResultSet results, const char[] error, any data)
2536{
2537 int client = GetClientFromSerial(data);
2538 if (results == null)
2539 {
2540
2541 if (client == 0)
2542 {
2543 LogError("Store error! Failed to create group (player unknown). Reason: %s", error);
2544 }
2545
2546 else
2547 {
2548 LogError("Store error! Failed to create \"%N\" group. Reason: %s", client, error);
2549 }
2550
2551 return;
2552 }
2553
2554 char[] sAuthID64 = new char[32];
2555 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
2556 char[] sQuery = new char[512];
2557 FormatEx(sQuery, 256, "SELECT * FROM `groups` WHERE `ownerid` = '%s';", sAuthID64);
2558 DB.Query(SQL_LoadNewGroup, sQuery, GetClientSerial(client), DBPrio_High);
2559}
2560
2561public void SQL_LoadNewGroup(Database db, DBResultSet results, const char[] error, any data)
2562{
2563 int client = GetClientFromSerial(data);
2564 if (results == null)
2565 {
2566 if (client == 0)
2567 {
2568 LogError("Store error! Failed to load new group data (player unknown). Reason: %s", error);
2569 }
2570
2571 else
2572 {
2573 LogError("Store error! Failed to load new group data (\"%N\" group). Reason: %s", client, error);
2574 }
2575
2576 return;
2577 }
2578
2579 while (results.FetchRow())
2580 {
2581 results.FetchString(0, groups[groupscount][0], sizeof(groups[][]));
2582 results.FetchString(1, groups[groupscount][1], sizeof(groups[][]));
2583 results.FetchString(2, groups[groupscount][2], sizeof(groups[][]));
2584 results.FetchString(3, groups[groupscount][3], sizeof(groups[][]));
2585 results.FetchString(4, groups[groupscount][4], sizeof(groups[][]));
2586
2587 groupid[client] = results.FetchInt(0);
2588
2589 groupscount++;
2590 }
2591
2592 UpdatePlayer(client, credits[client] - GangPrice);
2593 UpdatePlayerGroup(client, groupid[client]);
2594 LoadGroupPlayerCount(groupid[client], ArrayIDFromGroupID(groupid[client]));
2595 LoadGroupPlayerList(groupid[client], ArrayIDFromGroupID(groupid[client]));
2596
2597 char[] sQuery = new char[512];
2598 FormatEx(sQuery, 512, "INSERT INTO `groups_items` (`itemid`, `groupid`, `itemcount`) VALUES ('%s', '%d', '%d') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` + %d;", Sgangshop[0][0], groupid[client], FreeSlots, 0);
2599 DB.Query(SQL_AddFreeSlots, sQuery, GetClientSerial(client), DBPrio_High);
2600
2601 PrintToChat(client, "%s The gang was created", PREFIX);
2602}
2603
2604public void SQL_AddFreeSlots(Database db, DBResultSet results, const char[] error, any data)
2605{
2606 int client = GetClientFromSerial(data);
2607 if (results == null)
2608 {
2609
2610 if (client == 0)
2611 {
2612 LogError("Store error! Failed to insert a disconnected player's data to the table. Reason: %s", error);
2613 }
2614
2615 else
2616 {
2617 LogError("Store error! Failed to insert \"%N\"'s data to the table. Reason: %s", client, error);
2618 }
2619
2620 return;
2621 }
2622 LoadGroupItems(groupid[client], ArrayIDFromGroupID(groupid[client]));
2623}
2624
2625public int bountyplaycb(Menu bountyplay, MenuAction action, int client, int item)
2626{
2627 if (action == MenuAction_Select)
2628 {
2629 char Splayerid[32];
2630 bountyplay.GetItem(item, Splayerid, sizeof(Splayerid));
2631 int playerid = StringToInt(Splayerid);
2632 if (playerid != -1)
2633 {
2634 Menu bountycount = new Menu(bountycountcb);
2635 bountycount.SetTitle("Choose bounty count: ");
2636 char senditem[64], displayitem[128];
2637 for (int i = 1; i < 10; i++)
2638 {
2639 int count = 100 * i;
2640 if (credits[client] >= count)
2641 {
2642 Format(displayitem, sizeof(displayitem), "%d Credits", count);
2643 Format(senditem, sizeof(senditem), "%d|%d", playerid, count);
2644 bountycount.AddItem(senditem, displayitem);
2645 }
2646 }
2647 for (int i = 1; i < 10; i++)
2648 {
2649 int count = 1000 * i;
2650 if (credits[client] >= count)
2651 {
2652 Format(displayitem, sizeof(displayitem), "%d Credits", count);
2653 Format(senditem, sizeof(senditem), "%d|%d", playerid, count);
2654 bountycount.AddItem(senditem, displayitem);
2655 }
2656 }
2657 if (bountycount.ItemCount == 0)
2658 bountycount.AddItem("-1", "You cannot use 'bounty' right now.", ITEMDRAW_DISABLED);
2659
2660 bountycount.ExitBackButton = true;
2661 bountycount.ExitButton = true;
2662 bountycount.Display(client, MENU_TIME_FOREVER);
2663 }
2664
2665 }
2666 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)cmd_gang(client, 0);
2667}
2668
2669public int bountycountcb(Menu bountycount, MenuAction action, int client, int item)
2670{
2671 if (action == MenuAction_Select)
2672 {
2673 char bountyinfo[32];
2674 bountycount.GetItem(item, bountyinfo, sizeof(bountyinfo));
2675 char splitinfo[2][64];
2676 int splitcount = ExplodeString(bountyinfo, "|", splitinfo, sizeof(splitinfo), sizeof(splitinfo[]));
2677 int i_bountyinfo[2];
2678 for (int i = 0; i < splitcount; i++)i_bountyinfo[i] = StringToInt(splitinfo[i]);
2679 /*
2680 i_bountyinfo[0] - bounty player
2681 i_bountyinfo[1] - bounty count
2682 */
2683 if (IsValidClient(client) && playerload[client])
2684 {
2685 if (IsValidClient(i_bountyinfo[0]))
2686 {
2687 if (playerload[i_bountyinfo[0]])
2688 {
2689 if (!isbounty[i_bountyinfo[0]])
2690 {
2691 if (credits[client] >= i_bountyinfo[1])
2692 {
2693 UpdatePlayer(client, credits[client] - i_bountyinfo[1]);
2694 isbounty[i_bountyinfo[0]] = true;
2695 bountyowner[i_bountyinfo[0]] = client;
2696 bountycredits[i_bountyinfo[0]] = i_bountyinfo[1];
2697 bountytime[i_bountyinfo[0]][0] = CreateTimer(120.0, bountytargetwin, i_bountyinfo[0]);
2698 bountytime[i_bountyinfo[0]][1] = CreateTimer(0.2, displaybounty, i_bountyinfo[0], TIMER_REPEAT);
2699
2700 PrintToChatAll("%s %N set bounty on %N (%d credits)", PREFIX, bountyowner[i_bountyinfo[0]], i_bountyinfo[0], i_bountyinfo[1]);
2701 } else
2702 PrintToChat(client, "%s You dont have enogh credits.", PREFIX);
2703 } else
2704 PrintToChat(client, "%s Your target already have bounty.", PREFIX);
2705 } else
2706 PrintToChat(client, "%s Your target are not login to store system.", PREFIX);
2707 } else
2708 PrintToChat(client, "%s Your bounty failed, test again.", PREFIX);
2709 } else
2710 PrintToChat(client, "%s You are not login to store system.", PREFIX);
2711
2712 }
2713 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)FakeClientCommand(client, "sm_store");
2714}
2715
2716public Action displaybounty(Handle Timer, any client)
2717{
2718 float pos[3];
2719 int rgba[4];
2720 GetClientEyePosition(client, pos);
2721 pos[2] += 10;
2722
2723 rgba[0] = 255;
2724 rgba[1] = 0;
2725 rgba[2] = 0;
2726 rgba[3] = 255;
2727
2728 TE_SetupBeamRingPoint(pos, 2.0, 10.0, PrecacheModel("materials/sprites/laserbeam.vmt"), PrecacheModel("materials/sprites/glow01.vmt"), 0, 32, 0.45, 3.0, 0.0, rgba, 6, 0);
2729 TE_SendToAll();
2730}
2731
2732
2733public Action bountytargetwin(Handle Timer, any client)
2734{
2735 if (playerload[client])
2736 {
2737 UpdatePlayer(client, credits[client] + bountycredits[client]);
2738 PrintToChatAll("%s 2 min passed %N won his bounty", PREFIX, client);
2739 }
2740 ResetBounty(client);
2741}
2742
2743public void ResetBounty(int client)
2744{
2745 isbounty[client] = false;
2746 bountyowner[client] = -1;
2747 bountycredits[client] = 0;
2748 if (bountytime[client][0] != INVALID_HANDLE)
2749 {
2750 KillTimer(bountytime[client][0]);
2751 bountytime[client][0] = INVALID_HANDLE;
2752 }
2753 if (bountytime[client][1] != INVALID_HANDLE)
2754 {
2755 KillTimer(bountytime[client][1]);
2756 bountytime[client][1] = INVALID_HANDLE;
2757 }
2758}
2759
2760public int playerinvcb(Menu playerinv, MenuAction action, int client, int item)
2761{
2762 if (action == MenuAction_Select)
2763 {
2764 char sitemid[32], title[128], displayitem[128];
2765 playerinv.GetItem(item, sitemid, sizeof(sitemid));
2766 int citemid = GetSItemIDFromItemID(players_items[client][StringToInt(sitemid)][0]);
2767 Menu itemsettings = new Menu(itemsettingscb);
2768 Format(title, sizeof(title), "%s Settings", items[citemid][1]);
2769 itemsettings.SetTitle(title);
2770 Format(displayitem, sizeof(displayitem), "Sell item for %d credits", StringToInt(items[citemid][2]) / 2);
2771 strcopy(playeraction[client][0], sizeof(playeraction[][]), sitemid);
2772 if (players_items[client][StringToInt(sitemid)][2] > 0)
2773 itemsettings.AddItem("unequip", "Unquip");
2774 else
2775 itemsettings.AddItem("equip", "Equip");
2776 itemsettings.AddItem("sell", displayitem);
2777 itemsettings.AddItem("senditem", "Send this item");
2778 itemsettings.ExitBackButton = true;
2779 itemsettings.ExitButton = true;
2780 itemsettings.Display(client, MENU_TIME_FOREVER);
2781
2782 }
2783 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)FakeClientCommand(client, "sm_store");
2784}
2785
2786public int itemsettingscb(Menu playerinv, MenuAction action, int client, int item)
2787{
2788 if (action == MenuAction_Select)
2789 {
2790 char citem[32];
2791 playerinv.GetItem(item, citem, sizeof(citem));
2792 int citemid = GetSItemIDFromItemID(players_items[client][StringToInt(playeraction[client][0])][0]);
2793 if (StrEqual(citem, "equip"))
2794 {
2795 int sitemid;
2796 for (int i = 0; i < pmaxitems[client]; i++)
2797 {
2798 sitemid = GetSItemIDFromItemID(players_items[client][i][0]);
2799 if (StrEqual(items[sitemid][3], items[citemid][3]) && StrEqual(items[sitemid][4], items[citemid][4]))
2800 {
2801 if (players_items[client][i][2] > 0)
2802 {
2803 changeequip(client, i, 0);
2804 }
2805 }
2806 }
2807 changeequip(client, StringToInt(playeraction[client][0]), 1);
2808 PrintToChat(client, "%s You have been equip %s (%s).", PREFIX, items[citemid][1], items[citemid][3]);
2809 }
2810 if (StrEqual(citem, "unequip"))
2811 {
2812 changeequip(client, StringToInt(playeraction[client][0]), 0);
2813 PrintToChat(client, "%s You have been unequip %s (%s).", PREFIX, items[citemid][1], items[citemid][3]);
2814 }
2815 if (StrEqual(citem, "sell"))
2816 {
2817 SellCheck(client, citemid);
2818 }
2819 if (StrEqual(citem, "senditem"))
2820 {
2821 SendItem(client, citemid);
2822 }
2823 }
2824 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)FakeClientCommand(client, "sm_store");
2825}
2826
2827public void SendItem(int client, int itemsid)
2828{
2829 char item[MAX_NAME_LENGTH], itemid[64];
2830 Menu sendmenu = new Menu(sendmenucb);
2831 sendmenu.SetTitle("Choose Player");
2832 IntToString(itemsid, sendgiftitemid[client], sizeof(sendgiftitemid[]));
2833 int sendcount = 0;
2834 //PrintToConsole(client, "before");
2835 for (int i = 1; i <= MaxClients; i++)
2836 {
2837 if (IsValidClient(i) && i != client)
2838 {
2839 Format(item, sizeof(item), "%N", i);
2840 Format(itemid, sizeof(itemid), "%d", i);
2841 sendmenu.AddItem(itemid, item);
2842 sendcount++;
2843
2844 //PrintToConsole(client, "sendcount - %d | item - %s | itemid - %s", sendcount, item, itemid);
2845 }
2846 }
2847 if (sendcount == 0)
2848 sendmenu.AddItem("-1", "No online players...", ITEMDRAW_DISABLED);
2849 //PrintToConsole(client, "sendcount - %d", sendcount);
2850 sendmenu.ExitButton = true;
2851 sendmenu.Display(client, MENU_TIME_FOREVER);
2852}
2853
2854public int sendmenucb(Menu sendmenu, MenuAction action, int client, int item)
2855{
2856 if (action == MenuAction_Select)
2857 {
2858 char starget[32];
2859 sendmenu.GetItem(item, starget, sizeof(starget));
2860 int target = StringToInt(starget);
2861 int itemsid = StringToInt(sendgiftitemid[client]);
2862 if (DoItemGift(client, target, itemsid, 1))
2863 {
2864 PrintToChat(client, "%s You send %s to %N.", PREFIX, items[itemsid][1], target);
2865 PrintToChat(target, "%s You get %s from %N.", PREFIX, items[itemsid][1], client);
2866 FakeClientCommand(client, "sm_store");
2867 }
2868 }
2869}
2870
2871public bool DoItemGift(int client, int target, int itemsid, int count)
2872{
2873 char[] sAuthID64 = new char[32];
2874 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
2875 char id[32];
2876 Format(id, sizeof(id), "%s|%s", items[itemsid][0], sAuthID64);
2877
2878 char[] sQuery = new char[256];
2879 //INSERT INTO `players_items` (`id`, `itemid`, `steamid`, `itemcount`) VALUES ('1545646515', '5000', '1545636515', '1') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` + 1;
2880 FormatEx(sQuery, 256, "INSERT INTO `players_items` (`id`, `itemid`, `steamid`, `itemcount`) VALUES ('%s', '%d', '%s', '%d') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` - %d;", id, StringToInt(items[itemsid][0]), sAuthID64, count, count);
2881 DB.Query(SQL_SendFunc, sQuery, GetClientSerial(client), DBPrio_High);
2882
2883 GetClientAuthId(target, AuthId_SteamID64, sAuthID64, 32);
2884 Format(id, sizeof(id), "%s|%s", items[itemsid][0], sAuthID64);
2885
2886 FormatEx(sQuery, 256, "INSERT INTO `players_items` (`id`, `itemid`, `steamid`, `itemcount`) VALUES ('%s', '%d', '%s', '%d') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` + %d;", id, StringToInt(items[itemsid][0]), sAuthID64, count, count);
2887 DB.Query(SQL_SendFunc, sQuery, GetClientSerial(target), DBPrio_High);
2888
2889 char giftlog[128];
2890 Format(giftlog, sizeof(giftlog), "send %s [%s] for %N", items[itemsid][1], items[itemsid][3], target);
2891 SendLog(client, giftlog);
2892
2893 return true;
2894}
2895
2896public void SellCheck(int client, int itemsid)
2897{
2898 char title[128];
2899 Menu sellmenu = new Menu(sellmenucb);
2900 Format(title, sizeof(title), "Sell %s (%s) for %d credits", items[itemsid][1], items[itemsid][3], StringToInt(items[itemsid][2]) / 2);
2901 sellmenu.SetTitle(title);
2902 sellmenu.AddItem("no", "No");
2903 char sitemsid[256];
2904 IntToString(itemsid, sitemsid, sizeof(sitemsid));
2905 sellmenu.AddItem(sitemsid, "Yes, sell!");
2906 sellmenu.ExitButton = false;
2907 sellmenu.Display(client, MENU_TIME_FOREVER);
2908}
2909
2910public int sellmenucb(Menu sellmenu, MenuAction action, int client, int item)
2911{
2912 if (action == MenuAction_Select)
2913 {
2914 char sitem[32];
2915 sellmenu.GetItem(item, sitem, sizeof(sitem));
2916 if (!StrEqual(sitem, "no"))
2917 {
2918 int itemsid = StringToInt(sitem);
2919 if (DoSell(client, itemsid, 1))
2920 {
2921 PrintToChat(client, "%s You sold %s for %d credits.", PREFIX, items[itemsid][1], StringToInt(items[itemsid][2]) / 2);
2922 FakeClientCommand(client, "sm_store");
2923 }
2924 }
2925 }
2926}
2927
2928public bool DoSell(int client, int itemsid, int count)
2929{
2930 char[] sAuthID64 = new char[32];
2931 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
2932 char id[32];
2933 Format(id, sizeof(id), "%s|%s", items[itemsid][0], sAuthID64);
2934
2935 char[] sQuery = new char[256];
2936 //INSERT INTO `players_items` (`id`, `itemid`, `steamid`, `itemcount`) VALUES ('1545646515', '5000', '1545636515', '1') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` + 1;
2937 FormatEx(sQuery, 256, "INSERT INTO `players_items` (`id`, `itemid`, `steamid`, `itemcount`) VALUES ('%s', '%d', '%s', '%d') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` - %d;", id, StringToInt(items[itemsid][0]), sAuthID64, count, count);
2938 DB.Query(SQL_SellItem, sQuery, GetClientSerial(client), DBPrio_High);
2939
2940 UpdatePlayer(client, credits[client] + (StringToInt(items[itemsid][2]) / 2));
2941
2942 char selllog[128];
2943 Format(selllog, sizeof(selllog), "sold %s [%s] for %d credits", items[itemsid][1], items[itemsid][3], (StringToInt(items[itemsid][2]) / 2));
2944 SendLog(client, selllog);
2945
2946 UpdateAch(client, 1.0, sellcode);
2947
2948 return true;
2949}
2950
2951public void SQL_SellItem(Database db, DBResultSet results, const char[] error, any data)
2952{
2953 int client = GetClientFromSerial(data);
2954 if (results == null)
2955 {
2956
2957 if (client == 0)
2958 {
2959 LogError("Store error! Failed to insert a disconnected player's data to the table. Reason: %s", error);
2960 }
2961
2962 else
2963 {
2964 LogError("Store error! Failed to insert \"%N\"'s data to the table. Reason: %s", client, error);
2965 }
2966
2967 return;
2968 }
2969
2970 LoadPlayerItems(client);
2971}
2972
2973public void SQL_SendFunc(Database db, DBResultSet results, const char[] error, any data)
2974{
2975 int client = GetClientFromSerial(data);
2976 if (results == null)
2977 {
2978
2979 if (client == 0)
2980 {
2981 LogError("[SendFucn] Store error! Failed to insert a disconnected player's data to the table. Reason: %s", error);
2982 }
2983
2984 else
2985 {
2986 LogError("[SendFucn] Store error! Failed to insert \"%N\"'s data to the table. Reason: %s", client, error);
2987 }
2988
2989 return;
2990 }
2991
2992 LoadPlayerItems(client);
2993}
2994
2995public void changeequip(int client, int pitemsid, int status)
2996{
2997 char[] sAuthID64 = new char[32];
2998 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
2999
3000 int citemid = GetSItemIDFromItemID(players_items[client][pitemsid][0]);
3001
3002 char id[32];
3003 Format(id, sizeof(id), "%s|%s", items[citemid][0], sAuthID64);
3004
3005 char[] sQuery = new char[256];
3006 //INSERT INTO `players_items` (`id`, `itemid`, `steamid`, `itemcount`) VALUES ('1545646515', '5000', '1545636515', '1') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` + 1;
3007 FormatEx(sQuery, 256, "INSERT INTO `players_items` (`id`) VALUES ('%s') ON DUPLICATE KEY UPDATE `equip` = '%d';", id, status);
3008 DB.Query(SQL_UnEquip, sQuery, GetClientSerial(client), DBPrio_High);
3009
3010 players_items[client][pitemsid][2] = status;
3011}
3012
3013public void SQL_UnEquip(Database db, DBResultSet results, const char[] error, any data)
3014{
3015 int client = GetClientFromSerial(data);
3016 if (results == null)
3017 {
3018
3019 if (client == 0)
3020 {
3021 LogError("Store error! Failed to insert a disconnected player's data to the table. Reason: %s", error);
3022 }
3023
3024 else
3025 {
3026 LogError("Store error! Failed to insert \"%N\"'s data to the table. Reason: %s", client, error);
3027 }
3028
3029 return;
3030 }
3031}
3032
3033stock int GetSItemIDFromItemID(int itemid)
3034{
3035 for (int i = 0; i < itemscount; i++)
3036 {
3037 if (StringToInt(items[i][0]) == itemid)
3038 return i;
3039 }
3040 return -1;
3041}
3042
3043public int storecatagorycb(Menu storecatagory, MenuAction action, int client, int item)
3044{
3045 if (action == MenuAction_Select)
3046 {
3047 char sitem[32];
3048 storecatagory.GetItem(item, sitem, sizeof(sitem));
3049 Format(playeraction[client][1], sizeof(playeraction[][]), "%s", sitem);
3050
3051 //Player Skin
3052 char title[128];
3053 if (StrEqual(sitem, "terrorist"))Format(title, sizeof(title), "T`s skins");
3054 if (StrEqual(sitem, "counterterrorist"))Format(title, sizeof(title), "CT`s skins");
3055
3056 //Chat
3057 if (StrEqual(sitem, "chatcolor"))
3058 {
3059 Format(title, sizeof(title), "Chat colors");
3060 Format(playeraction[client][0], sizeof(playeraction[][]), "%s", sitem);
3061 Format(playeraction[client][1], sizeof(playeraction[][]), "both");
3062 }
3063 if (StrEqual(sitem, "chattag"))
3064 {
3065 Format(title, sizeof(title), "Chat tags");
3066 Format(playeraction[client][0], sizeof(playeraction[][]), "%s", sitem);
3067 Format(playeraction[client][1], sizeof(playeraction[][]), "both");
3068 }
3069 if (StrEqual(sitem, "chattagcolor"))
3070 {
3071 Format(title, sizeof(title), "Chat tag colors");
3072 Format(playeraction[client][0], sizeof(playeraction[][]), "%s", sitem);
3073 Format(playeraction[client][1], sizeof(playeraction[][]), "both");
3074 }
3075 if (StrEqual(sitem, "namecolor"))
3076 {
3077 Format(title, sizeof(title), "Name colors");
3078 Format(playeraction[client][0], sizeof(playeraction[][]), "%s", sitem);
3079 Format(playeraction[client][1], sizeof(playeraction[][]), "both");
3080 }
3081
3082 //Nades
3083 if (StrEqual(sitem, "grenadeskin"))
3084 {
3085 Format(title, sizeof(title), "Grenade skins");
3086 Format(playeraction[client][0], sizeof(playeraction[][]), "%s", sitem);
3087 Format(playeraction[client][1], sizeof(playeraction[][]), "both");
3088 }
3089 if (StrEqual(sitem, "smokeskin"))
3090 {
3091 Format(title, sizeof(title), "Smoke Skins");
3092 Format(playeraction[client][0], sizeof(playeraction[][]), "%s", sitem);
3093 Format(playeraction[client][1], sizeof(playeraction[][]), "both");
3094 }
3095 if (StrEqual(sitem, "flashskin"))
3096 {
3097 Format(title, sizeof(title), "Flash Skins");
3098 Format(playeraction[client][0], sizeof(playeraction[][]), "%s", sitem);
3099 Format(playeraction[client][1], sizeof(playeraction[][]), "both");
3100 }
3101
3102 //Display Items From DB
3103 ShowItems(client, title);
3104 }
3105 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)FakeClientCommand(client, "sm_store");
3106}
3107
3108public void ShowItems(int client, const char[] title)
3109{
3110 char itemnum[256], mitem[128];
3111 Menu storeitems = new Menu(storeitemscb);
3112 storeitems.SetTitle(title);
3113 for (int i = 0; i < itemscount; i++)
3114 {
3115 if (StrEqual(items[i][3], playeraction[client][0]) && StrEqual(items[i][4], playeraction[client][1]) && validitem(i, client))
3116 {
3117 IntToString(i, itemnum, sizeof(itemnum));
3118 Format(mitem, sizeof(mitem), "%s [%s credits]", items[i][1], items[i][2]);
3119 if (credits[client] >= StringToInt(items[i][2]))
3120 storeitems.AddItem(itemnum, mitem);
3121 else
3122 storeitems.AddItem(itemnum, mitem, ITEMDRAW_DISABLED);
3123 }
3124 }
3125 storeitems.ExitBackButton = true;
3126 storeitems.ExitButton = true;
3127 storeitems.Display(client, MENU_TIME_FOREVER);
3128}
3129
3130public int storeitemscb(Menu storeitems, MenuAction action, int client, int item)
3131{
3132 if (action == MenuAction_Select)
3133 {
3134 char chose[32];
3135 storeitems.GetItem(item, chose, sizeof(chose));
3136 int chosen = StringToInt(chose);
3137 BuyCheck(client, chosen);
3138 }
3139 if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)FakeClientCommand(client, "sm_store");
3140}
3141
3142public void BuyCheck(int client, int itemsid)
3143{
3144 char title[128];
3145 Menu buymenu = new Menu(buymenucb);
3146 Format(title, sizeof(title), "Buy %s (%s)", items[itemsid][1], items[itemsid][3]);
3147 buymenu.SetTitle(title);
3148 buymenu.AddItem("no", "No");
3149 char sitemsid[256];
3150 IntToString(itemsid, sitemsid, sizeof(sitemsid));
3151 buymenu.AddItem(sitemsid, "Yes, buy!");
3152 int ptype = ITEMDRAW_DISABLED;
3153 if (StrEqual(items[itemsid][3], "playerskin"))
3154 ptype = ITEMDRAW_DEFAULT;
3155
3156 Format(sitemsid, sizeof(sitemsid), "photo%s", sitemsid);
3157 buymenu.AddItem(sitemsid, "Show Photo", ptype);
3158 buymenu.ExitButton = false;
3159 buymenu.Display(client, MENU_TIME_FOREVER);
3160}
3161
3162public int buymenucb(Menu buymenu, MenuAction action, int client, int item)
3163{
3164 if (action == MenuAction_Select)
3165 {
3166 char sitem[32];
3167 buymenu.GetItem(item, sitem, sizeof(sitem));
3168 if (StrContains(sitem, "photo", false) != -1)
3169 {
3170 ReplaceString(sitem, sizeof(sitem), "photo", "");
3171 int itemsid = StringToInt(sitem);
3172 char[] sAuthID = new char[32];
3173 GetClientAuthId(client, AuthId_SteamID64, sAuthID, 32);
3174 char url[128];
3175 Format(url, sizeof(url), "http://csgo.gamers-israel.co.il/redirect.php?url=http://csgo.gamers-israel.co.il/storephotos/%s.jpg", items[itemsid][0]);
3176 ShowMOTDPanel(client, "GamersAchievement", url, MOTDPANEL_TYPE_URL);
3177 //PrintToChat(client, "%s", url);
3178 }
3179 else if (!StrEqual(sitem, "no"))
3180 {
3181 int itemsid = StringToInt(sitem);
3182 if (DoBuy(client, itemsid, 1))
3183 {
3184 PrintToChat(client, "%s You bought %s with %s credits.", PREFIX, items[itemsid][1], items[itemsid][2]);
3185 FakeClientCommand(client, "sm_store");
3186 }
3187 }
3188 }
3189}
3190
3191public bool DoBuy(int client, int itemsid, int count)
3192{
3193 char[] sAuthID64 = new char[32];
3194 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
3195 char id[32];
3196 Format(id, sizeof(id), "%s|%s", items[itemsid][0], sAuthID64);
3197
3198 char[] sQuery = new char[512];
3199 //INSERT INTO `players_items` (`id`, `itemid`, `steamid`, `itemcount`) VALUES ('1545646515', '5000', '1545636515', '1') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` + 1;
3200 //INSERT INTO `players_logs` (`steamid`, `name`, `log`, `unix_date`) VALUES ('76561198156423013', 'AuToPrO`', 'bought shit [Grenade Skin] for 100 credits.', '54543543');
3201 FormatEx(sQuery, 512, "INSERT INTO `players_items` (`id`, `itemid`, `steamid`, `itemcount`) VALUES ('%s', '%d', '%s', '%d') ON DUPLICATE KEY UPDATE `itemcount` = `itemcount` + %d;", id, StringToInt(items[itemsid][0]), sAuthID64, count, count);
3202 DB.Query(SQL_BuyItem, sQuery, GetClientSerial(client), DBPrio_High);
3203
3204 UpdatePlayer(client, credits[client] - StringToInt(items[itemsid][2]));
3205
3206 char buylog[128];
3207 Format(buylog, sizeof(buylog), "bought %s [%s] for %s credits", items[itemsid][1], items[itemsid][3], items[itemsid][2]);
3208 SendLog(client, buylog);
3209
3210 UpdateAch(client, 1.0, buycode);
3211
3212 return true;
3213}
3214
3215stock void SendLog(int client, const char[] log)
3216{
3217 char[] sAuthID64 = new char[32];
3218 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
3219
3220 char[] sName = new char[MAX_NAME_LENGTH];
3221 GetClientName(client, sName, MAX_NAME_LENGTH);
3222
3223 int iLength = ((strlen(sName) * 2) + 1);
3224 char[] sEscapedName = new char[iLength];
3225 DB.Escape(sName, sEscapedName, iLength);
3226
3227 char[] sQuery = new char[512];
3228 FormatEx(sQuery, 1024, "INSERT INTO `players_logs` (`steamid`, `name`, `log`, `unix_date`) VALUES ('%s', '%s', '%s', '%d');", sAuthID64, sName, log, GetTime());
3229 DB.Query(SQL_LeftLog, sQuery, GetClientSerial(client), DBPrio_High);
3230}
3231
3232public void SQL_LeftLog(Database db, DBResultSet results, const char[] error, any data)
3233{
3234 int client = GetClientFromSerial(data);
3235 if (results == null)
3236 {
3237
3238 if (client == 0)
3239 {
3240 LogError("Store error! Failed to insert a disconnected player's data to the table. Reason: %s", error);
3241 }
3242
3243 else
3244 {
3245 LogError("Store error! Failed to insert \"%N\"'s data to the table. Reason: %s", client, error);
3246 }
3247
3248 return;
3249 }
3250}
3251
3252public void SQL_BuyItem(Database db, DBResultSet results, const char[] error, any data)
3253{
3254 int client = GetClientFromSerial(data);
3255 if (results == null)
3256 {
3257
3258 if (client == 0)
3259 {
3260 LogError("Store error! Failed to insert a disconnected player's data to the table. Reason: %s", error);
3261 }
3262
3263 else
3264 {
3265 LogError("Store error! Failed to insert \"%N\"'s data to the table. Reason: %s", client, error);
3266 }
3267
3268 return;
3269 }
3270 LoadPlayerItems(client);
3271}
3272
3273public Action ChatQuestGenerate(Handle Timer)
3274{
3275 ChatGameType = GetRandomInt(ChatGame_Off + 1, MAX_CHAT_GAMES - 1);
3276 PrintToChatAll("%s %s start.", PREFIX, GamesList[ChatGameType]);
3277 gamecredits = GetRandomInt(1, 20);
3278 float gametime = GetRandomFloat(5.0, 12.0);
3279 if (ChatGameType == ChatGame_Math)
3280 {
3281 int quest = GetRandomInt(1, 3);
3282 int x = GetRandomInt(1, 999);
3283 int b = GetRandomInt(1, 999);
3284 if (quest == 1)
3285 mathquest = x + b;
3286 if (quest == 2)
3287 mathquest = x - b;
3288 if (quest == 3)
3289 mathquest = x * b;
3290
3291 //for (int i = 1; i <= 5; i++)
3292 PrintToChatAll("%s %d %s %d = ? (%d credits)", PREFIX, x, quest == 1 ? "+" : quest == 2 ? "-" : "*", b, gamecredits);
3293 }
3294 if (ChatGameType == ChatGame_Translate)
3295 StartTranslateGame();
3296 if (ChatGameType == ChatGame_MissingLetter)
3297 StartMissingLetter();
3298 StopGame = CreateTimer(gametime, EndGame, INVALID_HANDLE);
3299}
3300
3301public Action EndGame(Handle Timer)
3302{
3303 PrintToChatAll("%s No one find the %s answer", PREFIX, GamesList[ChatGameType]);
3304 ChatGameType = ChatGame_Off;
3305}
3306
3307public Action ForceCredits(Handle Timer)
3308{
3309 int rgive;
3310 for (int i = 1; i <= MaxClients; i++)
3311 {
3312 if (IsValidClient(i) && playerload[i])
3313 {
3314 int CreditsBoost = 0;
3315 if (groupid[i] != -1)
3316 {
3317 int GroupArrayID = ArrayIDFromGroupID(groupid[i]);
3318 if (GroupArrayID != -1)
3319 CreditsBoost = 0; //GetGroupSpecificItemCount(Sgangshop[2][0], groupid[i]);
3320 }
3321 rgive = GetRandomInt(ForceMinCredits, ForceMaxCredits + CreditsBoost);
3322 UpdatePlayer(i, credits[i] + rgive);
3323 PrintToChat(i, "%s You got %d credits.", PREFIX, rgive);
3324 }
3325 }
3326}
3327
3328public Action UpdateGroupData(Handle Timer)
3329{
3330 char[] sAuthID64 = new char[32];
3331 char[] sQuery = new char[256];
3332 for (int i = 1; i <= MaxClients; i++)
3333 {
3334 if (IsValidClient(i) && playerload[i] && groupid[i] != -1)
3335 {
3336 GetClientAuthId(i, AuthId_SteamID64, sAuthID64, 32);
3337 FormatEx(sQuery, 256, "SELECT `groupid` FROM `players` WHERE `steamid` = '%s';", sAuthID64);
3338 DB.Query(SQL_LoadPlayerGroup, sQuery, GetClientSerial(i), DBPrio_High);
3339 }
3340 }
3341 FormatEx(sQuery, 256, "SELECT * FROM `groups`;");
3342 DB.Query(SQL_LoadGroups, sQuery, 0, DBPrio_High);
3343 /*for (int i = 0; i < groupscount; i++)
3344 {
3345 int GroupID = StringToInt(groups[i][0]);
3346 int GroupArrayID = ArrayIDFromGroupID(GroupID);
3347
3348 LoadGroupItems(GroupID, GroupArrayID);
3349 LoadGroupPlayerCount(GroupID, GroupArrayID);
3350 LoadGroupPlayerList(GroupID, GroupArrayID);
3351 }*/
3352}
3353
3354public void SQL_LoadPlayerGroup(Database db, DBResultSet results, const char[] error, any data)
3355{
3356 int client = GetClientFromSerial(data);
3357 if (results == null)
3358 {
3359 if (client == 0)
3360 {
3361 LogError("Store error! Failed to select a disconnected player's data to the table. Reason: %s", error);
3362 }
3363
3364 else
3365 {
3366 LogError("Store error! Failed to select \"%N\"'s data to the table. Reason: %s", client, error);
3367 }
3368 return;
3369 }
3370
3371 while (results.FetchRow())
3372 {
3373 groupid[client] = results.FetchInt(0);
3374 }
3375}
3376
3377public void OnClientDisconnect(int client)
3378{
3379 if (isbounty[client])
3380 {
3381 if (playerload[bountyowner[client]])
3382 {
3383 UpdatePlayer(bountyowner[client], credits[bountyowner[client]] + bountycredits[client]);
3384 PrintToChat(bountyowner[client], "%s %N disconnected, your bounty`s credits back to your wallet.", PREFIX, client);
3385 ResetBounty(client);
3386 }
3387 } else {
3388 for (int i = 1; i <= MaxClients; i++)
3389 {
3390 if (IsValidClient(i) && playerload[i] && isbounty[i])
3391 {
3392 if (bountyowner[i] == client)
3393 {
3394 UpdatePlayer(i, credits[i] + bountycredits[i]);
3395 PrintToChat(i, "%s %N disconnected, you win your bounty.", PREFIX, client);
3396 ResetBounty(i);
3397 }
3398 }
3399 }
3400 }
3401 if (Iganginvite[client] != -1)
3402 {
3403 int GroupArray = ArrayIDFromGroupID(groupid[Iganginvite[client]]);
3404 if (GroupArray != -1)
3405 {
3406 if (invitetimer[GroupArray] != INVALID_HANDLE)
3407 {
3408 KillTimer(invitetimer[GroupArray]);
3409 invitetimer[GroupArray] = INVALID_HANDLE;
3410 }
3411
3412 Bganginvite[GroupArray] = false;
3413
3414 PrintToChat(Iganginvite[client], "%s %N disconnected, your invite aborted.", PREFIX, client);
3415 }
3416 } else {
3417 for (int i = 1; i <= MaxClients; i++)
3418 {
3419 if (IsValidClient(i) && client != i && playerload[i] && Iganginvite[i] == client)
3420 {
3421 int GroupArray = ArrayIDFromGroupID(groupid[client]);
3422 if (GroupArray != -1)
3423 {
3424 if (invitetimer[GroupArray] != INVALID_HANDLE)
3425 {
3426 KillTimer(invitetimer[GroupArray]);
3427 invitetimer[GroupArray] = INVALID_HANDLE;
3428 }
3429
3430 Bganginvite[GroupArray] = false;
3431 Iganginvite[i] = -1;
3432
3433 PrintToChat(i, "%s %N disconnected, your invite aborted.", PREFIX, client);
3434 }
3435 }
3436 }
3437 }
3438
3439 Iganginvite[client] = -1;
3440 playerload[client] = false;
3441 credits[client] = 0;
3442 groupid[client] = -1;
3443 playervip[client] = false;
3444 endtime[client] = 0;
3445 vipgiftcredits[client] = 0;
3446 jackpot[client] = -1;
3447 lastdaily[client] = 0;
3448 dailyplayerspot[client] = 0;
3449 timeunixupdate[client] = 0;
3450 cfcoinflipcount[client] = 0;
3451 cfplayerspot[client] = 0;
3452 cfplayerend[client] = 0;
3453 cfplayerstatus[client] = false;
3454 Format(sendgiftitemid[client], sizeof(sendgiftitemid[]), "-1");
3455 mirrorstatus[client] = false;
3456 for (int i = 0; i < pmaxitems[client]; i++)
3457 {
3458 players_items[client][i][0] = -1;
3459 players_items[client][i][1] = 0;
3460 players_items[client][i][2] = 0;
3461 }
3462 pmaxitems[client] = 0;
3463
3464 if (hPlayerTrail[client] != INVALID_HANDLE)
3465 {
3466 KillTimer(hPlayerTrail[client]);
3467 hPlayerTrail[client] = INVALID_HANDLE;
3468 }
3469
3470 if (dailydisplay[client] != INVALID_HANDLE)
3471 {
3472 KillTimer(dailydisplay[client]);
3473 dailydisplay[client] = INVALID_HANDLE;
3474 }
3475
3476 if (timeupdate[client] != INVALID_HANDLE)
3477 {
3478 KillTimer(timeupdate[client]);
3479 timeupdate[client] = INVALID_HANDLE;
3480 }
3481
3482 if (cfplayerdisplay[client] != INVALID_HANDLE)
3483 {
3484 KillTimer(cfplayerdisplay[client]);
3485 cfplayerdisplay[client] = INVALID_HANDLE;
3486 }
3487}
3488
3489public void OnClientPutInServer(int client)
3490{
3491 playerload[client] = false;
3492 credits[client] = 0;
3493 groupid[client] = -1;
3494 playervip[client] = false;
3495 endtime[client] = 0;
3496 vipgiftcredits[client] = 0;
3497 jackpot[client] = -1;
3498 lastdaily[client] = 0;
3499 dailyplayerspot[client] = 0;
3500 timeunixupdate[client] = 0;
3501 cfcoinflipcount[client] = 0;
3502 cfplayerspot[client] = 0;
3503 cfplayerend[client] = 0;
3504 cfplayerstatus[client] = false;
3505 mirrorstatus[client] = false;
3506 Iganginvite[client] = -1;
3507 ResetBounty(client);
3508 Format(sendgiftitemid[client], sizeof(sendgiftitemid[]), "-1");
3509 if (DB != null && IsValidClient(client))
3510 {
3511 char[] sAuthID64 = new char[32];
3512 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
3513 if (!StrEqual(sAuthID64, "STEAM_ID_STOP_IGNORING_RETVALS"))
3514 {
3515 char[] sName = new char[MAX_NAME_LENGTH];
3516 GetClientName(client, sName, MAX_NAME_LENGTH);
3517
3518 int iLength = ((strlen(sName) * 2) + 1);
3519 char[] sEscapedName = new char[iLength];
3520 DB.Escape(sName, sEscapedName, iLength);
3521
3522 char[] sQuery = new char[512];
3523 //INSERT INTO `players` (`steamid`, `name`) VALUES ('STAEM_0:065874', 'AutoPro') ON DUPLICATE KEY UPDATE `name` = 'AniPro', `lastjoin` = '15151';
3524
3525 char[] ip = new char[16];
3526 GetClientIP(client, ip, 16, true);
3527 FormatEx(sQuery, 512, "INSERT INTO `players` (`steamid`, `name`, `ip`) VALUES ('%s', '%s', '%s') ON DUPLICATE KEY UPDATE `name` = '%s', `lastjoin` = '%d', `ip` = '%s';", sAuthID64, sEscapedName, ip, sEscapedName, GetTime(), ip);
3528 DB.Query(SQL_LoadPlayercb, sQuery, GetClientSerial(client), DBPrio_High);
3529 }
3530 }
3531}
3532
3533public void SQL_LoadPlayercb(Database db, DBResultSet results, const char[] error, any data)
3534{
3535 int client = GetClientFromSerial(data);
3536 if (results == null)
3537 {
3538
3539 if (client == 0)
3540 {
3541 LogError("Store error! Failed to insert a disconnected player's data to the table. Reason: %s", error);
3542 }
3543
3544 else
3545 {
3546 LogError("Store error! Failed to insert \"%N\"'s data to the table. Reason: %s", client, error);
3547 }
3548
3549 return;
3550 }
3551
3552 char[] sAuthID64 = new char[32];
3553 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
3554
3555 char[] sQuery = new char[256];
3556 //SELECT `credits` FROM `players` WHERE `steamid` = 'STAEM_0:0655874';
3557 FormatEx(sQuery, 256, "SELECT `credits`, `groupid` FROM `players` WHERE `steamid` = '%s';", sAuthID64);
3558 DB.Query(SQL_LoadPlayerInfocb, sQuery, GetClientSerial(client), DBPrio_High);
3559}
3560
3561public void SQL_LoadPlayerInfocb(Database db, DBResultSet results, const char[] error, any data)
3562{
3563 int client = GetClientFromSerial(data);
3564 if (results == null)
3565 {
3566 if (client == 0)
3567 {
3568 LogError("Store error! Failed to select a disconnected player's data to the table. Reason: %s", error);
3569 }
3570
3571 else
3572 {
3573 LogError("Store error! Failed to select \"%N\"'s data to the table. Reason: %s", client, error);
3574 }
3575 return;
3576 }
3577
3578 while (results.FetchRow())
3579 {
3580 credits[client] = results.FetchInt(0);
3581 groupid[client] = results.FetchInt(1);
3582 }
3583
3584 LoadPlayerItems(client);
3585
3586 playerload[client] = true;
3587 char[] sAuthID64 = new char[32];
3588 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
3589 char[] sQuery = new char[256];
3590 //SELECT * FROM `storevip`
3591 FormatEx(sQuery, 256, "SELECT * FROM `storevip` WHERE `steamid` = '%s';", sAuthID64);
3592 DB.Query(SQL_LoadVIP, sQuery, GetClientSerial(client), DBPrio_High);
3593
3594 timeunixupdate[client] = GetTime();
3595 timeupdate[client] = CreateTimer(300.0, PlayTimeUpdate, client, TIMER_REPEAT);
3596}
3597
3598public void SQL_LoadVIP(Database db, DBResultSet results, const char[] error, any data)
3599{
3600 int client = GetClientFromSerial(data);
3601 if (results == null)
3602 {
3603 if (client == 0)
3604 {
3605 LogError("Store error! Failed to select a disconnected player's data to the table. Reason: %s", error);
3606 }
3607
3608 else
3609 {
3610 LogError("Store error! Failed to select \"%N\"'s data to the table. Reason: %s", client, error);
3611 }
3612 return;
3613 }
3614 playervip[client] = false;
3615 endtime[client] = 0;
3616 vipgiftcredits[client] = 0;
3617 while (results.FetchRow())
3618 {
3619 endtime[client] = results.FetchInt(2);
3620 vipgiftcredits[client] = results.FetchInt(3);
3621 if (endtime[client] > GetTime() || endtime[client] == 150)
3622 playervip[client] = true;
3623 }
3624
3625 char[] sAuthID64 = new char[32];
3626 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
3627
3628 char[] sName = new char[MAX_NAME_LENGTH];
3629 GetClientName(client, sName, MAX_NAME_LENGTH);
3630
3631 int iLength = ((strlen(sName) * 2) + 1);
3632 char[] sEscapedName = new char[iLength];
3633 DB.Escape(sName, sEscapedName, iLength);
3634
3635 char[] sQuery = new char[512];
3636
3637 FormatEx(sQuery, 512, "INSERT INTO `storedaily` (`steamid`, `name`, `lastdaily`) VALUES ('%s', '%s', '%d') ON DUPLICATE KEY UPDATE `name` = '%s';", sAuthID64, sEscapedName, GetTime() - 86400, sEscapedName);
3638 DB.Query(SQL_LoadDailyData, sQuery, GetClientSerial(client), DBPrio_High);
3639}
3640
3641public void SQL_LoadDailyData(Database db, DBResultSet results, const char[] error, any data)
3642{
3643 int client = GetClientFromSerial(data);
3644 if (results == null)
3645 {
3646
3647 if (client == 0)
3648 {
3649 LogError("Store error! Failed to insert a disconnected player's data to the table. Reason: %s", error);
3650 }
3651
3652 else
3653 {
3654 LogError("Store error! Failed to insert \"%N\"'s data to the table. Reason: %s", client, error);
3655 }
3656
3657 return;
3658 }
3659
3660 char[] sAuthID64 = new char[32];
3661 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
3662
3663 char[] sQuery = new char[256];
3664 FormatEx(sQuery, 256, "SELECT `lastdaily` FROM `storedaily` WHERE `steamid` = '%s';", sAuthID64);
3665 DB.Query(SQL_LoadDailyTime, sQuery, GetClientSerial(client), DBPrio_High);
3666}
3667
3668public void SQL_LoadDailyTime(Database db, DBResultSet results, const char[] error, any data)
3669{
3670 int client = GetClientFromSerial(data);
3671 if (results == null)
3672 {
3673 if (client == 0)
3674 {
3675 LogError("Store error! Failed to select a disconnected player's data to the table. Reason: %s", error);
3676 }
3677
3678 else
3679 {
3680 LogError("Store error! Failed to select \"%N\"'s data to the table. Reason: %s", client, error);
3681 }
3682 return;
3683 }
3684
3685 while (results.FetchRow())
3686 {
3687 lastdaily[client] = results.FetchInt(0);
3688 }
3689}
3690
3691public void LoadPlayerItems(int client)
3692{
3693 char[] sAuthID64 = new char[32];
3694 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
3695
3696 char[] sQuery = new char[256];
3697 //SELECT `itemid`, `itemcount` FROM `players_items` WHERE `steamid` = '1234';
3698 FormatEx(sQuery, 256, "SELECT `itemid`, `itemcount`, `equip` FROM `players_items` WHERE `steamid` = '%s';", sAuthID64);
3699 DB.Query(SQL_LoadPlayerItems, sQuery, GetClientSerial(client), DBPrio_High);
3700}
3701
3702public void SQL_LoadPlayerItems(Database db, DBResultSet results, const char[] error, any data)
3703{
3704 int client = GetClientFromSerial(data);
3705 if (results == null)
3706 {
3707 if (client == 0)
3708 {
3709 LogError("Store error! Failed to select a disconnected player's data to the table. Reason: %s", error);
3710 }
3711
3712 else
3713 {
3714 LogError("Store error! Failed to select \"%N\"'s data to the table. Reason: %s", client, error);
3715 }
3716 return;
3717 }
3718 pmaxitems[client] = 0;
3719 while (results.FetchRow())
3720 {
3721 players_items[client][pmaxitems[client]][0] = results.FetchInt(0);
3722 players_items[client][pmaxitems[client]][1] = results.FetchInt(1);
3723 players_items[client][pmaxitems[client]][2] = results.FetchInt(2);
3724 pmaxitems[client]++;
3725 }
3726}
3727
3728stock bool validitem(int itemid, int client)
3729{
3730 if (StringToInt(items[itemid][6]) == 0)
3731 return false;
3732
3733 if (StringToInt(items[itemid][5]) == 0)
3734 return true;
3735
3736 if (playervip[client])
3737 return true;
3738
3739 return false;
3740}
3741
3742public void UpdatePlayer(int uclient, int ucredits)
3743{
3744 char[] sAuthID = new char[32];
3745 GetClientAuthId(uclient, AuthId_SteamID64, sAuthID, 32);
3746
3747 char[] sQuery = new char[256];
3748 //UPDATE `players` SET `credits` = '99999999' WHERE `steamid` = 'STAEM_0:065874';
3749 FormatEx(sQuery, 256, "UPDATE `players` SET `credits` = '%d' WHERE `steamid` = '%s';", ucredits, sAuthID);
3750
3751 DB.Query(SQL_UpdatePlayer, sQuery);
3752
3753 credits[uclient] = ucredits;
3754}
3755
3756public void SQL_UpdatePlayer(Database db, DBResultSet results, const char[] error, any data)
3757{
3758 if (results == null)
3759 {
3760 LogError("Store (cant update player info) SQL query failed. Reason: %s", error);
3761
3762 return;
3763 }
3764}
3765
3766public void OnMapStart()
3767{
3768 ChatGameType = ChatGame_Off;
3769
3770 char[] sQuery = new char[256];
3771 //SELECT * FROM `items`
3772 FormatEx(sQuery, 256, "SELECT * FROM `items` ORDER By `price` ASC;");
3773 DB.Query(SQL_LoadItems, sQuery, 0, DBPrio_High);
3774 //SELECT * FROM `storeadmin`
3775 FormatEx(sQuery, 256, "SELECT * FROM `storeadmin`;");
3776 DB.Query(SQL_LoadAdmins, sQuery, 0, DBPrio_High);
3777 //SELECT * FROM `ach`
3778 FormatEx(sQuery, 256, "SELECT * FROM `ach`;");
3779 DB.Query(SQL_LoadAch, sQuery, 0, DBPrio_High);
3780 //SELECT * FROM `groups`
3781 FormatEx(sQuery, 256, "SELECT * FROM `groups`;");
3782 DB.Query(SQL_LoadGroups, sQuery, 0, DBPrio_High);
3783
3784 //Reset jp
3785 jackpotc = 0;
3786
3787 //Arms Fix
3788 PrecacheModel(defaultArms[0], true);
3789 PrecacheModel(defaultArms[1], true);
3790
3791 //Load CoinFlip
3792 char coinfile[128];
3793 for (int i = 1; i <= 16; i++)
3794 {
3795 Format(coinfile, sizeof(coinfile), "materials/gamers/coinflip/coinflip_%d.vmt", i);
3796 AddFileToDownloadsTable(coinfile);
3797 PrecacheModel(coinfile);
3798 Format(coinfile, sizeof(coinfile), "materials/gamers/coinflip/coinflip_%d.vtf", i);
3799 AddFileToDownloadsTable(coinfile);
3800 }
3801 //Daily Load
3802 char dailyfile[128];
3803 for (int i = 0; i < sizeof(DailySounds); i++)
3804 {
3805 Format(dailyfile, sizeof(dailyfile), "%s", DailySounds[i]);
3806 PrecacheSound(dailyfile, true);
3807 Format(dailyfile, sizeof(dailyfile), "sound/%s", DailySounds[i]);
3808 AddFileToDownloadsTable(dailyfile);
3809 }
3810 for (int i = 1; i <= 8; i++)
3811 {
3812 Format(dailyfile, sizeof(dailyfile), "materials/gamers/daily/daily_%d.vmt", i);
3813 AddFileToDownloadsTable(dailyfile);
3814 PrecacheModel(dailyfile);
3815 Format(dailyfile, sizeof(dailyfile), "materials/gamers/daily/daily_select_%d.vmt", i);
3816 AddFileToDownloadsTable(dailyfile);
3817 PrecacheModel(dailyfile);
3818 Format(dailyfile, sizeof(dailyfile), "materials/gamers/daily/daily_%d.vtf", i);
3819 AddFileToDownloadsTable(dailyfile);
3820 Format(dailyfile, sizeof(dailyfile), "materials/gamers/daily/daily_select_%d.vtf", i);
3821 AddFileToDownloadsTable(dailyfile);
3822 }
3823}
3824
3825public void SQL_LoadItems(Database db, DBResultSet results, const char[] error, any data)
3826{
3827 if (results == null)
3828 {
3829 LogError("Store error! Failed to load items data to the table. Reason: %s", error);
3830 return;
3831 }
3832
3833 itemscount = 0;
3834
3835 while (results.FetchRow())
3836 {
3837 results.FetchString(0, items[itemscount][0], sizeof(items[][]));
3838 results.FetchString(1, items[itemscount][1], sizeof(items[][]));
3839 results.FetchString(2, items[itemscount][2], sizeof(items[][]));
3840 results.FetchString(3, items[itemscount][3], sizeof(items[][]));
3841 results.FetchString(4, items[itemscount][4], sizeof(items[][]));
3842 results.FetchString(5, items[itemscount][5], sizeof(items[][]));
3843 results.FetchString(6, items[itemscount][6], sizeof(items[][]));
3844 results.FetchString(7, items[itemscount][7], sizeof(items[][]));
3845 results.FetchString(8, items[itemscount][8], sizeof(items[][]));
3846
3847 if (!StrEqual(items[itemscount][3], "namecolor") && !StrEqual(items[itemscount][3], "chattagcolor") && !StrEqual(items[itemscount][3], "chattag") && !StrEqual(items[itemscount][3], "chatcolor"))
3848 {
3849 PrecacheModel(items[itemscount][7], true);
3850 Downloader_AddFileToDownloadsTable(items[itemscount][7]);
3851 }
3852 itemscount++;
3853 }
3854}
3855
3856public void SQL_LoadAdmins(Database db, DBResultSet results, const char[] error, any data)
3857{
3858 if (results == null)
3859 {
3860 LogError("Store error! Failed to load storeadmin data to the table. Reason: %s", error);
3861 return;
3862 }
3863
3864 adminscount = 0;
3865
3866 while (results.FetchRow())
3867 {
3868 results.FetchString(0, storeadmin[adminscount][0], sizeof(storeadmin[][]));
3869 results.FetchString(1, storeadmin[adminscount][1], sizeof(storeadmin[][]));
3870 adminscount++;
3871 }
3872}
3873
3874public void SQL_LoadAch(Database db, DBResultSet results, const char[] error, any data)
3875{
3876 if (results == null)
3877 {
3878 LogError("Store error! Failed to load achievement list data to the table. Reason: %s", error);
3879 return;
3880 }
3881
3882 achcount = 0;
3883
3884 while (results.FetchRow())
3885 {
3886 results.FetchString(0, ach[achcount][0], sizeof(ach[][]));
3887 results.FetchString(1, ach[achcount][1], sizeof(ach[][]));
3888 results.FetchString(2, ach[achcount][2], sizeof(ach[][]));
3889 results.FetchString(3, ach[achcount][3], sizeof(ach[][]));
3890 results.FetchString(4, ach[achcount][4], sizeof(ach[][]));
3891 results.FetchString(5, ach[achcount][5], sizeof(ach[][]));
3892 results.FetchString(6, ach[achcount][6], sizeof(ach[][]));
3893 results.FetchString(7, ach[achcount][7], sizeof(ach[][]));
3894 if (StrEqual(ach[achcount][7], "playhours.png"))timecode = achcount;
3895 if (StrEqual(ach[achcount][7], "killplayers.png"))killcode = achcount;
3896 if (StrEqual(ach[achcount][7], "headshot.png"))headkillcode = achcount;
3897 if (StrEqual(ach[achcount][7], "knifekill.png"))knifekillcode = achcount;
3898 if (StrEqual(ach[achcount][7], "buy.png"))buycode = achcount;
3899 if (StrEqual(ach[achcount][7], "sell.png"))sellcode = achcount;
3900 if (StrEqual(ach[achcount][7], "daily.png"))spinnercode = achcount;
3901 if (StrEqual(ach[achcount][7], "gamble.png"))gamblecode = achcount;
3902 if (StrEqual(ach[achcount][7], "chat.png"))gamecode = achcount;
3903
3904 achcount++;
3905 }
3906}
3907
3908public void SQL_LoadGroups(Database db, DBResultSet results, const char[] error, any data)
3909{
3910 if (results == null)
3911 {
3912 LogError("Store error! Failed to load groups data to the table. Reason: %s", error);
3913 return;
3914 }
3915
3916 groupscount = 0;
3917
3918 while (results.FetchRow())
3919 {
3920 results.FetchString(0, groups[groupscount][0], sizeof(groups[][]));
3921 results.FetchString(1, groups[groupscount][1], sizeof(groups[][]));
3922 results.FetchString(2, groups[groupscount][2], sizeof(groups[][]));
3923 results.FetchString(3, groups[groupscount][3], sizeof(groups[][]));
3924 results.FetchString(4, groups[groupscount][4], sizeof(groups[][]));
3925
3926 LoadGroupItems(StringToInt(groups[groupscount][0]), groupscount);
3927 LoadGroupPlayerCount(StringToInt(groups[groupscount][0]), groupscount);
3928 LoadGroupPlayerList(StringToInt(groups[groupscount][0]), groupscount);
3929 Bganginvite[groupscount] = false;
3930 if (invitetimer[groupscount] != INVALID_HANDLE)
3931 {
3932 KillTimer(invitetimer[groupscount]);
3933 invitetimer[groupscount] = INVALID_HANDLE;
3934 }
3935
3936 groupscount++;
3937 }
3938}
3939
3940public void LoadGroupPlayerList(int GroupID, int GroupArrayID)
3941{
3942 char[] sQuery = new char[256];
3943 FormatEx(sQuery, 256, "SELECT * FROM `players` WHERE groupid = '%d'", GroupID);
3944 // PrintToChatAll("%s", sQuery);
3945 DB.Query(SQL_LoadGroupMembers, sQuery, GroupArrayID, DBPrio_High);
3946}
3947
3948public void SQL_LoadGroupMembers(Database db, DBResultSet results, const char[] error, any data)
3949{
3950 if (results == null)
3951 {
3952 LogError("Store error! Failed to load group member count (%s group). Reason: %s", groups[data][3], error);
3953 return;
3954 }
3955
3956 groupuserscount[data] = 0;
3957
3958 while (results.FetchRow())
3959 {
3960 results.FetchString(0, groupusers[data][groupuserscount[data]][0], sizeof(groupusers[][][]));
3961 results.FetchString(1, groupusers[data][groupuserscount[data]][1], sizeof(groupusers[][][]));
3962 // PrintToChatAll("%s | %s", groupusers[data][groupuserscount[data]][0], groupusers[data][groupuserscount[data]][1]);
3963 groupuserscount[data]++;
3964 }
3965}
3966
3967public void LoadGroupPlayerCount(int GroupID, int GroupArrayID)
3968{
3969 char[] sQuery = new char[256];
3970 //SELECT COUNT(*) FROM `players` WHERE groupid = '-1'
3971 FormatEx(sQuery, 256, "SELECT COUNT(*) FROM `players` WHERE groupid = '%d'", GroupID);
3972 DB.Query(SQL_LoadGroupMembersCount, sQuery, GroupArrayID, DBPrio_High);
3973}
3974
3975public void SQL_LoadGroupMembersCount(Database db, DBResultSet results, const char[] error, any data)
3976{
3977 if (results == null)
3978 {
3979 LogError("Store error! Failed to load group member count (%s group). Reason: %s", groups[data][3], error);
3980 return;
3981 }
3982
3983 while (results.FetchRow())
3984 {
3985 results.FetchString(0, groups[data][5], sizeof(groups[][]));
3986 }
3987}
3988
3989public void LoadGroupItems(int GroupID, int GroupArrayID)
3990{
3991 char[] sQuery = new char[256];
3992 //"SELECT * FROM `groups_items` WHERE `groupid` = '%s'", groups[groupscount][0];
3993 FormatEx(sQuery, 256, "SELECT * FROM `groups_items` WHERE `groupid` = '%d'", GroupID);
3994 DB.Query(SQL_LoadGroupItems, sQuery, GroupArrayID, DBPrio_High);
3995}
3996
3997public void SQL_LoadGroupItems(Database db, DBResultSet results, const char[] error, any data)
3998{
3999 if (results == null)
4000 {
4001 LogError("Store error! Failed to load group items data to the table (%s group). Reason: %s", groups[data][3], error);
4002 return;
4003 }
4004
4005 groupitemscount[data] = 0;
4006
4007 while (results.FetchRow())
4008 {
4009 results.FetchString(0, groupitems[data][groupitemscount[data]][0], sizeof(groupitems[][][]));
4010 results.FetchString(1, groupitems[data][groupitemscount[data]][1], sizeof(groupitems[][][]));
4011 results.FetchString(2, groupitems[data][groupitemscount[data]][2], sizeof(groupitems[][][]));
4012
4013 groupitemscount[data]++;
4014 }
4015}
4016
4017stock int GetGroupSpecificItemCount(const char[] ItemID, int GroupID)
4018{
4019 int GroupArrayID = ArrayIDFromGroupID(GroupID);
4020 if (GroupID == -1)return -10;
4021
4022 for (int i = 0; i < groupitemscount[GroupArrayID]; i++)
4023 if (StrEqual(groupitems[GroupArrayID][i][0], ItemID))return StringToInt(groupitems[GroupArrayID][i][2]);
4024
4025 return 0;
4026}
4027
4028stock int ArrayIDFromGroupID(int GroupID)
4029{
4030 for (int i = 0; i < groupscount; i++)
4031 if (StringToInt(groups[i][0]) == GroupID)return i;
4032
4033 return -1;
4034}
4035
4036stock bool IsGroupOwner(int client)
4037{
4038 if (groupid[client] == -1)return false;
4039
4040 int GroupArrayID = ArrayIDFromGroupID(groupid[client]);
4041
4042 if (GroupArrayID == -1)return false;
4043
4044 char[] sAuthID64 = new char[32];
4045 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
4046
4047 //for (int i = 0; i < groupscount; i++)
4048 //if (StrEqual(sAuthID64, groups[i][1]))return true;
4049
4050 if (StrEqual(sAuthID64, groups[GroupArrayID][1]))return true;
4051
4052 return false;
4053}
4054
4055public void UpdateGroup(int GroupID, int GroupCredits)
4056{
4057 int GroupArrayID = ArrayIDFromGroupID(GroupID);
4058 if (GroupArrayID != -1)
4059 {
4060
4061 char[] sQuery = new char[256];
4062 FormatEx(sQuery, 256, "UPDATE `groups` SET `credits` = '%d' WHERE `groupid` = '%d';", GroupCredits, GroupID);
4063
4064 DB.Query(SQL_UpdateGroup, sQuery);
4065
4066 Format(groups[GroupArrayID][4], sizeof(groups[][]), "%d", GroupCredits);
4067 }
4068}
4069
4070public void SQL_UpdateGroup(Database db, DBResultSet results, const char[] error, any data)
4071{
4072 if (results == null)
4073 {
4074 LogError("Store (cant update group info) SQL query failed. Reason: %s", error);
4075
4076 return;
4077 }
4078}
4079
4080stock bool IsStoreAdmin(const char[] sAuthID64, char[] name, int namesize)
4081{
4082 for (int i = 0; i < adminscount; i++)
4083 {
4084 if (StrEqual(storeadmin[i][0], sAuthID64))
4085 {
4086 strcopy(name, namesize, storeadmin[i][1]);
4087 return true;
4088 }
4089 }
4090
4091 return false;
4092}
4093
4094public void UpdateAch(int client, float count, int achid)
4095{
4096 char[] sAuthID64 = new char[32];
4097 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
4098 char id[32];
4099 Format(id, sizeof(id), "%s|%s", ach[achid][0], sAuthID64);
4100
4101 char[] sQuery = new char[256];
4102 FormatEx(sQuery, 256, "INSERT INTO `players_ach` (`id`, `achid`, `steamid`) VALUES ('%s', '%d', '%s') ON DUPLICATE KEY UPDATE `achid` = '%d';", id, StringToInt(ach[achid][0]), sAuthID64, StringToInt(ach[achid][0]));
4103 Handle data = CreateDataPack();
4104 WritePackCell(data, client);
4105 WritePackCell(data, achid);
4106 WritePackFloat(data, count);
4107 DB.Query(SQL_SetDefAch, sQuery, data, DBPrio_High);
4108}
4109
4110public void SQL_SetDefAch(Database db, DBResultSet results, const char[] error, Handle data)
4111{
4112 ResetPack(data);
4113 int client = ReadPackCell(data);
4114 int achid = ReadPackCell(data);
4115 if (results == null)
4116 {
4117
4118 if (client == 0)
4119 {
4120 LogError("Store error on SetDefAch! Failed to insert a disconnected player's data to the table. Reason: %s", error);
4121 }
4122
4123 else
4124 {
4125 LogError("Store error on SetDefAch! Failed to insert \"%N\"'s data to the table. Reason: %s", client, error);
4126 }
4127
4128 return;
4129 }
4130
4131 char[] sAuthID64 = new char[32];
4132 GetClientAuthId(client, AuthId_SteamID64, sAuthID64, 32);
4133
4134 char[] sQuery = new char[256];
4135
4136 FormatEx(sQuery, 256, "SELECT `count`, `level` FROM `players_ach` WHERE `steamid` = '%s' AND `achid` = '%d';", sAuthID64, StringToInt(ach[achid][0]));
4137 DB.Query(SQL_FindNotDefAch, sQuery, data, DBPrio_High);
4138}
4139
4140public void SQL_FindNotDefAch(Database db, DBResultSet results, const char[] error, Handle data)
4141{
4142 ResetPack(data);
4143 int client = ReadPackCell(data);
4144 int achid = ReadPackCell(data);
4145 float addcount = ReadPackFloat(data);
4146 if (results == null)
4147 {
4148 if (client == 0)
4149 {
4150 LogError("Store error on FindNotDefAch! Failed to select a disconnected player's data to the table. Reason: %s", error);
4151 }
4152
4153 else
4154 {
4155 LogError("Store error on FindNotDefAch! Failed to select \"%N\"'s data to the table. Reason: %s", client, error);
4156 }
4157 return;
4158 }
4159
4160 float count = 0.0;
4161 int level = 1;
4162
4163 while (results.FetchRow())
4164 {
4165 count = results.FetchFloat(0);
4166 level = results.FetchInt(1);
4167 }
4168
4169 int need = StringToInt(ach[achid][2]) + (level - 1) * StringToInt(ach[achid][3]);
4170 int creditsgift = StringToInt(ach[achid][4]) + (level - 1) * StringToInt(ach[achid][5]);
4171
4172 char[] sAuthID = new char[32];
4173 GetClientAuthId(client, AuthId_SteamID64, sAuthID, 32);
4174 char[] sQuery = new char[256];
4175
4176 if (count + addcount >= need)
4177 {
4178 FormatEx(sQuery, 256, "UPDATE `players_ach` SET `count` = '0.0', `level` = '%d' WHERE `steamid` = '%s' AND `achid` = '%d';", level + 1, sAuthID, StringToInt(ach[achid][0]));
4179
4180 UpdatePlayer(client, credits[client] + creditsgift);
4181 PrintToChat(client, "%s You complete %s achievement level %d (%d credits).", PREFIX, ach[achid][1], level, creditsgift);
4182 } else
4183 FormatEx(sQuery, 256, "UPDATE `players_ach` SET `count` = '%0.02f' WHERE `steamid` = '%s' AND `achid` = '%d';", (count + addcount), sAuthID, StringToInt(ach[achid][0]));
4184
4185 DB.Query(SQL_UpdatePlayer, sQuery);
4186}
4187
4188/*
4189* ============================ *
4190* ---------
4191* `players` - Table
4192* ---------
4193* `steamid` - Primary Key VARCHAR 32
4194* `name` - VARCHAR 32
4195* `credits` - INTEGER 16
4196* `lastjoin`- INTEGER 16
4197* `ip` - VARCHAR 16
4198* `groupid` - INTEGER 16
4199* ---------
4200* `players_items` - Table
4201* ---------
4202* `id` - Primary Key VARCHAR 32
4203* `itemid` - INTEGER 16
4204* `steamid` - VARCHAR 32
4205* `itemcount` - INTEGER 16
4206* `equip` - INTEGER 16 (0 no | 1 equipped)
4207* ---------
4208* `items` - Table
4209* ---------
4210* `id` - Primay Key AUTO_INCREMENT INTEGER 16
4211* `name` - VARCHAR 32
4212* `price` - INTEGER 16
4213* `type` - VARCHAR 16
4214* `team` - VARCHAR 16
4215* `vip` - INTEGER 2 (0 all | 1 only vip)
4216* `status` - INTEGER 2 (0 not available | 1 available)
4217* `mdl` - VARCHAR 256
4218* `rgb` - VARCHAR 32 (200,200,200)
4219* ---------
4220* `storeadmin` - Table
4221* ---------
4222* `steamid` - Primary Key VARCHAR 32
4223* `name` - VARCHAR 32
4224* `password` - VARCHAR 128
4225* `group` - VARCHAR 32
4226* ----------
4227* `player_logs` - Table
4228* ----------
4229* `id` - Primary Key AUTO_INCREEMENT INTEGER 16
4230* `steamid` - VARCHAR 32
4231* `name` - VARCHAR 32
4232* `log` - VARCHAR 128
4233* `unix_date` - INTEGER 32
4234* ----------
4235* `storevip`
4236* ----------
4237* `steamid` - Primary Key VARCHAR 32
4238* `name` - VARCHAR 32
4239* `endtime` - VARCHAR 32
4240* ----------
4241* `storedaily`
4242* ----------
4243* `steamid` - Primary Key VARCHAR 32
4244* `name` - VARCHAR 32
4245* `lastdaily` - INTEGER 32
4246* ----------
4247* `ach`
4248* ----------
4249* `id` - Primary Key INTEGER 32
4250* `name` - VARCHAR 32
4251* `startcount` - INTEGER 32
4252* `jumpcount` - INTEGER 32
4253* `startcredits` - INTEGER 32
4254* `jumpcredits` - INTEGER 32
4255* `details` - VARCHAR 16
4256* `img` - VARCHAR 256
4257* -----------
4258* `players_ach`
4259* -----------
4260* `id` - VARCHAR32
4261* `achid` - INTEGER 16
4262* `steamid` - VARCHAR 32
4263* `level` - INTEGER 16
4264* `count` - FLOAT 16
4265* -----------
4266* `groups`
4267* -----------
4268* `groupid` - AUTO_INCREMENT INTEGER 16
4269* `ownerid` - VARCHAR 32
4270* `ownername` - VARCHAR 32
4271* `name` - VARCHAR 32
4272* `credits` - INTEGER 16
4273* ============================ *
4274*/
4275
4276/*CREATE TABLE IF NOT EXISTS `groups` (`groupid` INTEGER(16) NOT NULL AUTO_INCREMENT, `ownerid` VARCHAR(32) NOT NULL, `ownername` VARCHAR(32) NOT NULL DEFAULT '< blank >', `name` VARCHAR(32) NOT NULL, `credits` INTEGER(16) NOT NULL DEFAULT '0', PRIMARY KEY(`groupid`))
4277------------------------------------------------------------------------------------------------------
4278CREATE TABLE IF NOT EXISTS `groups_items` (`itemid` VARCHAR(32) NOT NULL, `groupid` VARCHAR(32) NOT NULL, `itemcount` INTEGER(16) NOT NULL DEFAULT '0', PRIMARY KEY(`itemid`, `groupid`));
4279*/
4280
4281public void Store_DBConnect()
4282{
4283 if (DB != null)
4284 {
4285 delete DB;
4286 }
4287
4288 if (SQL_CheckConfig("Gamers_Store"))
4289 {
4290 char[] sError = new char[255];
4291
4292 if (!(DB = SQL_Connect("Gamers_Store", true, sError, 255)))
4293 {
4294 SetFailState("Store startup failed. Reason: %s", sError);
4295 }
4296
4297 DB.SetCharset("utf8");
4298 char querysend[512];
4299 Format(querysend, sizeof(querysend), "CREATE TABLE IF NOT EXISTS `players` (`steamid` VARCHAR(32) NOT NULL, `name` VARCHAR(32) NOT NULL DEFAULT '< blank >', `credits` INTEGER(16) NOT NULL DEFAULT '0', `lastjoin` INTEGER(16) NOT NULL DEFAULT '0', `ip` VARCHAR(16) NOT NULL DEFAULT '1.1.1.1', `groupid` INTEGER(16) NOT NULL DEFAULT '-1', PRIMARY KEY(`steamid`));");
4300 DB.Query(SQL_CreateTablecb, querysend, 0, DBPrio_High);
4301 Format(querysend, sizeof(querysend), "CREATE TABLE IF NOT EXISTS `players_items` (`id` VARCHAR(32) NOT NULL, `itemid` INTEGER(16) NOT NULL, `steamid` VARCHAR(32) NOT NULL DEFAULT '< blank >', `itemcount` INTEGER(16) NOT NULL DEFAULT '0', `equip` INTEGER(2) NOT NULL DEFAULT '0', PRIMARY KEY(`id`));");
4302 DB.Query(SQL_CreateTablecb, querysend, 0, DBPrio_High);
4303 Format(querysend, sizeof(querysend), "CREATE TABLE IF NOT EXISTS `items` (`id` INTEGER(16) NOT NULL AUTO_INCREMENT, `name` VARCHAR(32) NOT NULL, `price` INTEGER(16) NOT NULL, `type` VARCHAR(16) NOT NULL, `team` VARCHAR(16) NOT NULL DEFAULT 'both', `vip` INTEGER(2) NOT NULL DEFAULT '0', `status` INTEGER(2) NOT NULL DEFAULT '1', `mdl` VARCHAR(256) NOT NULL, `rgb` VARCHAR(32) NOT NULL DEFAULT '255,0,0', PRIMARY KEY(`id`));");
4304 DB.Query(SQL_CreateTablecb, querysend, 0, DBPrio_High);
4305 Format(querysend, sizeof(querysend), "CREATE TABLE IF NOT EXISTS `storeadmin` (`steamid` VARCHAR(32) NOT NULL, `name` VARCHAR(32) NOT NULL, `password` VARCHAR(128) NOT NULL, `group` VARCHAR(32) NOT NULL DEFAULT 'normal', PRIMARY KEY(`steamid`));");
4306 DB.Query(SQL_CreateTablecb, querysend, 0, DBPrio_High);
4307 Format(querysend, sizeof(querysend), "CREATE TABLE IF NOT EXISTS `players_logs` (`id` INTEGER(16) NOT NULL AUTO_INCREMENT, `steamid` VARCHAR(32) NOT NULL, `name` VARCHAR(32) NOT NULL, `log` VARCHAR(128) NOT NULL, `unix_date` INTEGER(32) NOT NULL, PRIMARY KEY(`id`));");
4308 DB.Query(SQL_CreateTablecb, querysend, 0, DBPrio_High);
4309 Format(querysend, sizeof(querysend), "CREATE TABLE IF NOT EXISTS `storevip` (`steamid` VARCHAR(32) NOT NULL, `name` VARCHAR(32) NOT NULL, `endtime` INTEGER(32) NOT NULL, `credits` INTEGER(16) NOT NULL DEFAULT '0', PRIMARY KEY(`steamid`));");
4310 DB.Query(SQL_CreateTablecb, querysend, 0, DBPrio_High);
4311 Format(querysend, sizeof(querysend), "CREATE TABLE IF NOT EXISTS `storedaily` (`steamid` VARCHAR(32) NOT NULL, `name` VARCHAR(32) NOT NULL, `lastdaily` INTEGER(32) NOT NULL, PRIMARY KEY(`steamid`));");
4312 DB.Query(SQL_CreateTablecb, querysend, 0, DBPrio_High);
4313 Format(querysend, sizeof(querysend), "CREATE TABLE IF NOT EXISTS `ach` (`id` INTEGER(16) NOT NULL AUTO_INCREMENT, `name` VARCHAR(32) NOT NULL, `startcount` INTEGER(16) NOT NULL, `jumpcount` INTEGER(16) NOT NULL, `startcredits` INTEGER(16) NOT NULL, `jumpcredits` INTEGER(16) NOT NULL, `details` VARCHAR(64) NOT NULL, `img` VARCHAR(256) NOT NULL, PRIMARY KEY(`id`));");
4314 DB.Query(SQL_CreateTablecb, querysend, 0, DBPrio_High);
4315 Format(querysend, sizeof(querysend), "CREATE TABLE IF NOT EXISTS `players_ach` (`id` VARCHAR(32) NOT NULL, `achid` INTEGER(16) NOT NULL, `steamid` VARCHAR(32) NOT NULL DEFAULT '< blank >', `level` INTEGER(16) NOT NULL DEFAULT '1', `count` FLOAT(16) NOT NULL DEFAULT '0.0', PRIMARY KEY(`id`));");
4316 DB.Query(SQL_CreateTablecb, querysend, 0, DBPrio_High);
4317 Format(querysend, sizeof(querysend), "CREATE TABLE IF NOT EXISTS `groups` (`groupid` INTEGER(16) NOT NULL AUTO_INCREMENT, `ownerid` VARCHAR(32) NOT NULL, `ownername` VARCHAR(32) NOT NULL DEFAULT '< blank >', `name` VARCHAR(32) NOT NULL, `credits` INTEGER(16) NOT NULL DEFAULT '0', PRIMARY KEY(`groupid`));");
4318 DB.Query(SQL_CreateTablecb, querysend, 0, DBPrio_High);
4319 Format(querysend, sizeof(querysend), "CREATE TABLE IF NOT EXISTS `groups_items` (`itemid` VARCHAR(32) NOT NULL, `groupid` VARCHAR(32) NOT NULL, `itemcount` INTEGER(16) NOT NULL DEFAULT '0', PRIMARY KEY(`itemid`, `groupid`));");
4320 DB.Query(SQL_CreateTablecb, querysend, 0, DBPrio_High);
4321
4322 }
4323
4324 else
4325 {
4326 SetFailState("Store startup failed. Reason: %s", "\"Gamers_Store\" is not a specified entry in databases.cfg.");
4327 }
4328}
4329
4330public void SQL_CreateTablecb(Database db, DBResultSet results, const char[] error, any data)
4331{
4332 if (results == null)
4333 {
4334 LogError("Store error! Data table creation failed. Reason: %s", error);
4335
4336 return;
4337 }
4338}
4339
4340public void StartMissingLetter()
4341{
4342 int iRandomLine = Math_GetRandomInt(1, wordsfilelinecount);
4343
4344 char szLineText[128];
4345 ReadSpecificLine(wordsfile, iRandomLine, szLineText, sizeof(szLineText));
4346
4347 ExplodeString(szLineText, " ", missingletterans, sizeof(missingletterans), sizeof missingletterans[]);
4348
4349 StripQuotes(missingletterans[0]);
4350
4351 if (!missingletterans[0][0]
4352 || missingletterans[0][0] == '\"'
4353 || missingletterans[0][0] == ' '
4354 || strlen(missingletterans[0]) < 2
4355 || StrEqual(missingletterans[0], "_")
4356 || StrContains(missingletterans[0], "\"") != -1) //"
4357 {
4358 StartMissingLetter();
4359
4360 return;
4361 //break;
4362 }
4363
4364 strcopy(missingletterans[1], sizeof(missingletterans[]), missingletterans[0]);
4365
4366 int iLength = strlen(missingletterans[0]);
4367
4368 int iMissing[2];
4369
4370 while (iMissing[0] == iMissing[1])
4371 {
4372 iMissing[0] = GetRandomInt(0, iLength - 1);
4373 iMissing[1] = GetRandomInt(0, iLength - 1);
4374 }
4375
4376 missingletterans[0][iMissing[0]] = '_';
4377
4378 if (iLength > 5)
4379 {
4380 missingletterans[0][iMissing[1]] = '_';
4381 }
4382
4383 PrintToChatAll("%s The missingword is - %s (%d credits)", PREFIX, missingletterans[0], gamecredits);
4384}
4385
4386public void StartTranslateGame()
4387{
4388 int iRandomLine = Math_GetRandomInt(1, wordsfilelinecount);
4389
4390 char szLineText[128];
4391 ReadSpecificLine(wordsfile, iRandomLine, szLineText, sizeof(szLineText));
4392
4393 ExplodeString(szLineText, " ", translateans, sizeof(translateans), sizeof translateans[]);
4394
4395 for (new i; i < sizeof(translateans); i++)
4396 {
4397 StripQuotes(translateans[i]);
4398
4399 if (i == 2)
4400 {
4401 ReplaceStringEx(translateans[i], 49, "\"", ""); // \" fix color bug with Notepad++
4402 ReplaceStringEx(translateans[i], 49, "\"", ""); // \" fix color bug with Notepad++
4403
4404 TrimString(translateans[i]);
4405 }
4406 }
4407
4408 for (new i; i < sizeof(translateans); i++)
4409 {
4410 if (!translateans[i][0]
4411 || translateans[i][0] == '\"'
4412 || translateans[i][0] == ' '
4413 || strlen(translateans[i]) < 2
4414 || StrContains(translateans[i], "\"") != -1) //"
4415 {
4416 StartTranslateGame();
4417
4418 return;
4419 //break;
4420 }
4421 }
4422
4423 PrintToChatAll("%s The word is - %s (%d credits)", PREFIX, translateans[0], gamecredits);
4424}
4425
4426bool IsValidClient(int client)
4427{
4428 return (client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client));
4429}
4430
4431stock GetFileMaxLines(const char[] file)
4432{
4433 Handle hFile = OpenFile(file, "r");
4434
4435 if (hFile == INVALID_HANDLE)
4436 {
4437 LogError("Couldn't read a game file!");
4438
4439 return false;
4440 }
4441
4442 char sBuffer[30]; // sBuffer[ 1 ]; DONT CHANGE
4443
4444 int iMaxLines = 0;
4445
4446 while (!IsEndOfFile(hFile) && ReadFileLine(hFile, sBuffer, sizeof(sBuffer)))
4447 {
4448 iMaxLines++;
4449 }
4450
4451 CloseHandle(hFile);
4452
4453 return iMaxLines;
4454}
4455
4456stock bool ReadSpecificLine(const char[] file, int line, char[] text, int maxlength)
4457{
4458 Handle hFile = OpenFile(file, "r");
4459
4460 if (line == 1)
4461 {
4462 ReadFileLine(hFile, text, maxlength);
4463 CloseHandle(hFile);
4464 return true;
4465 }
4466
4467 int index = 0;
4468
4469 char sBuffer[30]; // sBuffer[ 1 ]; DONT CHANGE
4470
4471 while (ReadFileLine(hFile, sBuffer, sizeof(sBuffer)))
4472 {
4473 index++;
4474 if (line == (index + 1))
4475 {
4476 break;
4477 }
4478 if (IsEndOfFile(hFile))
4479 {
4480 CloseHandle(hFile);
4481 return false;
4482 }
4483 }
4484
4485 ReadFileLine(hFile, text, maxlength);
4486 CloseHandle(hFile);
4487 return true;
4488}
4489//Store_PrintToChatAll(client, "got nothing from the case opening");
4490public void Store_PrintToChatAll(int client, const char[] message)
4491{
4492 PrintToChat(client, "%s You %s", PREFIX, message);
4493
4494 for (int i = 1; i <= MaxClients; i++)
4495 if (IsValidClient(i) && i != client)
4496 PrintToChat(i, "%s %N %s", PREFIX, client, message);
4497}