Advertisement
supertimor

Untitled

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