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