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