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