· 7 years ago · Jan 13, 2019, 04:08 PM
1/* [CS:GO] Jailbreak Gangs
2 *
3 * Copyright (C) 2017 Michael Flaherty // michaelwflaherty.com // michaelwflaherty@me.com
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation, either version 3 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see http://www.gnu.org/licenses/.
16 */
17
18#include <sourcemod>
19#include <sdkhooks>
20#include <sdktools>
21#include <autoexecconfig>
22#include <hl_gangs>
23
24#undef REQUIRE_PLUGIN
25#include <store>
26#define REQUIRE_PLUGIN
27
28#define TAG " \x03[Clans]\x04"
29
30/* Compiler Instructions */
31#pragma semicolon 1
32#pragma newdecls required
33
34/* ConVars */
35ConVar gcv_bPluginEnabled;
36ConVar gcv_sDatabase;
37ConVar gcv_iMaxGangSize;
38ConVar gcv_bInviteStyle;
39ConVar gcv_iHealthPrice;
40ConVar gcv_iCashPrice;
41ConVar gcv_iStorePrice;
42ConVar gcv_iMedishotPrice;
43ConVar gcv_iCreateGangPrice;
44ConVar gcv_iRenamePrice;
45ConVar gcv_iSizePrice;
46ConVar gcv_iPriceModifier;
47ConVar gcv_bDisableMedishot;
48ConVar gcv_bDisableStore;
49ConVar gcv_bDisableHealth;
50ConVar gcv_bDisableCash;
51ConVar gcv_bDisableSize;
52ConVar gcv_fStoreModifier;
53ConVar gcv_fHealthModifier;
54ConVar gcv_iGangSizeMaxUpgrades;
55
56/* Forwards */
57Handle g_hOnMainMenu;
58Handle g_hOnMainMenuCallback;
59Handle g_hOnPerkMenu;
60Handle g_hOnPerkMenuCallback;
61Handle g_hOnGangPerksSetPre;
62
63/* Gang Globals */
64GangRank ga_iRank[MAXPLAYERS + 1] = {Rank_Invalid, ...};
65int ga_iGangSize[MAXPLAYERS + 1] = {-1, ...};
66int ga_iInvitation[MAXPLAYERS + 1] = {-1, ...};
67int ga_iDateJoined[MAXPLAYERS + 1] = {-1, ...};
68int ga_iFunds[MAXPLAYERS + 1] = {0, ...};
69int ga_iHealth[MAXPLAYERS + 1] = {0, ...};
70int ga_iCash[MAXPLAYERS + 1] = {0, ...};
71int ga_iStore[MAXPLAYERS + 1] = {0, ...};
72int ga_iMedishot[MAXPLAYERS + 1] = {0, ...};
73int ga_iSize[MAXPLAYERS + 1] = {0, ...};
74int ga_iTempInt[MAXPLAYERS + 1] = {0, ...};
75int ga_iTempInt2[MAXPLAYERS + 1] = {0, ...};
76int g_iGangAmmount = 0;
77
78
79int KickShare[MAXPLAYERS + 1] = {0, ...};
80
81int ga_iShare[MAXPLAYERS + 1] = {0, ...};
82
83char ga_sGangName[MAXPLAYERS + 1][128];
84char ga_sInvitedBy[MAXPLAYERS + 1][128];
85
86bool ga_bSetName[MAXPLAYERS + 1] = {false, ...};
87bool ga_bIsPlayerInDatabase[MAXPLAYERS + 1] = {false, ...};
88bool ga_bIsGangInDatabase[MAXPLAYERS + 1] = {false, ...};
89bool ga_bHasGang[MAXPLAYERS + 1] = {false, ...};
90bool ga_bRename[MAXPLAYERS + 1] = {false, ...};
91
92/* Supported Store Modules */
93bool g_bZepyhrus = false;
94bool g_bShanapu = false;
95bool g_bDefault = false;
96bool g_bFrozdark = false;
97
98
99/* Player Globals */
100char ga_sSteamID[MAXPLAYERS + 1][30];
101bool g_bLateLoad = false;
102bool ga_bLoaded[MAXPLAYERS + 1] = {false, ...};
103
104/* Database Globals */
105Database g_hDatabase = null;
106char g_sDatabaseName[60];
107
108public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int err_max)
109{
110 MarkNativeAsOptional("Store_GetClientCredits");
111 MarkNativeAsOptional("Store_SetClientCredits");
112 MarkNativeAsOptional("Gangs_GetCredits");
113 MarkNativeAsOptional("Gangs_SetCredits");
114 MarkNativeAsOptional("MyJailShop_SetCredits");
115 MarkNativeAsOptional("MyJailShop_GetCredits");
116
117
118 CreateNative("Gangs_GetGangName", Native_GetGangName);
119 CreateNative("Gangs_GetGangRank", Native_GetGangRank);
120 CreateNative("Gangs_HasGang", Native_HasGang);
121 CreateNative("Gangs_GetGangSize", Native_GetGangSize);
122 CreateNative("Gangs_Message", Native_Message);
123 CreateNative("Gangs_MessageToAll", Native_MessageToAll);
124
125 RegPluginLibrary("hl_gangs");
126
127 g_bLateLoad = bLate;
128 return APLRes_Success;
129}
130
131public int Native_MessageToAll(Handle plugin, int numParams)
132{
133 char phrase[1024];
134 int bytes;
135
136 FormatNativeString(0, 1, 2, sizeof(phrase), bytes, phrase);
137
138 PrintToChatAll("%s %s", TAG, phrase);
139}
140
141public int Native_Message(Handle plugin, int numParams)
142{
143 int client = GetNativeCell(1);
144
145 if (!IsValidClient(client))
146 {
147 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%i)", client);
148 }
149
150 char phrase[1024];
151 int bytes;
152
153 FormatNativeString(0, 2, 3, sizeof(phrase), bytes, phrase);
154
155 PrintToChat(client, "%s %s", TAG, phrase);
156 return 0;
157}
158
159public int Native_GetGangName(Handle plugin, int numParams)
160{
161 int client = GetNativeCell(1);
162
163 if (!IsValidClient(client))
164 {
165 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%i)", client);
166 }
167
168 SetNativeString(2, ga_sGangName[client], GetNativeCell(3));
169 return 0;
170}
171
172public int Native_GetGangRank(Handle plugin, int numParams)
173{
174 int client = GetNativeCell(1);
175
176 if (!IsValidClient(client))
177 {
178 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%i)", client);
179 }
180
181 return view_as<int>(ga_iRank[client]);
182}
183
184public int Native_HasGang(Handle plugin, int numParams)
185{
186 int client = GetNativeCell(1);
187
188 if (!IsValidClient(client))
189 {
190 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%i)", client);
191 }
192
193 return view_as<int>(ga_bHasGang[client]);
194}
195
196public int Native_GetGangSize(Handle plugin, int numParams)
197{
198 int client = GetNativeCell(1);
199
200 if (!IsValidClient(client))
201 {
202 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%i)", client);
203 }
204
205 return ga_iGangSize[client];
206}
207
208public Plugin myinfo =
209{
210 name = "[CS:GO/CS:S] Jailbreak Gangs",
211 author = "Headline",
212 description = "An SQL-based gang plugin",
213 version = GANGS_VERSION,
214 url = "http://michaelwflaherty.com"
215};
216
217public void OnPluginStart()
218{
219 LoadTranslations("hl_gangs.phrases");
220 LoadTranslations("core.phrases");
221 LoadTranslations("common.phrases");
222
223 AutoExecConfig_SetFile("hl_gangs");
224
225 AutoExecConfig_CreateConVar("hl_gangs_version", GANGS_VERSION, "Headline's Gangs Plugin : Version", FCVAR_NOTIFY|FCVAR_DONTRECORD);
226
227 gcv_bPluginEnabled = AutoExecConfig_CreateConVar("hl_gangs_enabled", "1", "Enable the plugin? (1 = Yes, 0 = No)", FCVAR_NOTIFY, true, 0.0, true, 1.0);
228
229 gcv_bInviteStyle = AutoExecConfig_CreateConVar("hl_gangs_invite_style", "1", "Set invite style to pop up a Menu? \n (1 = Menu, 0 = Registered Command)", FCVAR_NOTIFY, true, 0.0, true, 1.0);
230
231 gcv_sDatabase = AutoExecConfig_CreateConVar("hl_gangs_database_name", "hl_gangs", "Name of the database for the plugin.");
232
233 gcv_iMaxGangSize = AutoExecConfig_CreateConVar("hl_gangs_max_size", "3", "Initial size for a gang");
234
235 gcv_iSizePrice = AutoExecConfig_CreateConVar("hl_gangs_size_price", "20000", "Price of the Size perk");
236
237 gcv_iPriceModifier = AutoExecConfig_CreateConVar("hl_gangs_price_modifier", "30000", "Price modifier for perks\n Set 0 to disable");
238
239 gcv_iGangSizeMaxUpgrades = AutoExecConfig_CreateConVar("hl_gangs_size_max_upgrades", "6", "The maximum amount of size upgrades that may occur");
240
241 gcv_iHealthPrice = AutoExecConfig_CreateConVar("hl_gangs_health_price", "10000", "Price of the Health perk");
242
243 gcv_fHealthModifier = AutoExecConfig_CreateConVar("hl_gangs_health_modifier", "10", "Health perk modifier. 1.0 default");
244
245 gcv_iCashPrice = AutoExecConfig_CreateConVar("hl_gangs_cash_price", "20000", "Price of the Cash perk");
246
247 gcv_iStorePrice = AutoExecConfig_CreateConVar("hl_gangs_store_price", "20000", "Price of the Store perk");
248
249 gcv_fStoreModifier = AutoExecConfig_CreateConVar("hl_gangs_store_modifier", "1", "Store perk modifier. 0.02 default");
250
251 gcv_iMedishotPrice = AutoExecConfig_CreateConVar("hl_gangs_medishot_price", "15000", "Price of the Medishot perk");
252
253
254 gcv_iCreateGangPrice = AutoExecConfig_CreateConVar("hl_gangs_creation_price", "500", "Price of gang creation");
255
256 gcv_iRenamePrice = AutoExecConfig_CreateConVar("hl_gangs_rename_price", "50000", "Price to rename");
257
258
259 /* Perk Disabling */
260 gcv_bDisableCash = AutoExecConfig_CreateConVar("hl_gangs_cash", "0", "Disable the cash perk?\n Set 1 to disable");
261 gcv_bDisableHealth = AutoExecConfig_CreateConVar("hl_gangs_health", "0", "Disable the health perk?\n Set 1 to disable");
262 gcv_bDisableMedishot = AutoExecConfig_CreateConVar("hl_gangs_medishot", "0", "Disable the medishot perk?\n Set 1 to disable");
263 gcv_bDisableStore = AutoExecConfig_CreateConVar("hl_gangs_store", "0", "Disable the store perk?\n Set 1 to disable");
264 gcv_bDisableSize = AutoExecConfig_CreateConVar("hl_gangs_size", "0", "Disable the size perk?\n Set 1 to disable");
265
266 AutoExecConfig_ExecuteFile();
267 AutoExecConfig_CleanFile();
268
269 gcv_sDatabase.GetString(g_sDatabaseName, sizeof(g_sDatabaseName));
270
271
272 /* Forwards */
273 g_hOnMainMenuCallback = CreateGlobalForward("Gangs_OnMenuCallback", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
274 g_hOnMainMenu = CreateGlobalForward("Gangs_OnMenuCreated", ET_Ignore, Param_Cell, Param_Cell);
275 g_hOnPerkMenuCallback = CreateGlobalForward("Gangs_OnPerkMenuCallback", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
276 g_hOnPerkMenu = CreateGlobalForward("Gangs_OnPerkMenuCreated", ET_Ignore, Param_Cell, Param_Cell);
277 g_hOnGangPerksSetPre = CreateGlobalForward("Gangs_OnPerksSetPre", ET_Ignore, Param_Cell, Param_CellByRef);
278
279 /* Events */
280 HookEvent("player_spawn", Event_PlayerSpawn);
281 HookEvent("round_start", Event_RoundStart);
282 HookEvent("round_end", Event_RoundEnd);
283
284 RegConsoleCmd("sm_gang", Command_Gang, "Open the gang menu!");
285 RegConsoleCmd("sm_gangs", Command_Gang, "Open the gang menu!");
286 RegConsoleCmd("sm_clan", Command_Gang, "Open the gang menu!");
287 RegConsoleCmd("sm_clans", Command_Gang, "Open the gang menu!");
288 RegConsoleCmd("sm_klan", Command_Gang, "Open the gang menu!");
289 RegConsoleCmd("sm_klany", Command_Gang, "Open the gang menu!");
290 RegConsoleCmd("sm_addfunds", sm_addfunds);
291 RegConsoleCmd("sm_bank", sm_addfunds);
292
293 if (gcv_bInviteStyle.BoolValue)
294 {
295 RegConsoleCmd("sm_accept", Command_Accept, "Accept an invitation!");
296 }
297
298 AddCommandListener(OnSay, "say");
299 AddCommandListener(OnSay, "say_team");
300
301 for(int i = 1; i <= MaxClients; i++)
302 {
303 if(IsValidClient(i))
304 {
305 LoadSteamID(i);
306 OnClientPutInServer(i);
307 }
308 }
309
310 g_bZepyhrus = LibraryExists("store_zephyrus");
311 if (g_bZepyhrus)
312 {
313 return; // Don't bother checking if others exist
314 }
315
316 g_bShanapu = LibraryExists("myjailshop");
317 if (g_bShanapu)
318 {
319 return; // Don't bother checking if others exist
320 }
321
322 g_bFrozdark = LibraryExists("shop");
323 if (g_bFrozdark)
324 {
325 return; // Don't bother checking if others exist
326 }
327
328 /* Stores */
329 g_bDefault = LibraryExists("hl_gangs_credits");
330 if (g_bDefault)
331 {
332 return; // Don't bother checking if others exist
333 }
334}
335
336public void OnClientConnected(int client)
337{
338 if (gcv_bPluginEnabled.BoolValue)
339 {
340 ResetVariables(client);
341 }
342
343 if (ga_iStore[client] != 0 && !gcv_bDisableStore.BoolValue)
344 {
345 Store_SetClientCredits(client, (Store_GetClientCredits(client) + gcv_fStoreModifier.IntValue * ga_iStore[client]));
346 CreateTimer(30.0, Timer_GrantStore, GetClientUserId(client), TIMER_REPEAT);
347 }
348
349}
350
351public void OnClientDisconnect(int client)
352{
353 if (gcv_bPluginEnabled.BoolValue)
354 {
355 UpdateSQL(client);
356
357 ResetVariables(client);
358 }
359}
360
361public void OnConfigsExecuted()
362{
363 if (gcv_bPluginEnabled.BoolValue)
364 {
365 if (g_hDatabase == null)
366 {
367 SetDB();
368 }
369 if (g_bLateLoad)
370 {
371 for (int i = 1; i <= MaxClients; i++)
372 {
373 if (IsValidClient(i))
374 {
375 GetClientAuthId(i, AuthId_Steam2, ga_sSteamID[i], sizeof(ga_sSteamID[]));
376
377 if (StrContains(ga_sSteamID[i], "STEAM_", true) != -1)
378 {
379 LoadSteamID(i);
380 }
381 else
382 {
383 CreateTimer(10.0, RefreshSteamID, GetClientUserId(i), TIMER_FLAG_NO_MAPCHANGE);
384 }
385 }
386 }
387 }
388 }
389}
390
391public Action Timer_GiveHealth(Handle timer, any client)
392{
393 if (ga_iHealth[client] != 0 && !gcv_bDisableHealth.BoolValue)
394 {
395 int iHealth = ga_iHealth[client] * gcv_fHealthModifier.IntValue + GetClientHealth(client);
396 SetEntProp(client, Prop_Send, "m_iHealth", iHealth);
397 }
398 if (ga_iMedishot[client] != 0 && !gcv_bDisableMedishot.BoolValue)
399 {
400 GivePlayerItem(client, "weapon_healthshot");
401 }
402}
403
404public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
405{
406 CreateTimer(5.0, GiveExtraCash);
407}
408
409public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
410{
411 for(int i = 1; i <= MaxClients; i++)
412 {
413 if(IsValidClient(i))
414 {
415 if(ga_bHasGang[i])
416 {
417 LoadSteamID(i);
418 PrintToChat(i, "1. Runda skończona, odpalam LoadSteamID");
419 }
420 }
421 }
422}
423
424public Action GiveExtraCash(Handle timer)
425{
426 for(int i; i < MAXPLAYERS + 1; i++)
427 {
428 if(ga_iCash[i] > 0)
429 {
430 int g_iToolsAccount = FindSendPropInfo("CCSPlayer", "m_iAccount");
431
432 int cash = GetEntData(i, g_iToolsAccount, 4);
433
434 cash = cash + (ga_iCash[i]*2000);
435
436 SetEntData(i, g_iToolsAccount, cash, 4);
437 }
438 }
439}
440
441public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
442{
443 int client = GetClientOfUserId(event.GetInt("userid"));
444
445
446 if (IsValidClient(client))
447 {
448 if (ga_bHasGang[client])
449 {
450 bool shouldSetPerks = true;
451 Call_StartForward(g_hOnGangPerksSetPre);
452 Call_PushCell(client);
453 Call_PushCellRef(shouldSetPerks);
454 Call_Finish();
455
456 if (!shouldSetPerks)
457 {
458 return Plugin_Continue;
459 }
460 CreateTimer(2.0, Timer_GiveHealth, client);
461 }
462 }
463
464 return Plugin_Continue;
465}
466
467public Action Timer_GrantStore(Handle hHandle, int iUserid)
468{
469 int client = GetClientOfUserId(iUserid);
470 if (ga_iStore[client] != 0 && !gcv_bDisableStore.BoolValue)
471 {
472 Store_SetClientCredits(client, (Store_GetClientCredits(client) + gcv_fStoreModifier.IntValue * ga_iStore[client]));
473 }
474 return Plugin_Continue;
475}
476
477
478public Action RefreshSteamID(Handle hTimer, int iUserID)
479{
480 int client = GetClientOfUserId(iUserID);
481 if (!IsValidClient(client))
482 {
483 return;
484 }
485
486 GetClientAuthId(client, AuthId_Steam2, ga_sSteamID[client], sizeof(ga_sSteamID[]));
487
488 if (StrContains(ga_sSteamID[client], "STEAM_", true) == -1) //still invalid - retry again
489 {
490
491 CreateTimer(10.0, RefreshSteamID, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
492 }
493 else
494 {
495 LoadSteamID(client);
496 PrintToChat(client, "~Odpaliło się RefreshSteamID, które uruchamia LoadSteamID");
497 }
498}
499
500public void OnClientPutInServer(int client)
501{
502 if (IsValidClient(client))
503 {
504 CreateTimer(2.0, Timer_AlertGang, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
505 }
506}
507
508public Action Timer_AlertGang(Handle hTimer, int userid)
509{
510 int client = GetClientOfUserId(userid);
511
512 if (!IsValidClient(client))
513 {
514 return;
515 }
516
517 char name[MAX_NAME_LENGTH];
518 GetClientName(client, name, sizeof(name));
519 PrintToGang(client, false, "%s %T", TAG, "GangAlert", LANG_SERVER, name);
520}
521
522public void OnClientPostAdminCheck(int client)
523{
524 if (gcv_bPluginEnabled.BoolValue)
525 {
526 LoadSteamID(client);
527 PrintToChat(client, "~Odpalono LoadSteamID z funkcji OnClientPostAdminCheck");
528 }
529}
530
531public void OnLibraryAdded(const char[] name)
532{
533 if (StrEqual(name, "store_zephyrus"))
534 {
535 g_bZepyhrus = true;
536 }
537 else if (StrEqual(name, "myjailshop"))
538 {
539 g_bShanapu = true;
540 }
541 else if (StrEqual(name, "shop"))
542 {
543 g_bFrozdark = true;
544 }
545 else if (StrEqual(name, "hl_gangs_credits"))
546 {
547 g_bDefault = true;
548 }
549}
550
551public void OnLibraryRemoved(const char[] name)
552{
553 if (StrEqual(name, "store_zephyrus"))
554 {
555 g_bZepyhrus = false;
556 }
557 else if (StrEqual(name, "myjailshop"))
558 {
559 g_bShanapu = false;
560 }
561 else if (StrEqual(name, "shop"))
562 {
563 g_bFrozdark = false;
564 }
565 else if (StrEqual(name, "hl_gangs_credits"))
566 {
567 g_bDefault = false;
568 }
569}
570
571/* SQL Callback On First Connection */
572public void SQLCallback_Connect(Database db, const char[] error, any data)
573{
574 if (db == null)
575 {
576 SetFailState(error);
577 }
578 else
579 {
580 g_hDatabase = db;
581
582 g_hDatabase.Query(SQLCallback_Void, "CREATE TABLE IF NOT EXISTS `hl_gangs_players` (`id` int(20) NOT NULL AUTO_INCREMENT, `steamid` varchar(32) NOT NULL, `playername` varchar(32) NOT NULL, `gang` varchar(32) NOT NULL, `rank` int(16) NOT NULL, `invitedby` varchar(32) NOT NULL, `date` int(32) NOT NULL, `share` int(20) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1", 1);
583 g_hDatabase.Query(SQLCallback_Void, "CREATE TABLE IF NOT EXISTS `hl_gangs_groups` (`id` int(20) NOT NULL AUTO_INCREMENT, `gang` varchar(32) NOT NULL, `health` int(16) NOT NULL, `cash` int(16) NOT NULL, `store` int(16) NOT NULL, `medishot` int(16) NOT NULL, `size` int(16) NOT NULL, `funds` int(20) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1", 1);
584 g_hDatabase.Query(SQLCallback_Void, "CREATE TABLE IF NOT EXISTS `hl_gangs_statistics` (`id` int(20) NOT NULL AUTO_INCREMENT, `gang` varchar(32) NOT NULL, `value` int(20) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1", 1);
585 g_hDatabase.Query(SQLCallback_Void, "ALTER TABLE `hl_gangs_groups` MODIFY COLUMN `gang` varchar(32) NOT NULL unique", 1);
586 g_hDatabase.Query(SQLCallback_Void, "ALTER TABLE `hl_gangs_statistics` MODIFY COLUMN `gang` varchar(32) NOT NULL unique", 1);
587
588 DeleteDuplicates();
589 }
590}
591
592void LoadSteamID(int client)
593{
594 if (gcv_bPluginEnabled.BoolValue)
595 {
596 if (!IsValidClient(client))
597 {
598 PrintToChatAll("Klient jest nieprawidłowy");
599 return;
600 }
601 GetClientAuthId(client, AuthId_Steam2, ga_sSteamID[client], sizeof(ga_sSteamID[]));
602
603 if (StrContains(ga_sSteamID[client], "STEAM_", true) == -1) //if ID is invalid
604 {
605 CreateTimer(10.0, RefreshSteamID, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
606 PrintToChat(client, "Reload, bo (StrContains(ga_sSteamID[client], STEAM_, true) == -1))");
607 }
608 else
609 {
610 PrintToChat(client, "Poszło (StrContains(ga_sSteamID[client], STEAM_, true) == -1)");
611 }
612
613 if (g_hDatabase == null) //connect not loaded - retry to give it time
614 {
615 CreateTimer(1.0, RepeatCheckRank, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
616 PrintToChat(client, "Database == null");
617 }
618 else
619 {
620 char sQuery[300];
621 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_players WHERE steamid=\"%s\"", ga_sSteamID[client]);
622 g_hDatabase.Query(SQLCallback_CheckSQL_Player, sQuery, GetClientUserId(client));
623 PrintToChat(client, "2. Odpalono LoadSteamID. Wysłano do bazy zapytanie SQLCallback_CheckSQL_Player");
624 }
625 }
626}
627
628public void SQLCallback_CheckSQL_Player(Database db, DBResultSet results, const char[] error, int data)
629{
630 if (db == null)
631 {
632 SetDB();
633 PrintToChatAll("SetDB, bo była null");
634 }
635 if (results == null)
636 {
637 LogError(error);
638 PrintToChatAll("Error: %s", error);
639 return;
640 }
641
642 int client = GetClientOfUserId(data);
643 if (!IsValidClient(client))
644 {
645 return;
646 }
647 else
648 {
649 if (results.RowCount == 1)
650 {
651 results.FetchRow();
652
653 results.FetchString(3, ga_sGangName[client], sizeof(ga_sGangName[]));
654 ga_iRank[client] = view_as<GangRank>(results.FetchInt(4));
655 results.FetchString(5, ga_sInvitedBy[client], sizeof(ga_sInvitedBy[]));
656 ga_iDateJoined[client] = results.FetchInt(6);
657 ga_iShare[client] = results.FetchInt(7);
658
659 ga_bIsPlayerInDatabase[client] = true;
660 ga_bHasGang[client] = true;
661
662 ga_iFunds[client] = 0;
663 ga_iHealth[client] = 0;
664 ga_iCash[client] = 0;
665 ga_iStore[client] = 0;
666 ga_iMedishot[client] = 0;
667 ga_iSize[client] = 0;
668
669 char sQuery_2[300];
670 Format(sQuery_2, sizeof(sQuery_2), "SELECT * FROM hl_gangs_groups WHERE gang=\"%s\"", ga_sGangName[client]);
671 g_hDatabase.Query(SQLCallback_CheckSQL_Groups, sQuery_2, GetClientUserId(client));
672 PrintToChat(client, "3. Ustawiono zmienne na 0 w tym zapytaniu i właśnie o nie zapytano. Odpala się funkcja SQLCallback_CheckSQL_Groups");
673 }
674 else
675 {
676 if (results.RowCount > 1)
677 {
678 LogError("Player %L has multiple entries under their ID. Running script to clean up duplicates and keep original entry (oldest)", client);
679 DeleteDuplicates();
680 CreateTimer(20.0, RepeatCheckRank, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
681 PrintToChat(client, "Player %L has multiple entries under their ID. Running script to clean up duplicates and keep original entry (oldest)", client);
682 }
683 else if (g_hDatabase == null)
684 {
685 CreateTimer(2.0, RepeatCheckRank, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
686 PrintToChat(client, "Database == null w Callbacku");
687 }
688 else
689 {
690 ga_bHasGang[client] = false;
691 ga_bLoaded[client] = true;
692 PrintToChat(client, "ga_bHasGang[client] = false; ga_bLoaded[client] = true;");
693 }
694 }
695 }
696}
697
698public void SQLCallback_CheckSQL_Groups(Database db, DBResultSet results, const char[] error, int data)
699{
700 if (db == null)
701 {
702 SetDB();
703 }
704 if (results == null)
705 {
706 LogError(error);
707 return;
708 }
709
710 int client = GetClientOfUserId(data);
711 if (!IsValidClient(client))
712 {
713 return;
714 }
715 else
716 {
717 if (results.RowCount == 1)
718 {
719 results.FetchRow();
720
721 ga_iHealth[client] = results.FetchInt(2);
722 ga_iCash[client] = results.FetchInt(3);
723 ga_iStore[client] = results.FetchInt(4);
724 ga_iMedishot[client] = results.FetchInt(5);
725 ga_iSize[client] = results.FetchInt(6);
726 ga_iFunds[client] = results.FetchInt(7);
727 PrintToChat(client, "Pobrano wszystkie ga_i* w funkcjhi CheckSQL_Groups, czyli odświeżono ulepszenia.");
728 }
729 }
730}
731
732public Action RepeatCheckRank(Handle timer, int iUserID)
733{
734 int client = GetClientOfUserId(iUserID);
735 LoadSteamID(client);
736}
737
738public void SQLCallback_Void(Database db, DBResultSet results, const char[] error, int data)
739{
740 if (db == null)
741 {
742 LogError("Error (%i): %s", data, error);
743 }
744}
745
746public Action Command_Accept(int client, int args)
747{
748 if (!gcv_bPluginEnabled.BoolValue)
749 {
750 ReplyToCommand(client, "%t", "DisabledPlugin");
751 return Plugin_Handled;
752 }
753 if (gcv_bInviteStyle.BoolValue)
754 {
755 ReplyToCommand(client, "%t","DisabledAcceptCommand");
756 return Plugin_Handled;
757 }
758
759 if (!IsValidClient(client))
760 {
761 ReplyToCommand(client, "[SM] %t", "PlayerNotInGame");
762 return Plugin_Handled;
763 }
764 if (ga_bHasGang[client])
765 {
766 ReplyToCommand(client, "%s %t", TAG, "AlreadyInGang");
767 return Plugin_Handled;
768 }
769 if (ga_iInvitation[client] == -1)
770 {
771 ReplyToCommand(client, "%s %t", TAG, "NotInvited");
772 return Plugin_Handled;
773 }
774
775 int sender = GetClientOfUserId(ga_iInvitation[client]);
776 if (ga_iGangSize[sender] >= gcv_iMaxGangSize.IntValue + ga_iSize[sender] && !gcv_bDisableSize.BoolValue)
777 {
778 ReplyToCommand(client, "%s %t", TAG, "GangIsFull");
779 return Plugin_Handled;
780 }
781
782 ga_sGangName[client] = ga_sGangName[sender];
783 ga_iDateJoined[client] = GetTime();
784 ga_bHasGang[client] = true;
785 ga_bSetName[client] = false;
786
787 char sName[MAX_NAME_LENGTH];
788 GetClientName(sender, sName, sizeof(sName));
789
790 ga_iShare[client] = 0;
791
792 ga_iFunds[client] = ga_iFunds[sender];
793 ga_iHealth[client] = ga_iHealth[sender];
794 ga_iCash[client] = ga_iCash[sender];
795 ga_iStore[client] = ga_iStore[sender];
796 ga_iMedishot[client] = ga_iMedishot[sender];
797 ga_iSize[client] = ga_iSize[sender];
798 ga_iGangSize[client] = ++ga_iGangSize[sender];
799
800 ga_sInvitedBy[client] = sName;
801 ga_iRank[client] = Rank_Normal;
802 UpdateSQL(client);
803 return Plugin_Handled;
804}
805
806public Action Command_Gang(int client, int args)
807{
808 if (!IsValidClient(client))
809 {
810 ReplyToCommand(client, "[SM] %t", "PlayerNotInGame");
811 return Plugin_Handled;
812 }
813 StartOpeningGangMenu(client);
814 return Plugin_Handled;
815}
816
817public Action sm_addfunds(int client, int args) {
818
819 if (!IsValidClient(client)) { // invalid client
820 PrintToChat(client, "[SM] %t", "PlayerNotInGame");
821 return Plugin_Handled;
822 }
823
824 if(ga_bHasGang[client])
825 {
826 if (args != 1)
827 { // invalid argument count
828 PrintToChat(client, "%s %t", TAG, "Invalid Arguments");
829 return Plugin_Handled;
830 }
831
832 char FundsAmount[64], sQuery[300];
833 GetCmdArg(1, FundsAmount, sizeof(FundsAmount));
834
835 int curCredits = Store_GetClientCredits(client);
836 int addCredits = StringToInt(FundsAmount);
837
838 if (curCredits < addCredits) { // not enough credits
839 PrintToChat(client, "%s %t", TAG, "Not Enough Credits", curCredits);
840 return Plugin_Handled;
841 }
842
843 Store_SetClientCredits(client, (Store_GetClientCredits(client) - addCredits));
844
845 ga_iShare[client] = ga_iShare[client] + addCredits;
846
847 for (int i = 0; i <= MaxClients; i++)
848 {
849 if (IsValidClient(i) && StrEqual(ga_sGangName[i], ga_sGangName[client]))
850 {
851 ga_iFunds[i] = ga_iFunds[i] + addCredits;
852 }
853 }
854
855 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_players SET share = share + %i WHERE steamid=\"%s\"", addCredits, ga_sSteamID[client]);
856
857 g_hDatabase.Query(SQLCallback_Void, sQuery);
858
859 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_groups SET funds = funds + %i WHERE gang=\"%s\"", addCredits, ga_sGangName[client]);
860
861 g_hDatabase.Query(SQLCallback_Void, sQuery);
862
863 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_statistics SET value = value + %i WHERE gang=\"%s\"", addCredits, ga_sGangName[client]);
864
865 g_hDatabase.Query(SQLCallback_Void, sQuery);
866
867 PrintToChat(client, "%s %t", TAG, "Funds Added", addCredits);
868 }
869 else
870 PrintToChat(client, "%s %t", TAG, "Funds Not Added");
871
872 return Plugin_Handled;
873}
874
875/*****************************************************************
876*********************** MAIN GANG MENU **************************
877******************************************************************/
878
879void StartOpeningGangMenu(int client)
880{
881 if (!StrEqual(ga_sGangName[client], ""))
882 {
883 char sQuery[300];
884 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_players WHERE gang = \"%s\"", ga_sGangName[client]);
885 g_hDatabase.Query(SQLCallback_OpenGangMenu, sQuery, GetClientUserId(client));
886 }
887 else
888 {
889 OpenGangsMenu(client);
890 }
891}
892
893public void SQLCallback_OpenGangMenu(Database db, DBResultSet results, const char[] error, int data)
894{
895 if (results == null)
896 {
897 LogError(error);
898 return;
899 }
900
901 int client = GetClientOfUserId(data);
902 if (!IsValidClient(client))
903 {
904 return;
905 }
906 else
907 {
908 ga_iGangSize[client] = results.RowCount;
909 }
910 OpenGangsMenu(client);
911}
912
913void OpenGangsMenu(int client)
914{
915 Menu menu = CreateMenu(GangsMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
916
917 if (ga_bHasGang[client])
918 {
919 char sString[128];
920 Format(sString, sizeof(sString), "%T \n%T %i \n%T: %s %i/%i", "GangsMenuTitle", client
921 , "Credits", client
922 , ga_iFunds[client]
923 , "CurrentGang", client
924 , ga_sGangName[client], ga_iGangSize[client], gcv_iMaxGangSize.IntValue + ga_iSize[client]);
925 SetMenuTitle(menu, sString);
926 }
927 else
928 {
929 char sString[128];
930 Format(sString, sizeof(sString), "%T \n%T: %i \n%T N/A", "GangsMenuTitle", client
931 , "Credits", client
932 , GetClientCredits(client)
933 , "CurrentGang", client);
934 SetMenuTitle(menu, sString);
935 }
936 char sDisplayBuffer[128];
937
938 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i %T]", "CreateAGang", client, gcv_iCreateGangPrice.IntValue, "Credits", client);
939 menu.AddItem("create", sDisplayBuffer, (ga_bHasGang[client] || GetClientCredits(client) < gcv_iCreateGangPrice.IntValue)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
940
941 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "InviteToGang", client);
942 menu.AddItem("invite", sDisplayBuffer, (ga_bHasGang[client] && ga_iRank[client] > Rank_Normal && ga_iGangSize[client] < gcv_iMaxGangSize.IntValue + ga_iSize[client])?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
943
944 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "GangMembers", client);
945 menu.AddItem("members", sDisplayBuffer, (ga_bHasGang[client])?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
946
947 if (gcv_bDisableCash.BoolValue && gcv_bDisableStore.BoolValue && gcv_bDisableHealth.BoolValue && gcv_bDisableSize.BoolValue && gcv_bDisableMedishot.BoolValue)
948 {
949 // draw nothing
950 }
951 else
952 {
953 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "GangPerks", client);
954 menu.AddItem("perks", sDisplayBuffer, (ga_bHasGang[client])?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
955 }
956
957 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "GangAdmin", client);
958 menu.AddItem("admin", sDisplayBuffer, (ga_iRank[client] >= Rank_Admin)?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
959
960 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "LeaveGang", client);
961 menu.AddItem("leave", sDisplayBuffer, (ga_bHasGang[client])?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
962
963 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "TopGangs", client);
964 menu.AddItem("topgangs", sDisplayBuffer);
965
966 Call_StartForward(g_hOnMainMenu);
967 Call_PushCell(client);
968 Call_PushCell(menu);
969 Call_Finish();
970
971
972 menu.Display(client, MENU_TIME_FOREVER);
973}
974
975public int GangsMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
976{
977 Call_StartForward(g_hOnMainMenuCallback);
978 Call_PushCell(menu);
979 Call_PushCell(action);
980 Call_PushCell(param1);
981 Call_PushCell(param2);
982 Call_Finish();
983
984 if (!IsValidClient(param1))
985 {
986 return;
987 }
988
989 switch (action)
990 {
991 case MenuAction_Select:
992 {
993 char sInfo[64];
994 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
995 if (StrEqual(sInfo, "create"))
996 {
997 SetClientCredits(param1, GetClientCredits(param1) - gcv_iCreateGangPrice.IntValue);
998 StartGangCreation(param1);
999 }
1000 else if (StrEqual(sInfo, "invite"))
1001 {
1002 OpenInvitationMenu(param1);
1003 }
1004 else if (StrEqual(sInfo, "members"))
1005 {
1006 StartOpeningMembersMenu(param1);
1007 }
1008 else if (StrEqual(sInfo, "perks"))
1009 {
1010 StartOpeningPerkMenu(param1);
1011 }
1012 else if (StrEqual(sInfo, "admin"))
1013 {
1014 OpenAdministrationMenu(param1);
1015 }
1016 else if (StrEqual(sInfo, "leave"))
1017 {
1018 OpenLeaveConfirmation(param1);
1019 }
1020 else if (StrEqual(sInfo, "topgangs"))
1021 {
1022 StartOpeningTopGangsMenu(param1);
1023 }
1024
1025 }
1026 case MenuAction_End:
1027 {
1028 delete menu;
1029 }
1030 }
1031 return;
1032}
1033
1034
1035
1036/*****************************************************************
1037*********************** GANG CREATION **************************
1038******************************************************************/
1039
1040
1041
1042void StartGangCreation(int client)
1043{
1044 if (!IsValidClient(client))
1045 {
1046 ReplyToCommand(client, "[SM] %t", "PlayerNotInGame", client);
1047 return;
1048 }
1049 for (int i = 0; i <= 5; i++)
1050 {
1051 PrintToChat(client, "%s %t", TAG, "GangName");
1052 }
1053 ga_bSetName[client] = true;
1054}
1055
1056public Action OnSay(int client, const char[] command, int args)
1057{
1058 if (!IsValidClient(client))
1059 {
1060 return Plugin_Continue;
1061 }
1062 if (ga_bSetName[client])
1063 {
1064 char sText[64], sFormattedText[2*sizeof(sText)+1];
1065 GetCmdArgString(sText, sizeof(sText));
1066 StripQuotes(sText);
1067
1068 g_hDatabase.Escape(sText, sFormattedText, sizeof(sFormattedText));
1069 TrimString(sFormattedText);
1070
1071 if (strlen(sText) > 16)
1072 {
1073 PrintToChat(client, "%s %t", TAG, "NameTooLong");
1074 return Plugin_Handled;
1075 }
1076 else if (strlen(sText) == 0)
1077 {
1078 return Plugin_Handled;
1079 }
1080
1081 DataPack data = new DataPack();
1082 data.WriteCell(client);
1083 data.WriteString(sText);
1084 data.Reset();
1085
1086 char sQuery[300];
1087 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_groups WHERE gang=\"%s\"", sFormattedText);
1088 g_hDatabase.Query(SQL_Callback_CheckName, sQuery, data);
1089
1090 return Plugin_Handled;
1091 }
1092 else if (ga_bRename[client])
1093 {
1094 char sText[64], sFormattedText[2*sizeof(sText)+1];
1095 GetCmdArgString(sText, sizeof(sText));
1096 StripQuotes(sText);
1097
1098 g_hDatabase.Escape(sText, sFormattedText, sizeof(sFormattedText));
1099 TrimString(sFormattedText);
1100
1101 if (strlen(sText) > 16)
1102 {
1103 PrintToChat(client, "%s %t", TAG, "NameTooLong");
1104 return Plugin_Handled;
1105 }
1106 else if (strlen(sText) == 0)
1107 {
1108 return Plugin_Handled;
1109 }
1110
1111 DataPack data = new DataPack();
1112 data.WriteCell(client);
1113 data.WriteString(sText);
1114 data.Reset();
1115
1116 char sQuery[300];
1117 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_groups WHERE gang=\"%s\"", sFormattedText);
1118 g_hDatabase.Query(SQL_Callback_CheckName, sQuery, data);
1119
1120 return Plugin_Handled;
1121 }
1122 return Plugin_Continue;
1123}
1124
1125public void SQL_Callback_CheckName(Database db, DBResultSet results, const char[] error, DataPack data)
1126{
1127 if (db == null)
1128 {
1129 SetDB();
1130 }
1131
1132 if (results == null)
1133 {
1134 LogError(error);
1135 return;
1136 }
1137
1138 char sText[64];
1139 int client = data.ReadCell();
1140 data.ReadString(sText, sizeof(sText));
1141 delete data;
1142
1143 if (!IsValidClient(client))
1144 {
1145 return;
1146 }
1147 else
1148 {
1149 if (ga_bSetName[client])
1150 {
1151 if (results.RowCount == 0)
1152 {
1153
1154 strcopy(ga_sGangName[client], sizeof(ga_sGangName[]), sText);
1155 ga_bHasGang[client] = true;
1156 ga_iDateJoined[client] = GetTime();
1157 ga_bHasGang[client] = true;
1158 ga_sInvitedBy[client] = "N/A";
1159 ga_iRank[client] = Rank_Owner;
1160 ga_iGangSize[client] = 1;
1161
1162 ga_iShare[client] = gcv_iCreateGangPrice.IntValue;
1163 ga_iFunds[client] = gcv_iCreateGangPrice.IntValue;
1164
1165 ga_iHealth[client] = 0;
1166 ga_iCash[client] = 0;
1167 ga_iStore[client] = 0;
1168 ga_iMedishot[client] = 0;
1169 ga_iSize[client] = 0;
1170
1171 UpdateSQL(client);
1172
1173 char sQuery[300];
1174 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_statistics WHERE gang = \"%s\"", ga_sGangName[client]);
1175 g_hDatabase.Query(SQL_Callback_LoadStatistics, sQuery, GetClientUserId(client));
1176
1177
1178 CreateTimer(0.2, Timer_OpenGangMenu, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
1179
1180 char name[MAX_NAME_LENGTH];
1181 GetClientName(client, name, sizeof(name));
1182 PrintToChatAll("%s %T", TAG, "GangCreated", LANG_SERVER, name, ga_sGangName[client]);
1183
1184 }
1185 else
1186 {
1187 PrintToChat(client, "%s %t", TAG, "NameAlreadyUsed");
1188 }
1189
1190 ga_bSetName[client] = false;
1191 }
1192 else if (ga_bRename[client])
1193 {
1194 if (results.RowCount == 0)
1195 {
1196 char sOldName[32];
1197 strcopy(sOldName, sizeof(sOldName), ga_sGangName[client]);
1198 strcopy(ga_sGangName[client], sizeof(ga_sGangName[]), sText);
1199 for (int i = 1; i <= MaxClients; i++)
1200 {
1201 if (IsValidClient(i) && StrEqual(ga_sGangName[i], sOldName))
1202 {
1203 strcopy(ga_sGangName[i], sizeof(ga_sGangName[]), sText);
1204 }
1205 }
1206 char sQuery[300];
1207 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_players SET gang=\"%s\" WHERE gang=\"%s\"", sText, sOldName);
1208
1209 g_hDatabase.Query(SQLCallback_Void, sQuery);
1210
1211 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_groups SET gang=\"%s\" WHERE gang=\"%s\"", sText, sOldName);
1212
1213 g_hDatabase.Query(SQLCallback_Void, sQuery);
1214
1215 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_statistics SET gang=\"%s\" WHERE gang=\"%s\"", sText, sOldName);
1216
1217 g_hDatabase.Query(SQLCallback_Void, sQuery);
1218
1219 char name[MAX_NAME_LENGTH];
1220 GetClientName(client, name, sizeof(name));
1221 PrintToChatAll("%s %T", TAG, "GangNameChange", LANG_SERVER, name, sOldName, sText);
1222
1223 ga_iFunds[client] = ga_iFunds[client] - gcv_iRenamePrice.IntValue;
1224 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_groups SET funds=%i WHERE gang=\"%s\"", ga_iFunds[client], ga_sGangName[client]);
1225 g_hDatabase.Query(SQLCallback_Void, sQuery);
1226 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_statistics SET value=value-%i WHERE gang=\"%s\"", gcv_iRenamePrice, ga_sGangName[client]);
1227 g_hDatabase.Query(SQLCallback_Void, sQuery);
1228
1229 StartOpeningGangMenu(client);
1230
1231 }
1232 else
1233 {
1234 PrintToChat(client, "%s %t", TAG, "NameAlreadyUsed");
1235 }
1236
1237 ga_bRename[client] = false;
1238 }
1239 }
1240}
1241
1242
1243public void SQL_Callback_LoadStatistics(Database db, DBResultSet results, const char[] error, int data)
1244{
1245 if (db == null)
1246 {
1247 SetDB();
1248 }
1249 if (results == null)
1250 {
1251 LogError(error);
1252 return;
1253 }
1254
1255 int client = GetClientOfUserId(data);
1256
1257 if (!IsValidClient(client))
1258 {
1259 return;
1260 }
1261
1262 if (results.RowCount == 0)
1263 {
1264 ga_bIsGangInDatabase[client] = false;
1265 }
1266 else
1267 {
1268 ga_bIsGangInDatabase[client] = true;
1269 }
1270
1271 char sQuery[300];
1272 if (!ga_bIsGangInDatabase[client])
1273 {
1274 Format(sQuery, sizeof(sQuery), "INSERT INTO hl_gangs_statistics (gang, value) VALUES(\"%s\", %i)", ga_sGangName[client], gcv_iCreateGangPrice.IntValue);
1275 }
1276
1277 g_hDatabase.Query(SQLCallback_Void, sQuery);
1278
1279}
1280
1281
1282public Action Timer_OpenGangMenu(Handle hTimer, int userid)
1283{
1284 int client = GetClientOfUserId(userid);
1285 if(IsValidClient(client))
1286 {
1287 StartOpeningGangMenu(client);
1288 }
1289}
1290
1291
1292/*****************************************************************
1293*********************** MEMBER LIST MENU *************************
1294******************************************************************/
1295
1296
1297void StartOpeningMembersMenu(int client)
1298{
1299 if (!StrEqual(ga_sGangName[client], ""))
1300 {
1301 char sQuery[300];
1302 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_players WHERE gang=\"%s\"", ga_sGangName[client]);
1303
1304 g_hDatabase.Query(SQLCallback_OpenMembersMenu, sQuery, GetClientUserId(client));
1305 }
1306}
1307
1308public void SQLCallback_OpenMembersMenu(Database db, DBResultSet results, const char[] error, int data)
1309{
1310 if (db == null)
1311 {
1312 SetDB();
1313 }
1314 int client = GetClientOfUserId(data);
1315 if (!IsValidClient(client))
1316 {
1317 return;
1318 }
1319 else
1320 {
1321 Menu menu = CreateMenu(MemberListMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
1322
1323 char sTitleString[128];
1324 Format(sTitleString, sizeof(sTitleString), "%T", "MemberList", client);
1325 SetMenuTitle(menu, sTitleString);
1326
1327 while (results.FetchRow())
1328 {
1329 char a_sTempArray[6][128]; // 0 - SteamID | 1 - Name | 2 - Invited By | 3 - Rank | 4 - Date (UTF) | 5 - Share
1330 results.FetchString(1, a_sTempArray[0], sizeof(a_sTempArray[])); // Steam-ID
1331 results.FetchString(2, a_sTempArray[1], sizeof(a_sTempArray[])); // Player Name
1332 results.FetchString(5, a_sTempArray[2], sizeof(a_sTempArray[])); // Invited By
1333 IntToString(results.FetchInt(4), a_sTempArray[3], sizeof(a_sTempArray[])); // Rank
1334 IntToString(results.FetchInt(6), a_sTempArray[4], sizeof(a_sTempArray[])); // Date
1335 IntToString(results.FetchInt(7), a_sTempArray[5], sizeof(a_sTempArray[])); // Share
1336
1337
1338 char sInfoString[128];
1339 char sDisplayString[128];
1340
1341 Format(sInfoString, sizeof(sInfoString), "%s;%s;%s;%i;%i;%i", a_sTempArray[0], a_sTempArray[1], a_sTempArray[2], StringToInt(a_sTempArray[3]), StringToInt(a_sTempArray[4]), StringToInt(a_sTempArray[5]));
1342
1343 if (StrEqual(a_sTempArray[3], "0"))
1344 {
1345 Format(sDisplayString, sizeof(sDisplayString), "%s (%T)", a_sTempArray[1], "MemberRank", client);
1346 }
1347 else if (StrEqual(a_sTempArray[3], "1"))
1348 {
1349 Format(sDisplayString, sizeof(sDisplayString), "%s (%T)", a_sTempArray[1], "AdminRank", client);
1350 }
1351 else if (StrEqual(a_sTempArray[3], "2"))
1352 {
1353 Format(sDisplayString, sizeof(sDisplayString), "%s (%T)", a_sTempArray[1], "OwnerRank", client);
1354 }
1355 menu.AddItem(sInfoString, sDisplayString);
1356 }
1357 menu.ExitBackButton = true;
1358
1359 menu.Display(client, MENU_TIME_FOREVER);
1360 }
1361}
1362
1363public int MemberListMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
1364{
1365 switch (action)
1366 {
1367 case MenuAction_Select:
1368 {
1369 char sInfo[128];
1370 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1371 OpenIndividualMemberMenu(param1, sInfo);
1372 }
1373 case MenuAction_Cancel:
1374 {
1375 StartOpeningGangMenu(param1);
1376 }
1377 case MenuAction_End:
1378 {
1379 delete menu;
1380 }
1381 }
1382 return;
1383}
1384
1385void OpenIndividualMemberMenu(int client, char[] sInfo)
1386{
1387 Menu menu = CreateMenu(IndividualMemberMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
1388 SetMenuTitle(menu, "Information On : ");
1389
1390 char sTempArray[6][64]; // 0 - SteamID | 1 - Name | 2 - Invited By | 3 - Rank | 4 - Date (UTF) | 5 - Share
1391 char sDisplayBuffer[32];
1392
1393 ExplodeString(sInfo, ";", sTempArray, 6, sizeof(sTempArray[]));
1394
1395 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %s", "Name", client, sTempArray[1]);
1396 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1397
1398 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "Steam ID : %s", sTempArray[0]);
1399 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1400
1401 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %s", "InvitedBy", client, sTempArray[2]);
1402 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1403
1404
1405 if (StrEqual(sTempArray[3], "0"))
1406 {
1407 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %T", "Rank", client, "MemberRank", client);
1408 }
1409 else if (StrEqual(sTempArray[3], "1"))
1410 {
1411 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %T", "Rank", client, "AdminRank", client);
1412 }
1413 else if (StrEqual(sTempArray[3], "2"))
1414 {
1415 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %T", "Rank", client, "OwnerRank", client);
1416 }
1417 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1418
1419 char sFormattedTime[64];
1420 FormatTime(sFormattedTime, sizeof(sFormattedTime), "%x", StringToInt(sTempArray[4]));
1421 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %s", "DateJoined", client, sFormattedTime);
1422
1423 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1424
1425 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %i", "Share", client, StringToInt(sTempArray[5]));
1426 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1427
1428 menu.ExitBackButton = true;
1429
1430
1431 menu.Display(client, MENU_TIME_FOREVER);
1432}
1433
1434public int IndividualMemberMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
1435{
1436 switch (action)
1437 {
1438 case MenuAction_Select:
1439 {
1440
1441 }
1442 case MenuAction_Cancel:
1443 {
1444 StartOpeningMembersMenu(param1);
1445 }
1446 case MenuAction_End:
1447 {
1448 delete menu;
1449 }
1450 }
1451 return;
1452}
1453/*****************************************************************
1454*********************** INVITATION MENU **************************
1455******************************************************************/
1456
1457
1458
1459void OpenInvitationMenu(int client)
1460{
1461 Menu menu = CreateMenu(InvitationMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
1462
1463 char sInfoString[64];
1464 char sDisplayString[64];
1465 char sMenuString[32];
1466
1467 Format(sMenuString, sizeof(sMenuString), "%T", "InviteToGang", client);
1468 SetMenuTitle(menu, sMenuString);
1469
1470 for (int i = 1; i <= MaxClients; i++)
1471 {
1472 if (IsValidClient(i) && i != client)
1473 {
1474 Format(sInfoString, sizeof(sInfoString), "%i", GetClientUserId(i));
1475 Format(sDisplayString, sizeof(sDisplayString), "%N", i);
1476 SanitizeName(sDisplayString);
1477
1478 menu.AddItem(sInfoString, sDisplayString, (ga_bHasGang[i] || ga_iRank[client] == Rank_Normal)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1479 }
1480 }
1481
1482 menu.Display(client, MENU_TIME_FOREVER);
1483
1484}
1485
1486public int InvitationMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
1487{
1488 switch (action)
1489 {
1490 case MenuAction_Select:
1491 {
1492 char sInfo[64];
1493 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1494 int iUserID = StringToInt(sInfo);
1495
1496 ga_iInvitation[GetClientOfUserId(iUserID)] = GetClientUserId(param1);
1497
1498 if (ga_iGangSize[param1] >= gcv_iMaxGangSize.IntValue + ga_iSize[param1]
1499 && !gcv_bDisableSize.BoolValue)
1500 {
1501 PrintToChat(param1, "%s %t", TAG, "GangIsFull");
1502 return;
1503 }
1504
1505 if (!gcv_bInviteStyle.BoolValue)
1506 {
1507 PrintToChat(GetClientOfUserId(iUserID), "%s %t", TAG, "AcceptInstructions", ga_sGangName[param1]);
1508 }
1509 else
1510 {
1511 OpenGangInvitationMenu(GetClientOfUserId(iUserID));
1512 }
1513 StartOpeningGangMenu(param1);
1514 }
1515 case MenuAction_Cancel:
1516 {
1517 StartOpeningGangMenu(param1);
1518 }
1519 case MenuAction_End:
1520 {
1521 delete menu;
1522 }
1523 }
1524 return;
1525}
1526
1527
1528void OpenGangInvitationMenu(int client)
1529{
1530 if (!IsValidClient(client))
1531 {
1532 return;
1533 }
1534 Menu menu = CreateMenu(SentInviteMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
1535 char sDisplayString[64];
1536 char sTitleString[64];
1537
1538 Format(sTitleString, sizeof(sTitleString), "%T", "GangInvitation", client);
1539 SetMenuTitle(menu, sTitleString);
1540
1541 int sender = GetClientOfUserId(ga_iInvitation[client]);
1542 char senderName[MAX_NAME_LENGTH];
1543 GetClientName(sender, senderName, sizeof(senderName));
1544 SanitizeName(senderName);
1545
1546 Format(sDisplayString, sizeof(sDisplayString), "%T", "InviteString", client, senderName);
1547 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
1548
1549 Format(sDisplayString, sizeof(sDisplayString), "%T", "WouldYouLikeToJoin", client, ga_sGangName[sender]);
1550 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
1551
1552 Format(sDisplayString, sizeof(sDisplayString), "%T", "IWouldLikeTo", client);
1553 menu.AddItem("yes", sDisplayString);
1554
1555 Format(sDisplayString, sizeof(sDisplayString), "%T", "IWouldNotLikeTo", client);
1556 menu.AddItem("no", sDisplayString);
1557
1558 menu.Display(client, MENU_TIME_FOREVER);
1559}
1560
1561
1562public int SentInviteMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
1563{
1564 if (!IsValidClient(param1))
1565 {
1566 return;
1567 }
1568 switch (action)
1569 {
1570 case MenuAction_Select:
1571 {
1572 char sInfo[64];
1573 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1574 if (StrEqual(sInfo, "yes"))
1575 {
1576 int sender = GetClientOfUserId(ga_iInvitation[param1]);
1577
1578 if (ga_iGangSize[param1] >= gcv_iMaxGangSize.IntValue + ga_iSize[param1] && !gcv_bDisableSize.BoolValue)
1579 {
1580 PrintToChat(param1, "%s %t", TAG, "GangIsFull");
1581 return;
1582 }
1583 ga_sGangName[param1] = ga_sGangName[sender];
1584 ga_iDateJoined[param1] = GetTime();
1585 ga_bHasGang[param1] = true;
1586 ga_bSetName[param1] = false;
1587
1588 ga_iShare[param1] = 0;
1589
1590 ga_iFunds[param1] = ga_iFunds[sender];
1591 ga_iHealth[param1] = ga_iHealth[sender];
1592 ga_iCash[param1] = ga_iCash[sender];
1593 ga_iStore[param1] = ga_iStore[sender];
1594 ga_iMedishot[param1] = ga_iMedishot[sender];
1595 ga_iSize[param1] = ga_iSize[sender];
1596 ga_iGangSize[param1] = ++ga_iGangSize[sender];
1597
1598
1599 char sName[MAX_NAME_LENGTH];
1600 GetClientName(sender, sName, sizeof(sName));
1601 ga_sInvitedBy[param1] = sName;
1602 ga_iRank[param1] = Rank_Normal;
1603 UpdateSQL(param1);
1604
1605 for (int i = 0; i <= MaxClients; i++)
1606 {
1607 if (IsValidClient(i) && StrEqual(ga_sGangName[param1], ga_sGangName[i]))
1608 {
1609 LoadSteamID(i);
1610 }
1611 }
1612
1613
1614 char name[MAX_NAME_LENGTH];
1615 GetClientName(param1, name, sizeof(name));
1616
1617 PrintToChatAll("%s %T", TAG, "GangJoined", LANG_SERVER, name, ga_sGangName[param1]);
1618 }
1619 else if (StrEqual(sInfo, "no"))
1620 {
1621 // Do Nothing
1622 }
1623 }
1624 case MenuAction_Cancel:
1625 {
1626 StartOpeningGangMenu(param1);
1627 }
1628 case MenuAction_End:
1629 {
1630 delete menu;
1631 }
1632 }
1633 return;
1634}
1635
1636
1637/*****************************************************************
1638*********************** PERK MENU *************************
1639******************************************************************/
1640
1641
1642public void StartOpeningPerkMenu(int client)
1643{
1644 if (IsValidClient(client))
1645 {
1646 char sQuery[300];
1647 Format(sQuery, sizeof(sQuery), "SELECT health, cash, store, medishot, size, funds FROM hl_gangs_groups WHERE gang=\"%s\"", ga_sGangName[client]);
1648 g_hDatabase.Query(SQLCallback_Perks, sQuery, GetClientUserId(client));
1649 }
1650}
1651
1652public void SQLCallback_Perks(Database db, DBResultSet results, const char[] error, int data)
1653{
1654 if (db == null)
1655 {
1656 SetDB();
1657 }
1658
1659 int client = GetClientOfUserId(data);
1660
1661 if (!IsValidClient(client))
1662 {
1663 return;
1664 }
1665 else
1666 {
1667 Menu menu = CreateMenu(PerksMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
1668
1669 char sTitleString[64];
1670
1671 Format(sTitleString, sizeof(sTitleString), "%T", "GangPerks", client);
1672 SetMenuTitle(menu, sTitleString);
1673
1674 if (results.RowCount == 1 && results.FetchRow())
1675 {
1676 ga_iHealth[client] = results.FetchInt(0); // Health
1677 ga_iCash[client] = results.FetchInt(1); // Cash
1678 ga_iStore[client] = results.FetchInt(2); // Store credits
1679 ga_iMedishot[client] = results.FetchInt(3); // Medishot
1680 ga_iSize[client] = results.FetchInt(4);
1681 ga_iFunds[client] = results.FetchInt(5);
1682 }
1683
1684 char sDisplayBuffer[64];
1685
1686 int price;
1687
1688 if (!gcv_bDisableHealth.BoolValue)
1689 {
1690 price = gcv_iHealthPrice.IntValue * (ga_iHealth[client] + 1);
1691 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/5] [%i %T]", "Health", client, ga_iHealth[client], price, "Credits", client);
1692 menu.AddItem("health", sDisplayBuffer, (ga_iHealth[client] >= 5 || ga_iFunds[client] < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1693 }
1694
1695 if (!gcv_bDisableCash.BoolValue)
1696 {
1697 price = gcv_iCashPrice.IntValue * (ga_iCash[client] + 1);
1698 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/5] [%i %T]", "Cash", client, ga_iCash[client], price, "Credits", client);
1699 menu.AddItem("cash", sDisplayBuffer, (ga_iCash[client] >= 5 || ga_iFunds[client] < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1700 }
1701
1702 if (!gcv_bDisableStore.BoolValue)
1703 {
1704 price = gcv_iStorePrice.IntValue * (ga_iStore[client] + 1);
1705 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/5] [%i %T]", "Store", client, ga_iStore[client], price, "Credits", client);
1706 menu.AddItem("store", sDisplayBuffer, (ga_iStore[client] >= 5 || ga_iFunds[client] < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1707 }
1708
1709 if (!gcv_bDisableMedishot.BoolValue)
1710 {
1711 price = gcv_iMedishotPrice.IntValue * (ga_iMedishot[client] + 1);
1712 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/1] [%i %T]", "Medishot", client, ga_iMedishot[client], price, "Credits", client);
1713 menu.AddItem("medishot", sDisplayBuffer, (ga_iMedishot[client] >= 1 || ga_iFunds[client] < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1714 }
1715
1716 if (!gcv_bDisableSize.BoolValue && gcv_iMaxGangSize.IntValue != 0)
1717 {
1718 price = gcv_iSizePrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iSize[client]);
1719 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/%i] [%i %T]", "GangSize", client, ga_iSize[client], gcv_iGangSizeMaxUpgrades.IntValue, price, "Credits", client);
1720 menu.AddItem("size", sDisplayBuffer, (ga_iSize[client] >= gcv_iGangSizeMaxUpgrades.IntValue || ga_iFunds[client] < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1721 }
1722
1723
1724 Call_StartForward(g_hOnPerkMenu);
1725 Call_PushCell(client);
1726 Call_PushCell(menu);
1727 Call_Finish();
1728
1729 menu.ExitBackButton = true;
1730
1731 menu.Display(client, MENU_TIME_FOREVER);
1732 }
1733}
1734
1735public int PerksMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
1736{
1737 Call_StartForward(g_hOnPerkMenuCallback);
1738 Call_PushCell(menu);
1739 Call_PushCell(action);
1740 Call_PushCell(param1);
1741 Call_PushCell(param2);
1742 Call_Finish();
1743
1744 if (!IsValidClient(param1))
1745 {
1746 return;
1747 }
1748 switch (action)
1749 {
1750 case MenuAction_Select:
1751 {
1752 char sInfo[64];
1753 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1754 char sQuery[300];
1755
1756 if (StrEqual(sInfo, "health"))
1757 {
1758 int price = gcv_iHealthPrice.IntValue * (ga_iHealth[param1] + 1);
1759 ga_iFunds[param1] = ga_iFunds[param1] - price;
1760 ++ga_iHealth[param1];
1761 PrintToGang(param1, true, "%s %T", TAG, "HealthUpgrade", LANG_SERVER);
1762 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_groups SET health=%i, funds=%i WHERE gang=\"%s\"", ga_iHealth[param1], ga_iFunds[param1], ga_sGangName[param1]);
1763 }
1764 else if (StrEqual(sInfo, "cash"))
1765 {
1766 int price = gcv_iCashPrice.IntValue * (ga_iCash[param1] + 1);
1767 ga_iFunds[param1] = ga_iFunds[param1] - price;
1768 ++ga_iCash[param1];
1769 PrintToGang(param1, true, "%s %T", TAG, "CashUpgrade", LANG_SERVER);
1770 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_groups SET cash=%i, funds=%i WHERE gang=\"%s\"", ga_iCash[param1], ga_iFunds[param1], ga_sGangName[param1]);
1771 }
1772 else if (StrEqual(sInfo, "store"))
1773 {
1774 int price = gcv_iStorePrice.IntValue * (ga_iStore[param1] + 1);
1775 ga_iFunds[param1] = ga_iFunds[param1] - price;
1776 PrintToGang(param1, true, "%s %T", TAG, "StoreUpgrade", LANG_SERVER);
1777 ++ga_iStore[param1];
1778 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_groups SET store=%i, funds=%i WHERE gang=\"%s\"", ga_iStore[param1], ga_iFunds[param1], ga_sGangName[param1]);
1779 }
1780 else if (StrEqual(sInfo, "medishot"))
1781 {
1782 int price = gcv_iMedishotPrice.IntValue * (ga_iMedishot[param1] + 1);
1783 ga_iFunds[param1] = ga_iFunds[param1] - price;
1784 PrintToGang(param1, true, "%s %T", TAG, "MedishotUpgrade", LANG_SERVER);
1785 ++ga_iMedishot[param1];
1786 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_groups SET medishot=%i, funds=%i WHERE gang=\"%s\"", ga_iMedishot[param1], ga_iFunds[param1],ga_sGangName[param1]);
1787 }
1788 else if (StrEqual(sInfo, "size"))
1789 {
1790 int price = gcv_iSizePrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iSize[param1]);
1791 ga_iFunds[param1] = ga_iFunds[param1] - price;
1792 PrintToGang(param1, true, "%s %T", TAG, "SizeUpgrade", LANG_SERVER);
1793 ++ga_iSize[param1];
1794 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_groups SET size=%i WHERE gang=\"%s\"", ga_iSize[param1], ga_iFunds[param1], ga_sGangName[param1]);
1795 }
1796 g_hDatabase.Query(SQLCallback_Void, sQuery, GetClientUserId(param1));
1797
1798 StartOpeningPerkMenu(param1);
1799 }
1800 case MenuAction_Cancel:
1801 {
1802 StartOpeningGangMenu(param1);
1803 }
1804 case MenuAction_End:
1805 {
1806 delete menu;
1807 }
1808 }
1809 return;
1810}
1811
1812
1813/*****************************************************************
1814******************* LEAVE CONFIRMATION ********************
1815******************************************************************/
1816
1817
1818void OpenLeaveConfirmation(int client)
1819{
1820 Menu menu = CreateMenu(LeaveConfirmation_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
1821
1822 char tempBuffer[128];
1823
1824 Format(tempBuffer, sizeof(tempBuffer), "%T", "LeaveGang", client);
1825 SetMenuTitle(menu, tempBuffer);
1826
1827 Format(tempBuffer, sizeof(tempBuffer), "%T", "AreYouSure", client);
1828 menu.AddItem("", tempBuffer, ITEMDRAW_DISABLED);
1829 if (ga_iRank[client] == Rank_Owner)
1830 {
1831 Format(tempBuffer, sizeof(tempBuffer), "%T", "OwnerWarning", client);
1832 menu.AddItem("", tempBuffer, ITEMDRAW_DISABLED);
1833 }
1834
1835 Format(tempBuffer, sizeof(tempBuffer), "%T", "YesLeave", client);
1836 menu.AddItem("yes", tempBuffer);
1837
1838 Format(tempBuffer, sizeof(tempBuffer), "%T", "NoLeave", client);
1839 menu.AddItem("no", tempBuffer);
1840
1841 menu.ExitBackButton = true;
1842
1843 menu.Display(client, MENU_TIME_FOREVER);
1844}
1845
1846public int LeaveConfirmation_Callback(Menu menu, MenuAction action, int param1, int param2)
1847{
1848 switch (action)
1849 {
1850 case MenuAction_Select:
1851 {
1852 char sInfo[64];
1853 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1854 if (StrEqual(sInfo, "yes"))
1855 {
1856 RemoveFromGang(param1);
1857 }
1858 else if (StrEqual(sInfo, "no"))
1859 {
1860 StartOpeningGangMenu(param1);
1861 }
1862
1863 }
1864 case MenuAction_Cancel:
1865 {
1866 StartOpeningGangMenu(param1);
1867 }
1868 case MenuAction_End:
1869 {
1870 delete menu;
1871 }
1872 }
1873 return;
1874}
1875
1876
1877
1878
1879/*****************************************************************
1880********************* ADMIN MAIN MENU **************************
1881******************************************************************/
1882
1883
1884void OpenAdministrationMenu(int client)
1885{
1886 if (!IsValidClient(client))
1887 {
1888 return;
1889 }
1890 Menu menu = CreateMenu(AdministrationMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
1891
1892 char tempBuffer[128];
1893 Format(tempBuffer, sizeof(tempBuffer), "%T", "GangAdmin", client);
1894 SetMenuTitle(menu, tempBuffer);
1895
1896 char sDisplayString[128];
1897
1898 Format(sDisplayString, sizeof(sDisplayString), "%T", "KickAMember", client);
1899 menu.AddItem("kick", "Kick a member", (ga_iRank[client] == Rank_Normal)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1900
1901 Format(sDisplayString, sizeof(sDisplayString), "%T [%i %T]", "RenameGang", client, gcv_iRenamePrice.IntValue, "Credits", client);
1902 menu.AddItem("rename", sDisplayString, (ga_iRank[client] == Rank_Owner && ga_iFunds[client] >= gcv_iRenamePrice.IntValue)?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
1903
1904 Format(sDisplayString, sizeof(sDisplayString), "%T", "Promote", client);
1905 menu.AddItem("promote", sDisplayString, (ga_iRank[client] == Rank_Normal)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1906
1907 Format(sDisplayString, sizeof(sDisplayString), "%T", "Disband", client);
1908 menu.AddItem("disband", sDisplayString, (ga_iRank[client] == Rank_Owner)?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
1909
1910
1911 menu.ExitBackButton = true;
1912
1913 menu.Display(client, MENU_TIME_FOREVER);
1914
1915}
1916
1917public int AdministrationMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
1918{
1919 if (!IsValidClient(param1))
1920 {
1921 return;
1922 }
1923 switch (action)
1924 {
1925 case MenuAction_Select:
1926 {
1927 char sInfo[64];
1928 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1929 if (StrEqual(sInfo, "kick"))
1930 {
1931 OpenAdministrationKickMenu(param1);
1932 }
1933 else if (StrEqual(sInfo, "rename"))
1934 {
1935 for (int i = 1; i <= 5; i++)
1936 {
1937 PrintToChat(param1, "%s %t", TAG, "GangName");
1938 }
1939 ga_bRename[param1] = true;
1940 }
1941 else if (StrEqual(sInfo, "promote"))
1942 {
1943 OpenAdministrationPromotionMenu(param1);
1944 }
1945 else if (StrEqual(sInfo, "disband"))
1946 {
1947 OpenDisbandMenu(param1);
1948 }
1949 }
1950 case MenuAction_Cancel:
1951 {
1952 StartOpeningGangMenu(param1);
1953 }
1954 case MenuAction_End:
1955 {
1956 delete menu;
1957 }
1958 }
1959 return;
1960}
1961
1962
1963
1964/*****************************************************************
1965******************* ADMIN PROMOTION MENU ***********************
1966******************************************************************/
1967
1968
1969
1970
1971void OpenAdministrationPromotionMenu(int client)
1972{
1973 if (!StrEqual(ga_sGangName[client], ""))
1974 {
1975 char sQuery[200];
1976 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_players WHERE gang=\"%s\"", ga_sGangName[client]);
1977
1978 g_hDatabase.Query(SQLCallback_AdministrationPromotionMenu, sQuery, GetClientUserId(client));
1979 }
1980}
1981
1982public void SQLCallback_AdministrationPromotionMenu(Database db, DBResultSet results, const char[] error, int data)
1983{
1984 if (db == null)
1985 {
1986 SetDB();
1987 }
1988 int client = GetClientOfUserId(data);
1989 if (!IsValidClient(client))
1990 {
1991 return;
1992 }
1993 else
1994 {
1995 Menu menu = CreateMenu(AdministrationPromoMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
1996
1997 char tempBuffer[128];
1998 Format(tempBuffer, sizeof(tempBuffer), "%T", "Promote", client);
1999 SetMenuTitle(menu, tempBuffer);
2000
2001 while (results.FetchRow())
2002 {
2003 char sTempArray[3][128]; // 0 - SteamID | 1 - Name | 2 - Invited By | 3 - Rank | 4 - Date (UTF)
2004 results.FetchString(1, sTempArray[0], sizeof(sTempArray[])); // Steam-ID
2005 results.FetchString(2, sTempArray[1], sizeof(sTempArray[])); // Player Name
2006 IntToString(results.FetchInt(4), sTempArray[2], sizeof(sTempArray[])); // Rank
2007
2008 char sSteamID[34];
2009 GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
2010
2011 if (!StrEqual(sSteamID, sTempArray[0]))
2012 {
2013 char sInfoString[128];
2014 char sDisplayString[128];
2015 Format(sInfoString, sizeof(sInfoString), "%s;%s;%i", sTempArray[0], sTempArray[1], StringToInt(sTempArray[2]));
2016 Format(sDisplayString, sizeof(sDisplayString), "%s (%s)", sTempArray[1], sTempArray[0]);
2017 menu.AddItem(sInfoString, sDisplayString, (ga_iRank[client] == Rank_Owner)?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
2018 }
2019 }
2020 menu.ExitBackButton = true;
2021
2022 menu.Display(client, MENU_TIME_FOREVER);
2023 }
2024}
2025
2026public int AdministrationPromoMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
2027{
2028 switch (action)
2029 {
2030 case MenuAction_Select:
2031 {
2032 char sInfo[256];
2033 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2034
2035 OpenPromoteDemoteMenu(param1, sInfo);
2036 }
2037 case MenuAction_Cancel:
2038 {
2039 OpenAdministrationMenu(param1);
2040 }
2041 case MenuAction_End:
2042 {
2043 delete menu;
2044 }
2045 }
2046 return;
2047}
2048
2049
2050void OpenPromoteDemoteMenu(int client, const char[] sInfo)
2051{
2052 char sTempArray[3][32];
2053 ExplodeString(sInfo, ";", sTempArray, 3, 32);
2054
2055 Menu menu = CreateMenu(AdministrationPromoDemoteMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
2056
2057 char tempBuffer[128];
2058 Format(tempBuffer, sizeof(tempBuffer), "%T", "GangMembersRanks", client);
2059 SetMenuTitle(menu, tempBuffer);
2060
2061 char sInfoString[32];
2062
2063 Format(tempBuffer, sizeof(tempBuffer), "%T", "Simply", client);
2064 menu.AddItem("", tempBuffer, ITEMDRAW_DISABLED);
2065
2066 Format(sInfoString, sizeof(sInfoString), "%s;normal", sTempArray[0]);
2067 Format(tempBuffer, sizeof(tempBuffer), "%T", "MemberRank", client);
2068 menu.AddItem(sInfoString, tempBuffer, (ga_iRank[client] != Rank_Owner)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
2069
2070 Format(sInfoString, sizeof(sInfoString), "%s;admin", sTempArray[0]);
2071 Format(tempBuffer, sizeof(tempBuffer), "%T", "AdminRank", client);
2072 menu.AddItem(sInfoString, tempBuffer, (ga_iRank[client] != Rank_Owner)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
2073
2074 menu.ExitBackButton = true;
2075
2076 menu.Display(client, MENU_TIME_FOREVER);
2077}
2078
2079public int AdministrationPromoDemoteMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
2080{
2081 switch (action)
2082 {
2083 case MenuAction_Select:
2084 {
2085 char sInfo[256];
2086 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2087 char sTempArray[2][32];
2088 ExplodeString(sInfo, ";", sTempArray, 2, 32);
2089
2090 char sQuery[300];
2091
2092 if (StrEqual(sTempArray[1], "normal"))
2093 {
2094 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_players SET rank=0 WHERE steamid=\"%s\"", sTempArray[0]);
2095 }
2096 else if (StrEqual(sTempArray[1], "admin"))
2097 {
2098 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_players SET rank=1 WHERE steamid=\"%s\"", sTempArray[0]);
2099 }
2100
2101 g_hDatabase.Query(SQLCallback_Void, sQuery);
2102 char sSteamID[32];
2103 for (int i = 1; i <= MaxClients; i++)
2104 {
2105 if (IsValidClient(i))
2106 {
2107 GetClientAuthId(i, AuthId_Steam2, sSteamID, sizeof(sSteamID));
2108 if (StrEqual(sSteamID, sTempArray[0]))
2109 {
2110 LoadSteamID(i);
2111 break;
2112 }
2113 }
2114 }
2115 }
2116 case MenuAction_Cancel:
2117 {
2118 OpenAdministrationMenu(param1);
2119 }
2120 case MenuAction_End:
2121 {
2122 delete menu;
2123 }
2124 }
2125 return;
2126}
2127
2128
2129
2130
2131
2132/*****************************************************************
2133********************* DISBAND MENU **************************
2134******************************************************************/
2135
2136
2137
2138
2139
2140
2141
2142void OpenDisbandMenu(int client)
2143{
2144 Menu menu = CreateMenu(DisbandMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
2145
2146 char tempString[128];
2147
2148 Format(tempString, sizeof(tempString), "%T", "DisbandGang", client);
2149 SetMenuTitle(menu, tempString);
2150
2151 Format(tempString, sizeof(tempString), "%T", "DisbandConfirmation", client);
2152 menu.AddItem("", tempString, ITEMDRAW_DISABLED);
2153
2154 Format(tempString, sizeof(tempString), "%T", "YesDisband", client);
2155 menu.AddItem("disband", tempString, (ga_iRank[client] != Rank_Owner)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
2156
2157 Format(tempString, sizeof(tempString), "%T", "NoDisband", client);
2158 menu.AddItem("no", tempString, (ga_iRank[client] != Rank_Owner)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
2159
2160 menu.ExitBackButton = true;
2161
2162 menu.Display(client, MENU_TIME_FOREVER);
2163}
2164
2165public int DisbandMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
2166{
2167 switch (action)
2168 {
2169 case MenuAction_Select:
2170 {
2171 char sInfo[256];
2172 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2173 if (StrEqual(sInfo, "disband"))
2174 {
2175 RemoveFromGang(param1);
2176 }
2177 }
2178 case MenuAction_Cancel:
2179 {
2180 OpenAdministrationMenu(param1);
2181 }
2182 case MenuAction_End:
2183 {
2184 delete menu;
2185 }
2186 }
2187 return;
2188}
2189
2190/*****************************************************************
2191********************* ADMIN KICK MENU **************************
2192******************************************************************/
2193
2194void OpenAdministrationKickMenu(int client)
2195{
2196 if (!StrEqual(ga_sGangName[client], ""))
2197 {
2198 char sQuery[200];
2199 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_players WHERE gang=\"%s\"", ga_sGangName[client]);
2200
2201 g_hDatabase.Query(SQLCallback_AdministrationKickMenu, sQuery, GetClientUserId(client));
2202 }
2203}
2204
2205public void SQLCallback_AdministrationKickMenu(Database db, DBResultSet results, const char[] error, int data)
2206{
2207 if (db == null)
2208 {
2209 SetDB();
2210 }
2211 int client = GetClientOfUserId(data);
2212 if (!IsValidClient(client))
2213 {
2214 return;
2215 }
2216 else
2217 {
2218
2219 Menu menu = CreateMenu(AdministrationKickMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
2220
2221 char tempString[128];
2222
2223 Format(tempString, sizeof(tempString), "%T", "KickGangMembers", client);
2224 SetMenuTitle(menu, tempString);
2225
2226 while (results.FetchRow())
2227 {
2228 char sTempArray[3][128]; // 0 - SteamID | 1 - Name | 2 - Invited By | 3 - Rank | 4 - Date (UTF)
2229 results.FetchString(1, sTempArray[0], sizeof(sTempArray[])); // Steam-ID
2230 results.FetchString(2, sTempArray[1], sizeof(sTempArray[])); // Player Name
2231 IntToString(results.FetchInt(4), sTempArray[2], sizeof(sTempArray[])); // Rank
2232 KickShare[client] = results.FetchInt(7);
2233
2234 PrintToChatAll("%s 1 kick %i client: %i", TAG, KickShare[client], client);
2235
2236 char sInfoString[128];
2237 char sDisplayString[128];
2238
2239 Format(sInfoString, sizeof(sInfoString), "%s;%s", sTempArray[0], sTempArray[1]);
2240 Format(sDisplayString, sizeof(sDisplayString), "%s (%s)", sTempArray[1], sTempArray[0]);
2241 menu.AddItem(sInfoString, sDisplayString, (ga_iRank[client] > view_as<GangRank>(StringToInt(sTempArray[2])))?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
2242 }
2243 menu.ExitBackButton = true;
2244
2245 menu.Display(client, MENU_TIME_FOREVER);
2246 }
2247}
2248
2249public int AdministrationKickMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
2250{
2251 switch (action)
2252 {
2253 case MenuAction_Select:
2254 {
2255 char sInfo[256];
2256 char sTempArray[2][128];
2257 char sQuery1[128];
2258
2259 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2260
2261 ExplodeString(sInfo, ";", sTempArray, 2, 128);
2262
2263 Format(sQuery1, sizeof(sQuery1), "DELETE FROM hl_gangs_players WHERE steamid = \"%s\"", sTempArray[0]);
2264 g_hDatabase.Query(SQLCallback_Void, sQuery1);
2265
2266 PrintToChatAll("%s 2 kick %i client: %i", TAG, KickShare[param1], param1);
2267
2268 KickShare[param1] = KickShare[param1] * 7 / 10;
2269
2270 PrintToChatAll("%s 3 kick %i", TAG, KickShare[param1]);
2271
2272 char sQuery2[300];
2273
2274 Format(sQuery2, sizeof(sQuery2), "UPDATE hl_gangs_groups SET funds = funds - %i WHERE gang=\"%s\"", KickShare[param1], ga_sGangName[param1]);
2275 g_hDatabase.Query(SQLCallback_Void, sQuery2);
2276
2277 Format(sQuery2, sizeof(sQuery2), "UPDATE hl_gangs_statistics SET value = value - %i WHERE gang=\"%s\"", KickShare[param1], ga_sGangName[param1]);
2278 g_hDatabase.Query(SQLCallback_Void, sQuery2);
2279
2280 PrintToChatAll("%s 4 kick %i", TAG, KickShare[param1]);
2281
2282 KickShare[param1] = 0;
2283
2284 PrintToChatAll("%s 5 kick %i", TAG, KickShare[param1]);
2285
2286 PrintToChatAll("%s %T", TAG, "GangMemberKick", LANG_SERVER, sTempArray[1], ga_sGangName[param1]);
2287
2288 char sSteamID[64];
2289 for (int i = 1; i <= MaxClients; i++)
2290 {
2291 if (IsValidClient(i))
2292 {
2293 GetClientAuthId(i, AuthId_Steam2, sSteamID, sizeof(sSteamID));
2294 if (StrEqual(sSteamID, sTempArray[0]))
2295 {
2296 ResetVariables(i);
2297 }
2298 }
2299 }
2300 }
2301 case MenuAction_Cancel:
2302 {
2303 OpenAdministrationMenu(param1);
2304 }
2305 case MenuAction_End:
2306 {
2307 delete menu;
2308 }
2309 }
2310}
2311
2312
2313/*****************************************************************
2314********************** TOP GANGS MENU **************************
2315******************************************************************/
2316
2317
2318
2319void StartOpeningTopGangsMenu(int client)
2320{
2321 if (IsValidClient(client))
2322 {
2323 g_hDatabase.Query(SQL_Callback_TopMenu, "SELECT * FROM hl_gangs_statistics ORDER BY value DESC", GetClientUserId(client));
2324 }
2325}
2326
2327public void SQL_Callback_TopMenu(Database db, DBResultSet results, const char[] error, int data)
2328{
2329 if (db == null)
2330 {
2331 SetDB();
2332 }
2333
2334 if (results == null)
2335 {
2336 LogError(error);
2337 return;
2338 }
2339
2340 int client = GetClientOfUserId(data);
2341 if (!IsValidClient(client))
2342 {
2343 return;
2344 }
2345 else
2346 {
2347 Menu menu = CreateMenu(TopGangsMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
2348
2349 char menuTitle[64];
2350 Format(menuTitle, sizeof(menuTitle), "%T", "TopGangs", client);
2351 menu.SetTitle(menuTitle);
2352 if (results.RowCount == 0)
2353 {
2354 PrintToChat(client, "%s %t", TAG, "NoGangs");
2355
2356 delete menu;
2357 return;
2358 }
2359 char sGangName[128];
2360 char sInfoString[128];
2361
2362
2363 ga_iTempInt2[client] = 0;
2364 g_iGangAmmount = 0;
2365 while (results.FetchRow())
2366 {
2367 g_iGangAmmount++;
2368 ga_iTempInt2[client]++;
2369
2370 results.FetchString(1, sGangName, sizeof(sGangName));
2371
2372 Format(sInfoString, sizeof(sInfoString), "%i;%s;%i", ga_iTempInt2[client], sGangName, results.FetchInt(2));
2373
2374 menu.AddItem(sInfoString, sGangName);
2375 }
2376
2377 menu.ExitBackButton = true;
2378
2379 menu.Display(client, MENU_TIME_FOREVER);
2380 }
2381}
2382
2383public int TopGangsMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
2384{
2385 switch (action)
2386 {
2387 case MenuAction_Select:
2388 {
2389 char sInfo[300];
2390 char sQuery[300];
2391 char sTempArray[3][128];
2392 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2393
2394 ExplodeString(sInfo, ";", sTempArray, 3, sizeof(sTempArray[]));
2395
2396 ga_iTempInt2[param1] = StringToInt(sTempArray[0]);
2397 ga_iTempInt[param1] = StringToInt(sTempArray[2]);
2398
2399 Format(sQuery, sizeof(sQuery), "SELECT * FROM `hl_gangs_players` WHERE `gang` = \"%s\" AND `rank` = 2", sTempArray[1]);
2400 g_hDatabase.Query(SQL_Callback_GangStatistics, sQuery, GetClientUserId(param1));
2401
2402 }
2403 case MenuAction_Cancel:
2404 {
2405 StartOpeningGangMenu(param1);
2406 }
2407 case MenuAction_End:
2408 {
2409 delete menu;
2410 }
2411 }
2412 return;
2413}
2414
2415
2416public void SQL_Callback_GangStatistics(Database db, DBResultSet results, const char[] error, int data)
2417{
2418 if (db == null)
2419 {
2420 SetDB();
2421 }
2422
2423 if (results == null)
2424 {
2425 LogError(error);
2426 return;
2427 }
2428
2429 int client = GetClientOfUserId(data);
2430 if (!IsValidClient(client))
2431 {
2432 return;
2433 }
2434 else
2435 {
2436 char sTempArray[2][128]; // Gang Name | Player Name
2437 char sFormattedTime[64];
2438 char sDisplayString[128];
2439
2440 results.FetchRow();
2441
2442
2443 results.FetchString(3, sTempArray[0], sizeof(sTempArray[]));
2444 results.FetchString(2, sTempArray[1], sizeof(sTempArray[]));
2445 int iDate = results.FetchInt(6);
2446
2447 Menu menu = CreateMenu(MenuCallback_Void, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
2448 menu.SetTitle("Top Gangs");
2449
2450 Format(sDisplayString, sizeof(sDisplayString), "%T : %s", "MenuGangName", client, sTempArray[0]);
2451 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2452
2453 Format(sDisplayString, sizeof(sDisplayString), "%T : %i/%i", "GangRank", client, ga_iTempInt2[client], g_iGangAmmount);
2454 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2455
2456 FormatTime(sFormattedTime, sizeof(sFormattedTime), "%x", iDate);
2457 Format(sDisplayString, sizeof(sDisplayString), "%T : %s", "DateCreated", client, sFormattedTime);
2458 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2459
2460 Format(sDisplayString, sizeof(sDisplayString), "%T : %s", "CreatedBy", client, sTempArray[1]);
2461 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2462
2463 Format(sDisplayString, sizeof(sDisplayString), "%T : %i ", "Value", client, ga_iTempInt[client]);
2464 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2465
2466 menu.ExitBackButton = true;
2467
2468 menu.Display(client, MENU_TIME_FOREVER);
2469 }
2470}
2471
2472public int MenuCallback_Void(Menu menu, MenuAction action, int param1, int param2)
2473{
2474 switch (action)
2475 {
2476 case MenuAction_Select:
2477 {
2478 // Do Nothing
2479 }
2480 case MenuAction_Cancel:
2481 {
2482 StartOpeningTopGangsMenu(param1);
2483 }
2484 case MenuAction_End:
2485 {
2486 delete menu;
2487 }
2488 }
2489 return;
2490}
2491
2492/*****************************************************************
2493*********************** HELPER FUNCTIONS ***********************
2494******************************************************************/
2495
2496
2497void UpdateSQL(int client)
2498{
2499 DeleteDuplicates();
2500
2501 /* We need to ensure that users are completely loaded in before calling save queries.
2502 * This may prevent errors where CT kills are reset to zero. */
2503 if (ga_bHasGang[client] && ga_bLoaded[client])
2504 {
2505 GetClientAuthId(client, AuthId_Steam2, ga_sSteamID[client], sizeof(ga_sSteamID[]));
2506
2507 char sQuery[300];
2508 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_players WHERE steamid=\"%s\"", ga_sSteamID[client]);
2509
2510 g_hDatabase.Query(SQLCallback_CheckIfInDatabase_Player, sQuery, GetClientUserId(client));
2511 }
2512}
2513
2514public void SQLCallback_CheckIfInDatabase_Player(Database db, DBResultSet results, const char[] error, int data)
2515{
2516 if (db == null)
2517 {
2518 SetDB();
2519 }
2520
2521 int client = GetClientOfUserId(data);
2522
2523 if (!IsValidClient(client))
2524 {
2525 return;
2526 }
2527 if (results.RowCount == 0)
2528 {
2529 ga_bIsPlayerInDatabase[client] = false;
2530 }
2531 else
2532 {
2533 ga_bIsPlayerInDatabase[client] = true;
2534 }
2535
2536 char sQuery[300];
2537 char playerName[MAX_NAME_LENGTH], escapedName[MAXPLAYERS*2+1];
2538
2539 GetClientName(client, playerName, sizeof(playerName));
2540 g_hDatabase.Escape(playerName, escapedName, sizeof(escapedName));
2541
2542 if (!ga_bIsPlayerInDatabase[client])
2543 {
2544 Format(sQuery, sizeof(sQuery), "INSERT INTO hl_gangs_players (gang, invitedby, rank, date, steamid, playername, share) VALUES(\"%s\", \"%s\", %i, %i, \"%s\", \"%s\", %i)", ga_sGangName[client], ga_sInvitedBy[client], ga_iRank[client], ga_iDateJoined[client], ga_sSteamID[client], escapedName, ga_iShare[client]);
2545 }
2546 else
2547 {
2548 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_players SET gang=\"%s\",invitedby=\"%s\",playername=\"%s\",rank=%i,date=%i WHERE steamid=\"%s\"", ga_sGangName[client], ga_sInvitedBy[client], escapedName, ga_iRank[client], ga_iDateJoined[client], ga_sSteamID[client]);
2549 }
2550 g_hDatabase.Query(SQLCallback_Void, sQuery);
2551
2552 char sQuery2[128];
2553
2554 Format(sQuery2, sizeof(sQuery2), "SELECT * FROM hl_gangs_groups WHERE gang=\"%s\"", ga_sGangName[client]);
2555
2556 g_hDatabase.Query(SQLCALLBACK_GROUPS, sQuery2, GetClientUserId(client));
2557}
2558
2559public void SQLCALLBACK_GROUPS(Database db, DBResultSet results, const char[] error, int data)
2560{
2561 if (db == null)
2562 {
2563 SetDB();
2564 }
2565
2566 int client = GetClientOfUserId(data);
2567
2568 if (!IsValidClient(client))
2569 {
2570 return;
2571 }
2572
2573 if (results.RowCount == 0)
2574 {
2575 ga_bIsGangInDatabase[client] = false;
2576 }
2577 else
2578 {
2579 ga_bIsGangInDatabase[client] = true;
2580 }
2581
2582 char sQuery[300];
2583 if (!ga_bIsGangInDatabase[client])
2584 {
2585 Format(sQuery, sizeof(sQuery), "INSERT INTO hl_gangs_groups (gang, health, cash, store, medishot, size, funds) VALUES(\"%s\", %i, %i, %i, %i, %i, %i)", ga_sGangName[client], ga_iHealth[client], ga_iCash[client], ga_iStore[client], ga_iMedishot[client], ga_iSize[client], ga_iFunds[client]);
2586 }
2587 else
2588 {
2589 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_groups SET health=%i,cash=%i,store=%i,medishot=%i,size=%i,funds=%i WHERE gang=\"%s\"", ga_iHealth[client], ga_iCash[client], ga_iStore[client], ga_iMedishot[client], ga_iSize[client], ga_sGangName[client], ga_iFunds[client]);
2590 }
2591
2592 g_hDatabase.Query(SQLCallback_Void, sQuery);
2593
2594}
2595
2596void SetDB()
2597{
2598 if (g_hDatabase == null)
2599 {
2600 gcv_sDatabase.GetString(g_sDatabaseName, sizeof(g_sDatabaseName));
2601 Database.Connect(SQLCallback_Connect, g_sDatabaseName);
2602 }
2603}
2604
2605void DeleteDuplicates()
2606{
2607 if (g_hDatabase != null)
2608 {
2609 g_hDatabase.Query(SQLCallback_Void, "delete hl_gangs_players from hl_gangs_players inner join (select min(id) minid, steamid from hl_gangs_players group by steamid having count(1) > 1) as duplicates on (duplicates.steamid = hl_gangs_players.steamid and duplicates.minid <> hl_gangs_players.id)", 4);
2610 g_hDatabase.Query(SQLCallback_Void, "delete hl_gangs_groups from hl_gangs_groups inner join (select min(id) minid, gang from hl_gangs_groups group by gang having count(1) > 1) as duplicates on (duplicates.gang = hl_gangs_groups.gang and duplicates.minid <> hl_gangs_groups.id)", 4);
2611 g_hDatabase.Query(SQLCallback_Void, "delete hl_gangs_statistics from hl_gangs_statistics inner join (select min(id) minid, gang from hl_gangs_statistics group by gang having count(1) > 1) as duplicates on (duplicates.gang = hl_gangs_statistics.gang and duplicates.minid <> hl_gangs_statistics.id)", 4);
2612 }
2613}
2614
2615int GetClientCredits(int client)
2616{
2617 if (g_bZepyhrus)
2618 {
2619 return Store_GetClientCredits(client);
2620 }
2621 else
2622 {
2623 SetFailState("ERROR: No supported credits plugin loaded!");
2624 return 0;
2625 }
2626}
2627
2628void SetClientCredits(int client, int iAmmount)
2629{
2630 if (g_bZepyhrus)
2631 {
2632 Store_SetClientCredits(client, iAmmount);
2633 }
2634 else
2635 {
2636 SetFailState("ERROR: No supported credits plugin loaded!");
2637 }
2638}
2639
2640void RemoveFromGang(int client)
2641{
2642 if (ga_iRank[client] == Rank_Owner)
2643 {
2644 char sQuery1[300];
2645 char sQuery2[300];
2646 char sQuery3[300];
2647 Format(sQuery1, sizeof(sQuery1), "DELETE FROM hl_gangs_players WHERE gang = \"%s\"", ga_sGangName[client]);
2648 Format(sQuery2, sizeof(sQuery2), "DELETE FROM hl_gangs_groups WHERE gang = \"%s\"", ga_sGangName[client]);
2649 Format(sQuery3, sizeof(sQuery3), "DELETE FROM hl_gangs_statistics WHERE gang = \"%s\"", ga_sGangName[client]);
2650
2651 g_hDatabase.Query(SQLCallback_Void, sQuery1);
2652 g_hDatabase.Query(SQLCallback_Void, sQuery2);
2653 g_hDatabase.Query(SQLCallback_Void, sQuery3);
2654
2655 char name[MAX_NAME_LENGTH];
2656 GetClientName(client, name, sizeof(name));
2657 PrintToChatAll("%s %T", TAG, "GangDisbanded", LANG_SERVER, name, ga_sGangName[client]);
2658 for (int i = 1; i <= MaxClients; i++)
2659 {
2660 if (IsValidClient(i) && StrEqual(ga_sGangName[i], ga_sGangName[client]) && i != client)
2661 {
2662 ResetVariables(i);
2663 }
2664 }
2665 ResetVariables(client);
2666 }
2667 else
2668 {
2669 char sQuery1[128];
2670 Format(sQuery1, sizeof(sQuery1), "DELETE FROM hl_gangs_players WHERE steamid = \"%s\"", ga_sSteamID[client]);
2671 g_hDatabase.Query(SQLCallback_Void, sQuery1);
2672
2673 char name[MAX_NAME_LENGTH];
2674 GetClientName(client, name, sizeof(name));
2675 PrintToChatAll("%s %T", TAG, "LeftGang", LANG_SERVER, name, ga_sGangName[client]);
2676 ResetVariables(client);
2677 }
2678}
2679
2680void PrintToGang(int client, bool bPrintToClient = false, const char[] sMsg, any ...)
2681{
2682 if(!IsValidClient(client))
2683 {
2684 return;
2685 }
2686 char sFormattedMsg[256];
2687 VFormat(sFormattedMsg, sizeof(sFormattedMsg), sMsg, 4);
2688
2689 for (int i = 1; i <= MaxClients; i++)
2690 {
2691 if (IsValidClient(i) && StrEqual(ga_sGangName[i], ga_sGangName[client]) && !StrEqual(ga_sGangName[client], ""))
2692 {
2693 if (bPrintToClient)
2694 {
2695 PrintToChat(i, sFormattedMsg);
2696 }
2697 else
2698 {
2699 if (i == client)
2700 {
2701 // Do nothing
2702 }
2703 else
2704 {
2705 PrintToChat(i, sFormattedMsg);
2706 }
2707 }
2708 }
2709 }
2710}
2711
2712
2713void ResetVariables(int client)
2714{
2715 ga_iRank[client] = Rank_Invalid;
2716 ga_iGangSize[client] = -1;
2717 ga_iInvitation[client] = -1;
2718 ga_iDateJoined[client] = -1;
2719 ga_iShare[client] = 0;
2720 ga_iFunds[client] = 0;
2721 ga_iHealth[client] = 0;
2722 ga_iCash[client] = 0;
2723 ga_iStore[client] = 0;
2724 ga_iMedishot[client] = 0;
2725 ga_iSize[client] = 0;
2726 ga_iTempInt[client] = 0;
2727 ga_iTempInt2[client] = 0;
2728 ga_sGangName[client] = "";
2729 ga_sInvitedBy[client] = "";
2730 ga_bSetName[client] = false;
2731 ga_bIsPlayerInDatabase[client] = false;
2732 ga_bIsGangInDatabase[client] = false;
2733 ga_bHasGang[client] = false;
2734 ga_bRename[client] = false;
2735 ga_sSteamID[client] = "";
2736 ga_bLoaded[client] = false;
2737}
2738
2739// to avoid this https://user-images.githubusercontent.com/3672466/28637962-0d324952-724c-11e7-8b27-15ff021f0a59.png
2740void SanitizeName(char[] name)
2741{
2742 ReplaceString(name, MAX_NAME_LENGTH, "#", "?");
2743}
2744
2745bool IsValidClient(int client, bool bAllowBots = false, bool bAllowDead = true)
2746{
2747 if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
2748 {
2749 return false;
2750 }
2751 return true;
2752}