· 7 years ago · Jan 13, 2019, 04:02 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 LoadSteamID(client);
920 char sString[128];
921 Format(sString, sizeof(sString), "%T \n%T %i \n%T: %s %i/%i", "GangsMenuTitle", client
922 , "Credits", client
923 , ga_iFunds[client]
924 , "CurrentGang", client
925 , ga_sGangName[client], ga_iGangSize[client], gcv_iMaxGangSize.IntValue + ga_iSize[client]);
926 SetMenuTitle(menu, sString);
927 }
928 else
929 {
930 char sString[128];
931 Format(sString, sizeof(sString), "%T \n%T: %i \n%T N/A", "GangsMenuTitle", client
932 , "Credits", client
933 , GetClientCredits(client)
934 , "CurrentGang", client);
935 SetMenuTitle(menu, sString);
936 }
937 char sDisplayBuffer[128];
938
939 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i %T]", "CreateAGang", client, gcv_iCreateGangPrice.IntValue, "Credits", client);
940 menu.AddItem("create", sDisplayBuffer, (ga_bHasGang[client] || GetClientCredits(client) < gcv_iCreateGangPrice.IntValue)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
941
942 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "InviteToGang", client);
943 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);
944
945 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "GangMembers", client);
946 menu.AddItem("members", sDisplayBuffer, (ga_bHasGang[client])?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
947
948 if (gcv_bDisableCash.BoolValue && gcv_bDisableStore.BoolValue && gcv_bDisableHealth.BoolValue && gcv_bDisableSize.BoolValue && gcv_bDisableMedishot.BoolValue)
949 {
950 // draw nothing
951 }
952 else
953 {
954 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "GangPerks", client);
955 menu.AddItem("perks", sDisplayBuffer, (ga_bHasGang[client])?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
956 }
957
958 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "GangAdmin", client);
959 menu.AddItem("admin", sDisplayBuffer, (ga_iRank[client] >= Rank_Admin)?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
960
961 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "LeaveGang", client);
962 menu.AddItem("leave", sDisplayBuffer, (ga_bHasGang[client])?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
963
964 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "TopGangs", client);
965 menu.AddItem("topgangs", sDisplayBuffer);
966
967 Call_StartForward(g_hOnMainMenu);
968 Call_PushCell(client);
969 Call_PushCell(menu);
970 Call_Finish();
971
972
973 menu.Display(client, MENU_TIME_FOREVER);
974}
975
976public int GangsMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
977{
978 Call_StartForward(g_hOnMainMenuCallback);
979 Call_PushCell(menu);
980 Call_PushCell(action);
981 Call_PushCell(param1);
982 Call_PushCell(param2);
983 Call_Finish();
984
985 if (!IsValidClient(param1))
986 {
987 return;
988 }
989
990 switch (action)
991 {
992 case MenuAction_Select:
993 {
994 char sInfo[64];
995 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
996 if (StrEqual(sInfo, "create"))
997 {
998 SetClientCredits(param1, GetClientCredits(param1) - gcv_iCreateGangPrice.IntValue);
999 StartGangCreation(param1);
1000 }
1001 else if (StrEqual(sInfo, "invite"))
1002 {
1003 OpenInvitationMenu(param1);
1004 }
1005 else if (StrEqual(sInfo, "members"))
1006 {
1007 StartOpeningMembersMenu(param1);
1008 }
1009 else if (StrEqual(sInfo, "perks"))
1010 {
1011 StartOpeningPerkMenu(param1);
1012 }
1013 else if (StrEqual(sInfo, "admin"))
1014 {
1015 OpenAdministrationMenu(param1);
1016 }
1017 else if (StrEqual(sInfo, "leave"))
1018 {
1019 OpenLeaveConfirmation(param1);
1020 }
1021 else if (StrEqual(sInfo, "topgangs"))
1022 {
1023 StartOpeningTopGangsMenu(param1);
1024 }
1025
1026 }
1027 case MenuAction_End:
1028 {
1029 delete menu;
1030 }
1031 }
1032 return;
1033}
1034
1035
1036
1037/*****************************************************************
1038*********************** GANG CREATION **************************
1039******************************************************************/
1040
1041
1042
1043void StartGangCreation(int client)
1044{
1045 if (!IsValidClient(client))
1046 {
1047 ReplyToCommand(client, "[SM] %t", "PlayerNotInGame", client);
1048 return;
1049 }
1050 for (int i = 0; i <= 5; i++)
1051 {
1052 PrintToChat(client, "%s %t", TAG, "GangName");
1053 }
1054 ga_bSetName[client] = true;
1055}
1056
1057public Action OnSay(int client, const char[] command, int args)
1058{
1059 if (!IsValidClient(client))
1060 {
1061 return Plugin_Continue;
1062 }
1063 if (ga_bSetName[client])
1064 {
1065 char sText[64], sFormattedText[2*sizeof(sText)+1];
1066 GetCmdArgString(sText, sizeof(sText));
1067 StripQuotes(sText);
1068
1069 g_hDatabase.Escape(sText, sFormattedText, sizeof(sFormattedText));
1070 TrimString(sFormattedText);
1071
1072 if (strlen(sText) > 16)
1073 {
1074 PrintToChat(client, "%s %t", TAG, "NameTooLong");
1075 return Plugin_Handled;
1076 }
1077 else if (strlen(sText) == 0)
1078 {
1079 return Plugin_Handled;
1080 }
1081
1082 DataPack data = new DataPack();
1083 data.WriteCell(client);
1084 data.WriteString(sText);
1085 data.Reset();
1086
1087 char sQuery[300];
1088 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_groups WHERE gang=\"%s\"", sFormattedText);
1089 g_hDatabase.Query(SQL_Callback_CheckName, sQuery, data);
1090
1091 return Plugin_Handled;
1092 }
1093 else if (ga_bRename[client])
1094 {
1095 char sText[64], sFormattedText[2*sizeof(sText)+1];
1096 GetCmdArgString(sText, sizeof(sText));
1097 StripQuotes(sText);
1098
1099 g_hDatabase.Escape(sText, sFormattedText, sizeof(sFormattedText));
1100 TrimString(sFormattedText);
1101
1102 if (strlen(sText) > 16)
1103 {
1104 PrintToChat(client, "%s %t", TAG, "NameTooLong");
1105 return Plugin_Handled;
1106 }
1107 else if (strlen(sText) == 0)
1108 {
1109 return Plugin_Handled;
1110 }
1111
1112 DataPack data = new DataPack();
1113 data.WriteCell(client);
1114 data.WriteString(sText);
1115 data.Reset();
1116
1117 char sQuery[300];
1118 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_groups WHERE gang=\"%s\"", sFormattedText);
1119 g_hDatabase.Query(SQL_Callback_CheckName, sQuery, data);
1120
1121 return Plugin_Handled;
1122 }
1123 return Plugin_Continue;
1124}
1125
1126public void SQL_Callback_CheckName(Database db, DBResultSet results, const char[] error, DataPack data)
1127{
1128 if (db == null)
1129 {
1130 SetDB();
1131 }
1132
1133 if (results == null)
1134 {
1135 LogError(error);
1136 return;
1137 }
1138
1139 char sText[64];
1140 int client = data.ReadCell();
1141 data.ReadString(sText, sizeof(sText));
1142 delete data;
1143
1144 if (!IsValidClient(client))
1145 {
1146 return;
1147 }
1148 else
1149 {
1150 if (ga_bSetName[client])
1151 {
1152 if (results.RowCount == 0)
1153 {
1154
1155 strcopy(ga_sGangName[client], sizeof(ga_sGangName[]), sText);
1156 ga_bHasGang[client] = true;
1157 ga_iDateJoined[client] = GetTime();
1158 ga_bHasGang[client] = true;
1159 ga_sInvitedBy[client] = "N/A";
1160 ga_iRank[client] = Rank_Owner;
1161 ga_iGangSize[client] = 1;
1162
1163 ga_iShare[client] = gcv_iCreateGangPrice.IntValue;
1164 ga_iFunds[client] = gcv_iCreateGangPrice.IntValue;
1165
1166 ga_iHealth[client] = 0;
1167 ga_iCash[client] = 0;
1168 ga_iStore[client] = 0;
1169 ga_iMedishot[client] = 0;
1170 ga_iSize[client] = 0;
1171
1172 UpdateSQL(client);
1173
1174 char sQuery[300];
1175 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_statistics WHERE gang = \"%s\"", ga_sGangName[client]);
1176 g_hDatabase.Query(SQL_Callback_LoadStatistics, sQuery, GetClientUserId(client));
1177
1178
1179 CreateTimer(0.2, Timer_OpenGangMenu, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
1180
1181 char name[MAX_NAME_LENGTH];
1182 GetClientName(client, name, sizeof(name));
1183 PrintToChatAll("%s %T", TAG, "GangCreated", LANG_SERVER, name, ga_sGangName[client]);
1184
1185 }
1186 else
1187 {
1188 PrintToChat(client, "%s %t", TAG, "NameAlreadyUsed");
1189 }
1190
1191 ga_bSetName[client] = false;
1192 }
1193 else if (ga_bRename[client])
1194 {
1195 if (results.RowCount == 0)
1196 {
1197 char sOldName[32];
1198 strcopy(sOldName, sizeof(sOldName), ga_sGangName[client]);
1199 strcopy(ga_sGangName[client], sizeof(ga_sGangName[]), sText);
1200 for (int i = 1; i <= MaxClients; i++)
1201 {
1202 if (IsValidClient(i) && StrEqual(ga_sGangName[i], sOldName))
1203 {
1204 strcopy(ga_sGangName[i], sizeof(ga_sGangName[]), sText);
1205 }
1206 }
1207 char sQuery[300];
1208 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_players SET gang=\"%s\" WHERE gang=\"%s\"", sText, sOldName);
1209
1210 g_hDatabase.Query(SQLCallback_Void, sQuery);
1211
1212 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_groups SET gang=\"%s\" WHERE gang=\"%s\"", sText, sOldName);
1213
1214 g_hDatabase.Query(SQLCallback_Void, sQuery);
1215
1216 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_statistics SET gang=\"%s\" WHERE gang=\"%s\"", sText, sOldName);
1217
1218 g_hDatabase.Query(SQLCallback_Void, sQuery);
1219
1220 char name[MAX_NAME_LENGTH];
1221 GetClientName(client, name, sizeof(name));
1222 PrintToChatAll("%s %T", TAG, "GangNameChange", LANG_SERVER, name, sOldName, sText);
1223
1224 ga_iFunds[client] = ga_iFunds[client] - gcv_iRenamePrice.IntValue;
1225 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_groups SET funds=%i WHERE gang=\"%s\"", ga_iFunds[client], ga_sGangName[client]);
1226 g_hDatabase.Query(SQLCallback_Void, sQuery);
1227 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_statistics SET value=value-%i WHERE gang=\"%s\"", gcv_iRenamePrice, ga_sGangName[client]);
1228 g_hDatabase.Query(SQLCallback_Void, sQuery);
1229
1230 StartOpeningGangMenu(client);
1231
1232 }
1233 else
1234 {
1235 PrintToChat(client, "%s %t", TAG, "NameAlreadyUsed");
1236 }
1237
1238 ga_bRename[client] = false;
1239 }
1240 }
1241}
1242
1243
1244public void SQL_Callback_LoadStatistics(Database db, DBResultSet results, const char[] error, int data)
1245{
1246 if (db == null)
1247 {
1248 SetDB();
1249 }
1250 if (results == null)
1251 {
1252 LogError(error);
1253 return;
1254 }
1255
1256 int client = GetClientOfUserId(data);
1257
1258 if (!IsValidClient(client))
1259 {
1260 return;
1261 }
1262
1263 if (results.RowCount == 0)
1264 {
1265 ga_bIsGangInDatabase[client] = false;
1266 }
1267 else
1268 {
1269 ga_bIsGangInDatabase[client] = true;
1270 }
1271
1272 char sQuery[300];
1273 if (!ga_bIsGangInDatabase[client])
1274 {
1275 Format(sQuery, sizeof(sQuery), "INSERT INTO hl_gangs_statistics (gang, value) VALUES(\"%s\", %i)", ga_sGangName[client], gcv_iCreateGangPrice.IntValue);
1276 }
1277
1278 g_hDatabase.Query(SQLCallback_Void, sQuery);
1279
1280}
1281
1282
1283public Action Timer_OpenGangMenu(Handle hTimer, int userid)
1284{
1285 int client = GetClientOfUserId(userid);
1286 if(IsValidClient(client))
1287 {
1288 StartOpeningGangMenu(client);
1289 }
1290}
1291
1292
1293/*****************************************************************
1294*********************** MEMBER LIST MENU *************************
1295******************************************************************/
1296
1297
1298void StartOpeningMembersMenu(int client)
1299{
1300 if (!StrEqual(ga_sGangName[client], ""))
1301 {
1302 char sQuery[300];
1303 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_players WHERE gang=\"%s\"", ga_sGangName[client]);
1304
1305 g_hDatabase.Query(SQLCallback_OpenMembersMenu, sQuery, GetClientUserId(client));
1306 }
1307}
1308
1309public void SQLCallback_OpenMembersMenu(Database db, DBResultSet results, const char[] error, int data)
1310{
1311 if (db == null)
1312 {
1313 SetDB();
1314 }
1315 int client = GetClientOfUserId(data);
1316 if (!IsValidClient(client))
1317 {
1318 return;
1319 }
1320 else
1321 {
1322 Menu menu = CreateMenu(MemberListMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
1323
1324 char sTitleString[128];
1325 Format(sTitleString, sizeof(sTitleString), "%T", "MemberList", client);
1326 SetMenuTitle(menu, sTitleString);
1327
1328 while (results.FetchRow())
1329 {
1330 char a_sTempArray[6][128]; // 0 - SteamID | 1 - Name | 2 - Invited By | 3 - Rank | 4 - Date (UTF) | 5 - Share
1331 results.FetchString(1, a_sTempArray[0], sizeof(a_sTempArray[])); // Steam-ID
1332 results.FetchString(2, a_sTempArray[1], sizeof(a_sTempArray[])); // Player Name
1333 results.FetchString(5, a_sTempArray[2], sizeof(a_sTempArray[])); // Invited By
1334 IntToString(results.FetchInt(4), a_sTempArray[3], sizeof(a_sTempArray[])); // Rank
1335 IntToString(results.FetchInt(6), a_sTempArray[4], sizeof(a_sTempArray[])); // Date
1336 IntToString(results.FetchInt(7), a_sTempArray[5], sizeof(a_sTempArray[])); // Share
1337
1338
1339 char sInfoString[128];
1340 char sDisplayString[128];
1341
1342 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]));
1343
1344 if (StrEqual(a_sTempArray[3], "0"))
1345 {
1346 Format(sDisplayString, sizeof(sDisplayString), "%s (%T)", a_sTempArray[1], "MemberRank", client);
1347 }
1348 else if (StrEqual(a_sTempArray[3], "1"))
1349 {
1350 Format(sDisplayString, sizeof(sDisplayString), "%s (%T)", a_sTempArray[1], "AdminRank", client);
1351 }
1352 else if (StrEqual(a_sTempArray[3], "2"))
1353 {
1354 Format(sDisplayString, sizeof(sDisplayString), "%s (%T)", a_sTempArray[1], "OwnerRank", client);
1355 }
1356 menu.AddItem(sInfoString, sDisplayString);
1357 }
1358 menu.ExitBackButton = true;
1359
1360 menu.Display(client, MENU_TIME_FOREVER);
1361 }
1362}
1363
1364public int MemberListMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
1365{
1366 switch (action)
1367 {
1368 case MenuAction_Select:
1369 {
1370 char sInfo[128];
1371 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1372 OpenIndividualMemberMenu(param1, sInfo);
1373 }
1374 case MenuAction_Cancel:
1375 {
1376 StartOpeningGangMenu(param1);
1377 }
1378 case MenuAction_End:
1379 {
1380 delete menu;
1381 }
1382 }
1383 return;
1384}
1385
1386void OpenIndividualMemberMenu(int client, char[] sInfo)
1387{
1388 Menu menu = CreateMenu(IndividualMemberMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
1389 SetMenuTitle(menu, "Information On : ");
1390
1391 char sTempArray[6][64]; // 0 - SteamID | 1 - Name | 2 - Invited By | 3 - Rank | 4 - Date (UTF) | 5 - Share
1392 char sDisplayBuffer[32];
1393
1394 ExplodeString(sInfo, ";", sTempArray, 6, sizeof(sTempArray[]));
1395
1396 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %s", "Name", client, sTempArray[1]);
1397 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1398
1399 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "Steam ID : %s", sTempArray[0]);
1400 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1401
1402 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %s", "InvitedBy", client, sTempArray[2]);
1403 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1404
1405
1406 if (StrEqual(sTempArray[3], "0"))
1407 {
1408 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %T", "Rank", client, "MemberRank", client);
1409 }
1410 else if (StrEqual(sTempArray[3], "1"))
1411 {
1412 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %T", "Rank", client, "AdminRank", client);
1413 }
1414 else if (StrEqual(sTempArray[3], "2"))
1415 {
1416 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %T", "Rank", client, "OwnerRank", client);
1417 }
1418 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1419
1420 char sFormattedTime[64];
1421 FormatTime(sFormattedTime, sizeof(sFormattedTime), "%x", StringToInt(sTempArray[4]));
1422 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %s", "DateJoined", client, sFormattedTime);
1423
1424 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1425
1426 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %i", "Share", client, StringToInt(sTempArray[5]));
1427 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1428
1429 menu.ExitBackButton = true;
1430
1431
1432 menu.Display(client, MENU_TIME_FOREVER);
1433}
1434
1435public int IndividualMemberMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
1436{
1437 switch (action)
1438 {
1439 case MenuAction_Select:
1440 {
1441
1442 }
1443 case MenuAction_Cancel:
1444 {
1445 StartOpeningMembersMenu(param1);
1446 }
1447 case MenuAction_End:
1448 {
1449 delete menu;
1450 }
1451 }
1452 return;
1453}
1454/*****************************************************************
1455*********************** INVITATION MENU **************************
1456******************************************************************/
1457
1458
1459
1460void OpenInvitationMenu(int client)
1461{
1462 Menu menu = CreateMenu(InvitationMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
1463
1464 char sInfoString[64];
1465 char sDisplayString[64];
1466 char sMenuString[32];
1467
1468 Format(sMenuString, sizeof(sMenuString), "%T", "InviteToGang", client);
1469 SetMenuTitle(menu, sMenuString);
1470
1471 for (int i = 1; i <= MaxClients; i++)
1472 {
1473 if (IsValidClient(i) && i != client)
1474 {
1475 Format(sInfoString, sizeof(sInfoString), "%i", GetClientUserId(i));
1476 Format(sDisplayString, sizeof(sDisplayString), "%N", i);
1477 SanitizeName(sDisplayString);
1478
1479 menu.AddItem(sInfoString, sDisplayString, (ga_bHasGang[i] || ga_iRank[client] == Rank_Normal)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1480 }
1481 }
1482
1483 menu.Display(client, MENU_TIME_FOREVER);
1484
1485}
1486
1487public int InvitationMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
1488{
1489 switch (action)
1490 {
1491 case MenuAction_Select:
1492 {
1493 char sInfo[64];
1494 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1495 int iUserID = StringToInt(sInfo);
1496
1497 ga_iInvitation[GetClientOfUserId(iUserID)] = GetClientUserId(param1);
1498
1499 if (ga_iGangSize[param1] >= gcv_iMaxGangSize.IntValue + ga_iSize[param1]
1500 && !gcv_bDisableSize.BoolValue)
1501 {
1502 PrintToChat(param1, "%s %t", TAG, "GangIsFull");
1503 return;
1504 }
1505
1506 if (!gcv_bInviteStyle.BoolValue)
1507 {
1508 PrintToChat(GetClientOfUserId(iUserID), "%s %t", TAG, "AcceptInstructions", ga_sGangName[param1]);
1509 }
1510 else
1511 {
1512 OpenGangInvitationMenu(GetClientOfUserId(iUserID));
1513 }
1514 StartOpeningGangMenu(param1);
1515 }
1516 case MenuAction_Cancel:
1517 {
1518 StartOpeningGangMenu(param1);
1519 }
1520 case MenuAction_End:
1521 {
1522 delete menu;
1523 }
1524 }
1525 return;
1526}
1527
1528
1529void OpenGangInvitationMenu(int client)
1530{
1531 if (!IsValidClient(client))
1532 {
1533 return;
1534 }
1535 Menu menu = CreateMenu(SentInviteMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
1536 char sDisplayString[64];
1537 char sTitleString[64];
1538
1539 Format(sTitleString, sizeof(sTitleString), "%T", "GangInvitation", client);
1540 SetMenuTitle(menu, sTitleString);
1541
1542 int sender = GetClientOfUserId(ga_iInvitation[client]);
1543 char senderName[MAX_NAME_LENGTH];
1544 GetClientName(sender, senderName, sizeof(senderName));
1545 SanitizeName(senderName);
1546
1547 Format(sDisplayString, sizeof(sDisplayString), "%T", "InviteString", client, senderName);
1548 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
1549
1550 Format(sDisplayString, sizeof(sDisplayString), "%T", "WouldYouLikeToJoin", client, ga_sGangName[sender]);
1551 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
1552
1553 Format(sDisplayString, sizeof(sDisplayString), "%T", "IWouldLikeTo", client);
1554 menu.AddItem("yes", sDisplayString);
1555
1556 Format(sDisplayString, sizeof(sDisplayString), "%T", "IWouldNotLikeTo", client);
1557 menu.AddItem("no", sDisplayString);
1558
1559 menu.Display(client, MENU_TIME_FOREVER);
1560}
1561
1562
1563public int SentInviteMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
1564{
1565 if (!IsValidClient(param1))
1566 {
1567 return;
1568 }
1569 switch (action)
1570 {
1571 case MenuAction_Select:
1572 {
1573 char sInfo[64];
1574 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1575 if (StrEqual(sInfo, "yes"))
1576 {
1577 int sender = GetClientOfUserId(ga_iInvitation[param1]);
1578
1579 if (ga_iGangSize[param1] >= gcv_iMaxGangSize.IntValue + ga_iSize[param1] && !gcv_bDisableSize.BoolValue)
1580 {
1581 PrintToChat(param1, "%s %t", TAG, "GangIsFull");
1582 return;
1583 }
1584 ga_sGangName[param1] = ga_sGangName[sender];
1585 ga_iDateJoined[param1] = GetTime();
1586 ga_bHasGang[param1] = true;
1587 ga_bSetName[param1] = false;
1588
1589 ga_iShare[param1] = 0;
1590
1591 ga_iFunds[param1] = ga_iFunds[sender];
1592 ga_iHealth[param1] = ga_iHealth[sender];
1593 ga_iCash[param1] = ga_iCash[sender];
1594 ga_iStore[param1] = ga_iStore[sender];
1595 ga_iMedishot[param1] = ga_iMedishot[sender];
1596 ga_iSize[param1] = ga_iSize[sender];
1597 ga_iGangSize[param1] = ++ga_iGangSize[sender];
1598
1599
1600 char sName[MAX_NAME_LENGTH];
1601 GetClientName(sender, sName, sizeof(sName));
1602 ga_sInvitedBy[param1] = sName;
1603 ga_iRank[param1] = Rank_Normal;
1604 UpdateSQL(param1);
1605
1606 for (int i = 0; i <= MaxClients; i++)
1607 {
1608 if (IsValidClient(i) && StrEqual(ga_sGangName[param1], ga_sGangName[i]))
1609 {
1610 LoadSteamID(i);
1611 }
1612 }
1613
1614
1615 char name[MAX_NAME_LENGTH];
1616 GetClientName(param1, name, sizeof(name));
1617
1618 PrintToChatAll("%s %T", TAG, "GangJoined", LANG_SERVER, name, ga_sGangName[param1]);
1619 }
1620 else if (StrEqual(sInfo, "no"))
1621 {
1622 // Do Nothing
1623 }
1624 }
1625 case MenuAction_Cancel:
1626 {
1627 StartOpeningGangMenu(param1);
1628 }
1629 case MenuAction_End:
1630 {
1631 delete menu;
1632 }
1633 }
1634 return;
1635}
1636
1637
1638/*****************************************************************
1639*********************** PERK MENU *************************
1640******************************************************************/
1641
1642
1643public void StartOpeningPerkMenu(int client)
1644{
1645 if (IsValidClient(client))
1646 {
1647 char sQuery[300];
1648 Format(sQuery, sizeof(sQuery), "SELECT health, cash, store, medishot, size, funds FROM hl_gangs_groups WHERE gang=\"%s\"", ga_sGangName[client]);
1649 g_hDatabase.Query(SQLCallback_Perks, sQuery, GetClientUserId(client));
1650 }
1651}
1652
1653public void SQLCallback_Perks(Database db, DBResultSet results, const char[] error, int data)
1654{
1655 if (db == null)
1656 {
1657 SetDB();
1658 }
1659
1660 int client = GetClientOfUserId(data);
1661
1662 if (!IsValidClient(client))
1663 {
1664 return;
1665 }
1666 else
1667 {
1668 Menu menu = CreateMenu(PerksMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
1669
1670 char sTitleString[64];
1671
1672 Format(sTitleString, sizeof(sTitleString), "%T", "GangPerks", client);
1673 SetMenuTitle(menu, sTitleString);
1674
1675 if (results.RowCount == 1 && results.FetchRow())
1676 {
1677 ga_iHealth[client] = results.FetchInt(0); // Health
1678 ga_iCash[client] = results.FetchInt(1); // Cash
1679 ga_iStore[client] = results.FetchInt(2); // Store credits
1680 ga_iMedishot[client] = results.FetchInt(3); // Medishot
1681 ga_iSize[client] = results.FetchInt(4);
1682 ga_iFunds[client] = results.FetchInt(5);
1683 }
1684
1685 char sDisplayBuffer[64];
1686
1687 int price;
1688
1689 if (!gcv_bDisableHealth.BoolValue)
1690 {
1691 price = gcv_iHealthPrice.IntValue * (ga_iHealth[client] + 1);
1692 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/5] [%i %T]", "Health", client, ga_iHealth[client], price, "Credits", client);
1693 menu.AddItem("health", sDisplayBuffer, (ga_iHealth[client] >= 5 || ga_iFunds[client] < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1694 }
1695
1696 if (!gcv_bDisableCash.BoolValue)
1697 {
1698 price = gcv_iCashPrice.IntValue * (ga_iCash[client] + 1);
1699 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/5] [%i %T]", "Cash", client, ga_iCash[client], price, "Credits", client);
1700 menu.AddItem("cash", sDisplayBuffer, (ga_iCash[client] >= 5 || ga_iFunds[client] < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1701 }
1702
1703 if (!gcv_bDisableStore.BoolValue)
1704 {
1705 price = gcv_iStorePrice.IntValue * (ga_iStore[client] + 1);
1706 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/5] [%i %T]", "Store", client, ga_iStore[client], price, "Credits", client);
1707 menu.AddItem("store", sDisplayBuffer, (ga_iStore[client] >= 5 || ga_iFunds[client] < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1708 }
1709
1710 if (!gcv_bDisableMedishot.BoolValue)
1711 {
1712 price = gcv_iMedishotPrice.IntValue * (ga_iMedishot[client] + 1);
1713 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/1] [%i %T]", "Medishot", client, ga_iMedishot[client], price, "Credits", client);
1714 menu.AddItem("medishot", sDisplayBuffer, (ga_iMedishot[client] >= 1 || ga_iFunds[client] < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1715 }
1716
1717 if (!gcv_bDisableSize.BoolValue && gcv_iMaxGangSize.IntValue != 0)
1718 {
1719 price = gcv_iSizePrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iSize[client]);
1720 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/%i] [%i %T]", "GangSize", client, ga_iSize[client], gcv_iGangSizeMaxUpgrades.IntValue, price, "Credits", client);
1721 menu.AddItem("size", sDisplayBuffer, (ga_iSize[client] >= gcv_iGangSizeMaxUpgrades.IntValue || ga_iFunds[client] < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1722 }
1723
1724
1725 Call_StartForward(g_hOnPerkMenu);
1726 Call_PushCell(client);
1727 Call_PushCell(menu);
1728 Call_Finish();
1729
1730 menu.ExitBackButton = true;
1731
1732 menu.Display(client, MENU_TIME_FOREVER);
1733 }
1734}
1735
1736public int PerksMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
1737{
1738 Call_StartForward(g_hOnPerkMenuCallback);
1739 Call_PushCell(menu);
1740 Call_PushCell(action);
1741 Call_PushCell(param1);
1742 Call_PushCell(param2);
1743 Call_Finish();
1744
1745 if (!IsValidClient(param1))
1746 {
1747 return;
1748 }
1749 switch (action)
1750 {
1751 case MenuAction_Select:
1752 {
1753 char sInfo[64];
1754 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1755 char sQuery[300];
1756
1757 if (StrEqual(sInfo, "health"))
1758 {
1759 int price = gcv_iHealthPrice.IntValue * (ga_iHealth[param1] + 1);
1760 ga_iFunds[param1] = ga_iFunds[param1] - price;
1761 ++ga_iHealth[param1];
1762 PrintToGang(param1, true, "%s %T", TAG, "HealthUpgrade", LANG_SERVER);
1763 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]);
1764 }
1765 else if (StrEqual(sInfo, "cash"))
1766 {
1767 int price = gcv_iCashPrice.IntValue * (ga_iCash[param1] + 1);
1768 ga_iFunds[param1] = ga_iFunds[param1] - price;
1769 ++ga_iCash[param1];
1770 PrintToGang(param1, true, "%s %T", TAG, "CashUpgrade", LANG_SERVER);
1771 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]);
1772 }
1773 else if (StrEqual(sInfo, "store"))
1774 {
1775 int price = gcv_iStorePrice.IntValue * (ga_iStore[param1] + 1);
1776 ga_iFunds[param1] = ga_iFunds[param1] - price;
1777 PrintToGang(param1, true, "%s %T", TAG, "StoreUpgrade", LANG_SERVER);
1778 ++ga_iStore[param1];
1779 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]);
1780 }
1781 else if (StrEqual(sInfo, "medishot"))
1782 {
1783 int price = gcv_iMedishotPrice.IntValue * (ga_iMedishot[param1] + 1);
1784 ga_iFunds[param1] = ga_iFunds[param1] - price;
1785 PrintToGang(param1, true, "%s %T", TAG, "MedishotUpgrade", LANG_SERVER);
1786 ++ga_iMedishot[param1];
1787 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]);
1788 }
1789 else if (StrEqual(sInfo, "size"))
1790 {
1791 int price = gcv_iSizePrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iSize[param1]);
1792 ga_iFunds[param1] = ga_iFunds[param1] - price;
1793 PrintToGang(param1, true, "%s %T", TAG, "SizeUpgrade", LANG_SERVER);
1794 ++ga_iSize[param1];
1795 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_groups SET size=%i WHERE gang=\"%s\"", ga_iSize[param1], ga_iFunds[param1], ga_sGangName[param1]);
1796 }
1797 g_hDatabase.Query(SQLCallback_Void, sQuery, GetClientUserId(param1));
1798
1799 StartOpeningPerkMenu(param1);
1800 }
1801 case MenuAction_Cancel:
1802 {
1803 StartOpeningGangMenu(param1);
1804 }
1805 case MenuAction_End:
1806 {
1807 delete menu;
1808 }
1809 }
1810 return;
1811}
1812
1813
1814/*****************************************************************
1815******************* LEAVE CONFIRMATION ********************
1816******************************************************************/
1817
1818
1819void OpenLeaveConfirmation(int client)
1820{
1821 Menu menu = CreateMenu(LeaveConfirmation_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
1822
1823 char tempBuffer[128];
1824
1825 Format(tempBuffer, sizeof(tempBuffer), "%T", "LeaveGang", client);
1826 SetMenuTitle(menu, tempBuffer);
1827
1828 Format(tempBuffer, sizeof(tempBuffer), "%T", "AreYouSure", client);
1829 menu.AddItem("", tempBuffer, ITEMDRAW_DISABLED);
1830 if (ga_iRank[client] == Rank_Owner)
1831 {
1832 Format(tempBuffer, sizeof(tempBuffer), "%T", "OwnerWarning", client);
1833 menu.AddItem("", tempBuffer, ITEMDRAW_DISABLED);
1834 }
1835
1836 Format(tempBuffer, sizeof(tempBuffer), "%T", "YesLeave", client);
1837 menu.AddItem("yes", tempBuffer);
1838
1839 Format(tempBuffer, sizeof(tempBuffer), "%T", "NoLeave", client);
1840 menu.AddItem("no", tempBuffer);
1841
1842 menu.ExitBackButton = true;
1843
1844 menu.Display(client, MENU_TIME_FOREVER);
1845}
1846
1847public int LeaveConfirmation_Callback(Menu menu, MenuAction action, int param1, int param2)
1848{
1849 switch (action)
1850 {
1851 case MenuAction_Select:
1852 {
1853 char sInfo[64];
1854 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1855 if (StrEqual(sInfo, "yes"))
1856 {
1857 RemoveFromGang(param1);
1858 }
1859 else if (StrEqual(sInfo, "no"))
1860 {
1861 StartOpeningGangMenu(param1);
1862 }
1863
1864 }
1865 case MenuAction_Cancel:
1866 {
1867 StartOpeningGangMenu(param1);
1868 }
1869 case MenuAction_End:
1870 {
1871 delete menu;
1872 }
1873 }
1874 return;
1875}
1876
1877
1878
1879
1880/*****************************************************************
1881********************* ADMIN MAIN MENU **************************
1882******************************************************************/
1883
1884
1885void OpenAdministrationMenu(int client)
1886{
1887 if (!IsValidClient(client))
1888 {
1889 return;
1890 }
1891 Menu menu = CreateMenu(AdministrationMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
1892
1893 char tempBuffer[128];
1894 Format(tempBuffer, sizeof(tempBuffer), "%T", "GangAdmin", client);
1895 SetMenuTitle(menu, tempBuffer);
1896
1897 char sDisplayString[128];
1898
1899 Format(sDisplayString, sizeof(sDisplayString), "%T", "KickAMember", client);
1900 menu.AddItem("kick", "Kick a member", (ga_iRank[client] == Rank_Normal)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1901
1902 Format(sDisplayString, sizeof(sDisplayString), "%T [%i %T]", "RenameGang", client, gcv_iRenamePrice.IntValue, "Credits", client);
1903 menu.AddItem("rename", sDisplayString, (ga_iRank[client] == Rank_Owner && ga_iFunds[client] >= gcv_iRenamePrice.IntValue)?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
1904
1905 Format(sDisplayString, sizeof(sDisplayString), "%T", "Promote", client);
1906 menu.AddItem("promote", sDisplayString, (ga_iRank[client] == Rank_Normal)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1907
1908 Format(sDisplayString, sizeof(sDisplayString), "%T", "Disband", client);
1909 menu.AddItem("disband", sDisplayString, (ga_iRank[client] == Rank_Owner)?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
1910
1911
1912 menu.ExitBackButton = true;
1913
1914 menu.Display(client, MENU_TIME_FOREVER);
1915
1916}
1917
1918public int AdministrationMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
1919{
1920 if (!IsValidClient(param1))
1921 {
1922 return;
1923 }
1924 switch (action)
1925 {
1926 case MenuAction_Select:
1927 {
1928 char sInfo[64];
1929 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1930 if (StrEqual(sInfo, "kick"))
1931 {
1932 OpenAdministrationKickMenu(param1);
1933 }
1934 else if (StrEqual(sInfo, "rename"))
1935 {
1936 for (int i = 1; i <= 5; i++)
1937 {
1938 PrintToChat(param1, "%s %t", TAG, "GangName");
1939 }
1940 ga_bRename[param1] = true;
1941 }
1942 else if (StrEqual(sInfo, "promote"))
1943 {
1944 OpenAdministrationPromotionMenu(param1);
1945 }
1946 else if (StrEqual(sInfo, "disband"))
1947 {
1948 OpenDisbandMenu(param1);
1949 }
1950 }
1951 case MenuAction_Cancel:
1952 {
1953 StartOpeningGangMenu(param1);
1954 }
1955 case MenuAction_End:
1956 {
1957 delete menu;
1958 }
1959 }
1960 return;
1961}
1962
1963
1964
1965/*****************************************************************
1966******************* ADMIN PROMOTION MENU ***********************
1967******************************************************************/
1968
1969
1970
1971
1972void OpenAdministrationPromotionMenu(int client)
1973{
1974 if (!StrEqual(ga_sGangName[client], ""))
1975 {
1976 char sQuery[200];
1977 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_players WHERE gang=\"%s\"", ga_sGangName[client]);
1978
1979 g_hDatabase.Query(SQLCallback_AdministrationPromotionMenu, sQuery, GetClientUserId(client));
1980 }
1981}
1982
1983public void SQLCallback_AdministrationPromotionMenu(Database db, DBResultSet results, const char[] error, int data)
1984{
1985 if (db == null)
1986 {
1987 SetDB();
1988 }
1989 int client = GetClientOfUserId(data);
1990 if (!IsValidClient(client))
1991 {
1992 return;
1993 }
1994 else
1995 {
1996 Menu menu = CreateMenu(AdministrationPromoMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
1997
1998 char tempBuffer[128];
1999 Format(tempBuffer, sizeof(tempBuffer), "%T", "Promote", client);
2000 SetMenuTitle(menu, tempBuffer);
2001
2002 while (results.FetchRow())
2003 {
2004 char sTempArray[3][128]; // 0 - SteamID | 1 - Name | 2 - Invited By | 3 - Rank | 4 - Date (UTF)
2005 results.FetchString(1, sTempArray[0], sizeof(sTempArray[])); // Steam-ID
2006 results.FetchString(2, sTempArray[1], sizeof(sTempArray[])); // Player Name
2007 IntToString(results.FetchInt(4), sTempArray[2], sizeof(sTempArray[])); // Rank
2008
2009 char sSteamID[34];
2010 GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
2011
2012 if (!StrEqual(sSteamID, sTempArray[0]))
2013 {
2014 char sInfoString[128];
2015 char sDisplayString[128];
2016 Format(sInfoString, sizeof(sInfoString), "%s;%s;%i", sTempArray[0], sTempArray[1], StringToInt(sTempArray[2]));
2017 Format(sDisplayString, sizeof(sDisplayString), "%s (%s)", sTempArray[1], sTempArray[0]);
2018 menu.AddItem(sInfoString, sDisplayString, (ga_iRank[client] == Rank_Owner)?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
2019 }
2020 }
2021 menu.ExitBackButton = true;
2022
2023 menu.Display(client, MENU_TIME_FOREVER);
2024 }
2025}
2026
2027public int AdministrationPromoMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
2028{
2029 switch (action)
2030 {
2031 case MenuAction_Select:
2032 {
2033 char sInfo[256];
2034 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2035
2036 OpenPromoteDemoteMenu(param1, sInfo);
2037 }
2038 case MenuAction_Cancel:
2039 {
2040 OpenAdministrationMenu(param1);
2041 }
2042 case MenuAction_End:
2043 {
2044 delete menu;
2045 }
2046 }
2047 return;
2048}
2049
2050
2051void OpenPromoteDemoteMenu(int client, const char[] sInfo)
2052{
2053 char sTempArray[3][32];
2054 ExplodeString(sInfo, ";", sTempArray, 3, 32);
2055
2056 Menu menu = CreateMenu(AdministrationPromoDemoteMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
2057
2058 char tempBuffer[128];
2059 Format(tempBuffer, sizeof(tempBuffer), "%T", "GangMembersRanks", client);
2060 SetMenuTitle(menu, tempBuffer);
2061
2062 char sInfoString[32];
2063
2064 Format(tempBuffer, sizeof(tempBuffer), "%T", "Simply", client);
2065 menu.AddItem("", tempBuffer, ITEMDRAW_DISABLED);
2066
2067 Format(sInfoString, sizeof(sInfoString), "%s;normal", sTempArray[0]);
2068 Format(tempBuffer, sizeof(tempBuffer), "%T", "MemberRank", client);
2069 menu.AddItem(sInfoString, tempBuffer, (ga_iRank[client] != Rank_Owner)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
2070
2071 Format(sInfoString, sizeof(sInfoString), "%s;admin", sTempArray[0]);
2072 Format(tempBuffer, sizeof(tempBuffer), "%T", "AdminRank", client);
2073 menu.AddItem(sInfoString, tempBuffer, (ga_iRank[client] != Rank_Owner)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
2074
2075 menu.ExitBackButton = true;
2076
2077 menu.Display(client, MENU_TIME_FOREVER);
2078}
2079
2080public int AdministrationPromoDemoteMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
2081{
2082 switch (action)
2083 {
2084 case MenuAction_Select:
2085 {
2086 char sInfo[256];
2087 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2088 char sTempArray[2][32];
2089 ExplodeString(sInfo, ";", sTempArray, 2, 32);
2090
2091 char sQuery[300];
2092
2093 if (StrEqual(sTempArray[1], "normal"))
2094 {
2095 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_players SET rank=0 WHERE steamid=\"%s\"", sTempArray[0]);
2096 }
2097 else if (StrEqual(sTempArray[1], "admin"))
2098 {
2099 Format(sQuery, sizeof(sQuery), "UPDATE hl_gangs_players SET rank=1 WHERE steamid=\"%s\"", sTempArray[0]);
2100 }
2101
2102 g_hDatabase.Query(SQLCallback_Void, sQuery);
2103 char sSteamID[32];
2104 for (int i = 1; i <= MaxClients; i++)
2105 {
2106 if (IsValidClient(i))
2107 {
2108 GetClientAuthId(i, AuthId_Steam2, sSteamID, sizeof(sSteamID));
2109 if (StrEqual(sSteamID, sTempArray[0]))
2110 {
2111 LoadSteamID(i);
2112 break;
2113 }
2114 }
2115 }
2116 }
2117 case MenuAction_Cancel:
2118 {
2119 OpenAdministrationMenu(param1);
2120 }
2121 case MenuAction_End:
2122 {
2123 delete menu;
2124 }
2125 }
2126 return;
2127}
2128
2129
2130
2131
2132
2133/*****************************************************************
2134********************* DISBAND MENU **************************
2135******************************************************************/
2136
2137
2138
2139
2140
2141
2142
2143void OpenDisbandMenu(int client)
2144{
2145 Menu menu = CreateMenu(DisbandMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
2146
2147 char tempString[128];
2148
2149 Format(tempString, sizeof(tempString), "%T", "DisbandGang", client);
2150 SetMenuTitle(menu, tempString);
2151
2152 Format(tempString, sizeof(tempString), "%T", "DisbandConfirmation", client);
2153 menu.AddItem("", tempString, ITEMDRAW_DISABLED);
2154
2155 Format(tempString, sizeof(tempString), "%T", "YesDisband", client);
2156 menu.AddItem("disband", tempString, (ga_iRank[client] != Rank_Owner)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
2157
2158 Format(tempString, sizeof(tempString), "%T", "NoDisband", client);
2159 menu.AddItem("no", tempString, (ga_iRank[client] != Rank_Owner)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
2160
2161 menu.ExitBackButton = true;
2162
2163 menu.Display(client, MENU_TIME_FOREVER);
2164}
2165
2166public int DisbandMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
2167{
2168 switch (action)
2169 {
2170 case MenuAction_Select:
2171 {
2172 char sInfo[256];
2173 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2174 if (StrEqual(sInfo, "disband"))
2175 {
2176 RemoveFromGang(param1);
2177 }
2178 }
2179 case MenuAction_Cancel:
2180 {
2181 OpenAdministrationMenu(param1);
2182 }
2183 case MenuAction_End:
2184 {
2185 delete menu;
2186 }
2187 }
2188 return;
2189}
2190
2191/*****************************************************************
2192********************* ADMIN KICK MENU **************************
2193******************************************************************/
2194
2195void OpenAdministrationKickMenu(int client)
2196{
2197 if (!StrEqual(ga_sGangName[client], ""))
2198 {
2199 char sQuery[200];
2200 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_players WHERE gang=\"%s\"", ga_sGangName[client]);
2201
2202 g_hDatabase.Query(SQLCallback_AdministrationKickMenu, sQuery, GetClientUserId(client));
2203 }
2204}
2205
2206public void SQLCallback_AdministrationKickMenu(Database db, DBResultSet results, const char[] error, int data)
2207{
2208 if (db == null)
2209 {
2210 SetDB();
2211 }
2212 int client = GetClientOfUserId(data);
2213 if (!IsValidClient(client))
2214 {
2215 return;
2216 }
2217 else
2218 {
2219
2220 Menu menu = CreateMenu(AdministrationKickMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
2221
2222 char tempString[128];
2223
2224 Format(tempString, sizeof(tempString), "%T", "KickGangMembers", client);
2225 SetMenuTitle(menu, tempString);
2226
2227 while (results.FetchRow())
2228 {
2229 char sTempArray[3][128]; // 0 - SteamID | 1 - Name | 2 - Invited By | 3 - Rank | 4 - Date (UTF)
2230 results.FetchString(1, sTempArray[0], sizeof(sTempArray[])); // Steam-ID
2231 results.FetchString(2, sTempArray[1], sizeof(sTempArray[])); // Player Name
2232 IntToString(results.FetchInt(4), sTempArray[2], sizeof(sTempArray[])); // Rank
2233 KickShare[client] = results.FetchInt(7);
2234
2235 PrintToChatAll("%s 1 kick %i client: %i", TAG, KickShare[client], client);
2236
2237 char sInfoString[128];
2238 char sDisplayString[128];
2239
2240 Format(sInfoString, sizeof(sInfoString), "%s;%s", sTempArray[0], sTempArray[1]);
2241 Format(sDisplayString, sizeof(sDisplayString), "%s (%s)", sTempArray[1], sTempArray[0]);
2242 menu.AddItem(sInfoString, sDisplayString, (ga_iRank[client] > view_as<GangRank>(StringToInt(sTempArray[2])))?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
2243 }
2244 menu.ExitBackButton = true;
2245
2246 menu.Display(client, MENU_TIME_FOREVER);
2247 }
2248}
2249
2250public int AdministrationKickMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
2251{
2252 switch (action)
2253 {
2254 case MenuAction_Select:
2255 {
2256 char sInfo[256];
2257 char sTempArray[2][128];
2258 char sQuery1[128];
2259
2260 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2261
2262 ExplodeString(sInfo, ";", sTempArray, 2, 128);
2263
2264 Format(sQuery1, sizeof(sQuery1), "DELETE FROM hl_gangs_players WHERE steamid = \"%s\"", sTempArray[0]);
2265 g_hDatabase.Query(SQLCallback_Void, sQuery1);
2266
2267 PrintToChatAll("%s 2 kick %i client: %i", TAG, KickShare[param1], param1);
2268
2269 KickShare[param1] = KickShare[param1] * 7 / 10;
2270
2271 PrintToChatAll("%s 3 kick %i", TAG, KickShare[param1]);
2272
2273 char sQuery2[300];
2274
2275 Format(sQuery2, sizeof(sQuery2), "UPDATE hl_gangs_groups SET funds = funds - %i WHERE gang=\"%s\"", KickShare[param1], ga_sGangName[param1]);
2276 g_hDatabase.Query(SQLCallback_Void, sQuery2);
2277
2278 Format(sQuery2, sizeof(sQuery2), "UPDATE hl_gangs_statistics SET value = value - %i WHERE gang=\"%s\"", KickShare[param1], ga_sGangName[param1]);
2279 g_hDatabase.Query(SQLCallback_Void, sQuery2);
2280
2281 PrintToChatAll("%s 4 kick %i", TAG, KickShare[param1]);
2282
2283 KickShare[param1] = 0;
2284
2285 PrintToChatAll("%s 5 kick %i", TAG, KickShare[param1]);
2286
2287 PrintToChatAll("%s %T", TAG, "GangMemberKick", LANG_SERVER, sTempArray[1], ga_sGangName[param1]);
2288
2289 char sSteamID[64];
2290 for (int i = 1; i <= MaxClients; i++)
2291 {
2292 if (IsValidClient(i))
2293 {
2294 GetClientAuthId(i, AuthId_Steam2, sSteamID, sizeof(sSteamID));
2295 if (StrEqual(sSteamID, sTempArray[0]))
2296 {
2297 ResetVariables(i);
2298 }
2299 }
2300 }
2301 }
2302 case MenuAction_Cancel:
2303 {
2304 OpenAdministrationMenu(param1);
2305 }
2306 case MenuAction_End:
2307 {
2308 delete menu;
2309 }
2310 }
2311}
2312
2313
2314/*****************************************************************
2315********************** TOP GANGS MENU **************************
2316******************************************************************/
2317
2318
2319
2320void StartOpeningTopGangsMenu(int client)
2321{
2322 if (IsValidClient(client))
2323 {
2324 g_hDatabase.Query(SQL_Callback_TopMenu, "SELECT * FROM hl_gangs_statistics ORDER BY value DESC", GetClientUserId(client));
2325 }
2326}
2327
2328public void SQL_Callback_TopMenu(Database db, DBResultSet results, const char[] error, int data)
2329{
2330 if (db == null)
2331 {
2332 SetDB();
2333 }
2334
2335 if (results == null)
2336 {
2337 LogError(error);
2338 return;
2339 }
2340
2341 int client = GetClientOfUserId(data);
2342 if (!IsValidClient(client))
2343 {
2344 return;
2345 }
2346 else
2347 {
2348 Menu menu = CreateMenu(TopGangsMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
2349
2350 char menuTitle[64];
2351 Format(menuTitle, sizeof(menuTitle), "%T", "TopGangs", client);
2352 menu.SetTitle(menuTitle);
2353 if (results.RowCount == 0)
2354 {
2355 PrintToChat(client, "%s %t", TAG, "NoGangs");
2356
2357 delete menu;
2358 return;
2359 }
2360 char sGangName[128];
2361 char sInfoString[128];
2362
2363
2364 ga_iTempInt2[client] = 0;
2365 g_iGangAmmount = 0;
2366 while (results.FetchRow())
2367 {
2368 g_iGangAmmount++;
2369 ga_iTempInt2[client]++;
2370
2371 results.FetchString(1, sGangName, sizeof(sGangName));
2372
2373 Format(sInfoString, sizeof(sInfoString), "%i;%s;%i", ga_iTempInt2[client], sGangName, results.FetchInt(2));
2374
2375 menu.AddItem(sInfoString, sGangName);
2376 }
2377
2378 menu.ExitBackButton = true;
2379
2380 menu.Display(client, MENU_TIME_FOREVER);
2381 }
2382}
2383
2384public int TopGangsMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
2385{
2386 switch (action)
2387 {
2388 case MenuAction_Select:
2389 {
2390 char sInfo[300];
2391 char sQuery[300];
2392 char sTempArray[3][128];
2393 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2394
2395 ExplodeString(sInfo, ";", sTempArray, 3, sizeof(sTempArray[]));
2396
2397 ga_iTempInt2[param1] = StringToInt(sTempArray[0]);
2398 ga_iTempInt[param1] = StringToInt(sTempArray[2]);
2399
2400 Format(sQuery, sizeof(sQuery), "SELECT * FROM `hl_gangs_players` WHERE `gang` = \"%s\" AND `rank` = 2", sTempArray[1]);
2401 g_hDatabase.Query(SQL_Callback_GangStatistics, sQuery, GetClientUserId(param1));
2402
2403 }
2404 case MenuAction_Cancel:
2405 {
2406 StartOpeningGangMenu(param1);
2407 }
2408 case MenuAction_End:
2409 {
2410 delete menu;
2411 }
2412 }
2413 return;
2414}
2415
2416
2417public void SQL_Callback_GangStatistics(Database db, DBResultSet results, const char[] error, int data)
2418{
2419 if (db == null)
2420 {
2421 SetDB();
2422 }
2423
2424 if (results == null)
2425 {
2426 LogError(error);
2427 return;
2428 }
2429
2430 int client = GetClientOfUserId(data);
2431 if (!IsValidClient(client))
2432 {
2433 return;
2434 }
2435 else
2436 {
2437 char sTempArray[2][128]; // Gang Name | Player Name
2438 char sFormattedTime[64];
2439 char sDisplayString[128];
2440
2441 results.FetchRow();
2442
2443
2444 results.FetchString(3, sTempArray[0], sizeof(sTempArray[]));
2445 results.FetchString(2, sTempArray[1], sizeof(sTempArray[]));
2446 int iDate = results.FetchInt(6);
2447
2448 Menu menu = CreateMenu(MenuCallback_Void, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
2449 menu.SetTitle("Top Gangs");
2450
2451 Format(sDisplayString, sizeof(sDisplayString), "%T : %s", "MenuGangName", client, sTempArray[0]);
2452 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2453
2454 Format(sDisplayString, sizeof(sDisplayString), "%T : %i/%i", "GangRank", client, ga_iTempInt2[client], g_iGangAmmount);
2455 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2456
2457 FormatTime(sFormattedTime, sizeof(sFormattedTime), "%x", iDate);
2458 Format(sDisplayString, sizeof(sDisplayString), "%T : %s", "DateCreated", client, sFormattedTime);
2459 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2460
2461 Format(sDisplayString, sizeof(sDisplayString), "%T : %s", "CreatedBy", client, sTempArray[1]);
2462 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2463
2464 Format(sDisplayString, sizeof(sDisplayString), "%T : %i ", "Value", client, ga_iTempInt[client]);
2465 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2466
2467 menu.ExitBackButton = true;
2468
2469 menu.Display(client, MENU_TIME_FOREVER);
2470 }
2471}
2472
2473public int MenuCallback_Void(Menu menu, MenuAction action, int param1, int param2)
2474{
2475 switch (action)
2476 {
2477 case MenuAction_Select:
2478 {
2479 // Do Nothing
2480 }
2481 case MenuAction_Cancel:
2482 {
2483 StartOpeningTopGangsMenu(param1);
2484 }
2485 case MenuAction_End:
2486 {
2487 delete menu;
2488 }
2489 }
2490 return;
2491}
2492
2493/*****************************************************************
2494*********************** HELPER FUNCTIONS ***********************
2495******************************************************************/
2496
2497
2498void UpdateSQL(int client)
2499{
2500 DeleteDuplicates();
2501
2502 /* We need to ensure that users are completely loaded in before calling save queries.
2503 * This may prevent errors where CT kills are reset to zero. */
2504 if (ga_bHasGang[client] && ga_bLoaded[client])
2505 {
2506 GetClientAuthId(client, AuthId_Steam2, ga_sSteamID[client], sizeof(ga_sSteamID[]));
2507
2508 char sQuery[300];
2509 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_gangs_players WHERE steamid=\"%s\"", ga_sSteamID[client]);
2510
2511 g_hDatabase.Query(SQLCallback_CheckIfInDatabase_Player, sQuery, GetClientUserId(client));
2512 }
2513}
2514
2515public void SQLCallback_CheckIfInDatabase_Player(Database db, DBResultSet results, const char[] error, int data)
2516{
2517 if (db == null)
2518 {
2519 SetDB();
2520 }
2521
2522 int client = GetClientOfUserId(data);
2523
2524 if (!IsValidClient(client))
2525 {
2526 return;
2527 }
2528 if (results.RowCount == 0)
2529 {
2530 ga_bIsPlayerInDatabase[client] = false;
2531 }
2532 else
2533 {
2534 ga_bIsPlayerInDatabase[client] = true;
2535 }
2536
2537 char sQuery[300];
2538 char playerName[MAX_NAME_LENGTH], escapedName[MAXPLAYERS*2+1];
2539
2540 GetClientName(client, playerName, sizeof(playerName));
2541 g_hDatabase.Escape(playerName, escapedName, sizeof(escapedName));
2542
2543 if (!ga_bIsPlayerInDatabase[client])
2544 {
2545 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]);
2546 }
2547 else
2548 {
2549 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]);
2550 }
2551 g_hDatabase.Query(SQLCallback_Void, sQuery);
2552
2553 char sQuery2[128];
2554
2555 Format(sQuery2, sizeof(sQuery2), "SELECT * FROM hl_gangs_groups WHERE gang=\"%s\"", ga_sGangName[client]);
2556
2557 g_hDatabase.Query(SQLCALLBACK_GROUPS, sQuery2, GetClientUserId(client));
2558}
2559
2560public void SQLCALLBACK_GROUPS(Database db, DBResultSet results, const char[] error, int data)
2561{
2562 if (db == null)
2563 {
2564 SetDB();
2565 }
2566
2567 int client = GetClientOfUserId(data);
2568
2569 if (!IsValidClient(client))
2570 {
2571 return;
2572 }
2573
2574 if (results.RowCount == 0)
2575 {
2576 ga_bIsGangInDatabase[client] = false;
2577 }
2578 else
2579 {
2580 ga_bIsGangInDatabase[client] = true;
2581 }
2582
2583 char sQuery[300];
2584 if (!ga_bIsGangInDatabase[client])
2585 {
2586 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]);
2587 }
2588 else
2589 {
2590 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]);
2591 }
2592
2593 g_hDatabase.Query(SQLCallback_Void, sQuery);
2594
2595}
2596
2597void SetDB()
2598{
2599 if (g_hDatabase == null)
2600 {
2601 gcv_sDatabase.GetString(g_sDatabaseName, sizeof(g_sDatabaseName));
2602 Database.Connect(SQLCallback_Connect, g_sDatabaseName);
2603 }
2604}
2605
2606void DeleteDuplicates()
2607{
2608 if (g_hDatabase != null)
2609 {
2610 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);
2611 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);
2612 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);
2613 }
2614}
2615
2616int GetClientCredits(int client)
2617{
2618 if (g_bZepyhrus)
2619 {
2620 return Store_GetClientCredits(client);
2621 }
2622 else
2623 {
2624 SetFailState("ERROR: No supported credits plugin loaded!");
2625 return 0;
2626 }
2627}
2628
2629void SetClientCredits(int client, int iAmmount)
2630{
2631 if (g_bZepyhrus)
2632 {
2633 Store_SetClientCredits(client, iAmmount);
2634 }
2635 else
2636 {
2637 SetFailState("ERROR: No supported credits plugin loaded!");
2638 }
2639}
2640
2641void RemoveFromGang(int client)
2642{
2643 if (ga_iRank[client] == Rank_Owner)
2644 {
2645 char sQuery1[300];
2646 char sQuery2[300];
2647 char sQuery3[300];
2648 Format(sQuery1, sizeof(sQuery1), "DELETE FROM hl_gangs_players WHERE gang = \"%s\"", ga_sGangName[client]);
2649 Format(sQuery2, sizeof(sQuery2), "DELETE FROM hl_gangs_groups WHERE gang = \"%s\"", ga_sGangName[client]);
2650 Format(sQuery3, sizeof(sQuery3), "DELETE FROM hl_gangs_statistics WHERE gang = \"%s\"", ga_sGangName[client]);
2651
2652 g_hDatabase.Query(SQLCallback_Void, sQuery1);
2653 g_hDatabase.Query(SQLCallback_Void, sQuery2);
2654 g_hDatabase.Query(SQLCallback_Void, sQuery3);
2655
2656 char name[MAX_NAME_LENGTH];
2657 GetClientName(client, name, sizeof(name));
2658 PrintToChatAll("%s %T", TAG, "GangDisbanded", LANG_SERVER, name, ga_sGangName[client]);
2659 for (int i = 1; i <= MaxClients; i++)
2660 {
2661 if (IsValidClient(i) && StrEqual(ga_sGangName[i], ga_sGangName[client]) && i != client)
2662 {
2663 ResetVariables(i);
2664 }
2665 }
2666 ResetVariables(client);
2667 }
2668 else
2669 {
2670 char sQuery1[128];
2671 Format(sQuery1, sizeof(sQuery1), "DELETE FROM hl_gangs_players WHERE steamid = \"%s\"", ga_sSteamID[client]);
2672 g_hDatabase.Query(SQLCallback_Void, sQuery1);
2673
2674 char name[MAX_NAME_LENGTH];
2675 GetClientName(client, name, sizeof(name));
2676 PrintToChatAll("%s %T", TAG, "LeftGang", LANG_SERVER, name, ga_sGangName[client]);
2677 ResetVariables(client);
2678 }
2679}
2680
2681void PrintToGang(int client, bool bPrintToClient = false, const char[] sMsg, any ...)
2682{
2683 if(!IsValidClient(client))
2684 {
2685 return;
2686 }
2687 char sFormattedMsg[256];
2688 VFormat(sFormattedMsg, sizeof(sFormattedMsg), sMsg, 4);
2689
2690 for (int i = 1; i <= MaxClients; i++)
2691 {
2692 if (IsValidClient(i) && StrEqual(ga_sGangName[i], ga_sGangName[client]) && !StrEqual(ga_sGangName[client], ""))
2693 {
2694 if (bPrintToClient)
2695 {
2696 PrintToChat(i, sFormattedMsg);
2697 }
2698 else
2699 {
2700 if (i == client)
2701 {
2702 // Do nothing
2703 }
2704 else
2705 {
2706 PrintToChat(i, sFormattedMsg);
2707 }
2708 }
2709 }
2710 }
2711}
2712
2713
2714void ResetVariables(int client)
2715{
2716 ga_iRank[client] = Rank_Invalid;
2717 ga_iGangSize[client] = -1;
2718 ga_iInvitation[client] = -1;
2719 ga_iDateJoined[client] = -1;
2720 ga_iShare[client] = 0;
2721 ga_iFunds[client] = 0;
2722 ga_iHealth[client] = 0;
2723 ga_iCash[client] = 0;
2724 ga_iStore[client] = 0;
2725 ga_iMedishot[client] = 0;
2726 ga_iSize[client] = 0;
2727 ga_iTempInt[client] = 0;
2728 ga_iTempInt2[client] = 0;
2729 ga_sGangName[client] = "";
2730 ga_sInvitedBy[client] = "";
2731 ga_bSetName[client] = false;
2732 ga_bIsPlayerInDatabase[client] = false;
2733 ga_bIsGangInDatabase[client] = false;
2734 ga_bHasGang[client] = false;
2735 ga_bRename[client] = false;
2736 ga_sSteamID[client] = "";
2737 ga_bLoaded[client] = false;
2738}
2739
2740// to avoid this https://user-images.githubusercontent.com/3672466/28637962-0d324952-724c-11e7-8b27-15ff021f0a59.png
2741void SanitizeName(char[] name)
2742{
2743 ReplaceString(name, MAX_NAME_LENGTH, "#", "?");
2744}
2745
2746bool IsValidClient(int client, bool bAllowBots = false, bool bAllowDead = true)
2747{
2748 if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
2749 {
2750 return false;
2751 }
2752 return true;
2753}