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