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