Advertisement
Guest User

Untitled

a guest
May 7th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 38.01 KB | None | 0 0
  1. /*
  2.  * MyJailbreak - Ratio Plugin.
  3.  * by: shanapu
  4.  * https://github.com/shanapu/MyJailbreak/
  5.  *
  6.  * This file is part of the MyJailbreak SourceMod Plugin.
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify it under
  9.  * the terms of the GNU General Public License, version 3.0, as published by the
  10.  * Free Software Foundation.
  11.  *
  12.  * This program is distributed in the hope that it will be useful, but WITHOUT
  13.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  14.  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  15.  * details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License along with
  18.  * this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  */
  20.  
  21.  
  22. /******************************************************************************
  23.                    STARTUP
  24. ******************************************************************************/
  25.  
  26.  
  27. //Includes
  28. #include <sourcemod>
  29. #include <sdktools>
  30. #include <sdkhooks>
  31. #include <cstrike>
  32. #include <colors>
  33. #include <autoexecconfig>
  34. #include <mystocks>
  35.  
  36. //Optional Plugins
  37. #undef REQUIRE_PLUGIN
  38. #include <myjailbreak>
  39. #include <warden>
  40. #define REQUIRE_PLUGIN
  41.  
  42.  
  43. //Compiler Options
  44. #pragma semicolon 1
  45. #pragma newdecls required
  46.  
  47.  
  48. //Console Variables
  49. ConVar gc_fPrisonerPerGuard;
  50. ConVar gc_sCustomCommandGuard;
  51. ConVar gc_sCustomCommandQueue;
  52. ConVar gc_sCustomCommandLeave;
  53. ConVar gc_sCustomCommandRatio;
  54. ConVar gc_sCustomCommandRemove;
  55. ConVar gc_sAdminFlag;
  56. ConVar gc_bToggle;
  57. ConVar gc_bToggleAnnounce;
  58. ConVar gc_bAdsVIP;
  59. ConVar gc_bVIPQueue;
  60. ConVar gc_bAdminBypass;
  61. ConVar gc_bForceTConnect;
  62. ConVar gc_iJoinMode;
  63. ConVar gc_iQuestionTimes;
  64. ConVar gc_bBalanceTerror;
  65. ConVar gc_bBalanceGuards;
  66. ConVar gc_bBalanceWarden;
  67. ConVar gc_bRespawn;
  68.  
  69.  
  70. //Booleans
  71. bool g_bRatioEnable = true;
  72. bool g_bQueueCooldown[MAXPLAYERS+1] = false;
  73. bool gp_bWarden = false;
  74.  
  75.  
  76. //Handles
  77. Handle g_aGuardQueue;
  78. Handle g_aGuardList;
  79. Handle g_hOnClientJoinGuards;
  80.  
  81.  
  82. //Integer
  83. int g_iRandomAnswer[MAXPLAYERS+1];
  84. int g_iQuestionTimes[MAXPLAYERS+1];
  85.  
  86.  
  87. //Strings
  88. char g_sRestrictedSound[32] = "buttons/button11.wav";
  89. char g_sRightAnswerSound[32] = "buttons/button14.wav";
  90. char g_sAdminFlag[32];
  91.  
  92.  
  93. //Info
  94. public Plugin myinfo = {
  95.     name = "MyJailbreak - Ratio",
  96.     author = "shanapu, Addicted",
  97.     description = "Jailbreak team balance / ratio plugin",
  98.     version = MYJB_VERSION,
  99.     url = MYJB_URL_LINK
  100. };
  101.  
  102.  
  103. //Start
  104. public void OnPluginStart()
  105. {
  106.     //Translation
  107.     LoadTranslations("MyJailbreak.Ratio.phrases");
  108.    
  109.    
  110.     //Client commands
  111.     RegConsoleCmd("sm_guard", Command_JoinGuardQueue, "Allows the prisoners to queue to CT");
  112.     RegConsoleCmd("sm_viewqueue", Command_ViewGuardQueue, "Allows a player to show queue to CT");
  113.     RegConsoleCmd("sm_leavequeue", Command_LeaveQueue, "Allows a player to leave queue to CT");
  114.     RegConsoleCmd("sm_ratio", Command_ToggleRatio, "Allows the admin toggle the ratio check and player to see if ratio is enabled");
  115.    
  116.    
  117.     //Admin commands
  118.     RegAdminCmd("sm_removequeue", AdminCommand_RemoveFromQueue, ADMFLAG_GENERIC, "Allows the admin to remove player from queue to CT");
  119.     RegAdminCmd("sm_clearqueue", AdminCommand_ClearQueue, ADMFLAG_GENERIC, "Allows the admin clear the CT queue");
  120.    
  121.     //AutoExecConfig
  122.     AutoExecConfig_SetFile("Ratio", "MyJailbreak");
  123.     AutoExecConfig_SetCreateFile(true);
  124.    
  125.     AutoExecConfig_CreateConVar("sm_ratio_version", MYJB_VERSION, "The version of this MyJailbreak SourceMod plugin", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
  126.     gc_sCustomCommandGuard = AutoExecConfig_CreateConVar("sm_ratio_cmds_guard", "g, ct, guards", "Set your custom chat command for become guard(!guard (no 'sm_'/'!')(seperate with comma ', ')(max. 12 commands))");
  127.     gc_sCustomCommandQueue = AutoExecConfig_CreateConVar("sm_ratio_cmds_queue", "vq, queue", "Set your custom chat command for view guard queue (!viewqueue (no 'sm_'/'!')(seperate with comma ', ')(max. 12 commands))");
  128.     gc_sCustomCommandLeave = AutoExecConfig_CreateConVar("sm_ratio_cmds_leave", "lq, stay", "Set your custom chat command for view leave queue (!leavequeue (no 'sm_'/'!')(seperate with comma ', ')(max. 12 commands))");
  129.     gc_sCustomCommandRatio = AutoExecConfig_CreateConVar("sm_ratio_cmds_ratio", "balance", "Set your custom chat command for view/toggle ratio (!ratio (no 'sm_'/'!')(seperate with comma ', ')(max. 12 commands))");
  130.     gc_sCustomCommandRemove = AutoExecConfig_CreateConVar("sm_ratio_cmds_remove", "rq", "Set your custom chat command for admins to remove a player from guard queue (!removequeue (no 'sm_'/'!')(seperate with comma ', ')(max. 12 commands))");
  131.     gc_fPrisonerPerGuard = AutoExecConfig_CreateConVar("sm_ratio_T_per_CT", "2", "How many prisoners for each guard.", _, true, 1.0);
  132.     gc_bVIPQueue = AutoExecConfig_CreateConVar("sm_ratio_flag", "1", "0 - disabled, 1 - enable VIPs moved to front of queue", _, true,  0.0, true, 1.0);
  133.     gc_bForceTConnect = AutoExecConfig_CreateConVar("sm_ratio_force_t", "1", "0 - disabled, 1 - force player on connect to join T side", _, true,  0.0, true, 1.0);
  134.     gc_sAdminFlag = AutoExecConfig_CreateConVar("sm_ratio_vipflag", "a", "Set the flag for VIP");
  135.     gc_bToggle = AutoExecConfig_CreateConVar("sm_ratio_disable", "0", "Allow the admin to toggle 'ratio check & autoswap' on/off with !ratio", _, true,  0.0, true, 1.0);
  136.     gc_bToggleAnnounce = AutoExecConfig_CreateConVar("sm_ratio_disable_announce", "0", "Announce in a chatmessage on roundend when ratio is disabled", _, true,  0.0, true, 1.0);
  137.     gc_bAdsVIP = AutoExecConfig_CreateConVar("sm_ratio_adsvip", "1", "0 - disabled, 1 - enable adverstiment for 'VIPs moved to front of queue' when player types !quard ", _, true,  0.0, true, 1.0);
  138.     gc_iJoinMode = AutoExecConfig_CreateConVar("sm_ratio_join_mode", "1", "0 - instandly join ct/queue, no confirmation / 1 - confirm rules / 2 - Qualification questions", _, true,  0.0, true, 2.0);
  139.     gc_iQuestionTimes = AutoExecConfig_CreateConVar("sm_ratio_questions", "3", "How many question a player have to answer before join ct/queue. need sm_ratio_join_mode 2", _, true,  1.0, true, 5.0);
  140.     gc_bAdminBypass = AutoExecConfig_CreateConVar("sm_ratio_vip_bypass", "1", "Bypass Admin/VIP though agreement / question", _, true,  0.0, true, 1.0);
  141.     gc_bBalanceTerror = AutoExecConfig_CreateConVar("sm_ratio_balance_terror", "1", "0 = Could result in unbalanced teams. 1 = Switch a random T, when nobody is in guardqueue to balance the teams.", _, true, 0.0, true, 1.0);
  142.     gc_bBalanceGuards = AutoExecConfig_CreateConVar("sm_ratio_balance_guard", "1", "Mode to choose a guard to be switch to T on balance the teams. 1 = Last In First Out / 0 = Random Guard", _, true, 0.0, true, 1.0);
  143.     gc_bBalanceWarden = AutoExecConfig_CreateConVar("sm_ratio_balance_warden", "1", "Prevent warden & deputy to be switch to T on balance the teams. Could result in unbalanced teams", _, true, 0.0, true, 1.0);
  144.     gc_bRespawn = AutoExecConfig_CreateConVar("sm_ratio_respawn", "1", "0 - Move player on next round to CT / 1 - Move player immediately to CT and respawn", _, true, 0.0, true, 1.0);
  145.    
  146.     AutoExecConfig_ExecuteFile();
  147.     AutoExecConfig_CleanFile();
  148.    
  149.    
  150.     //Hooks
  151.     AddCommandListener(Event_OnJoinTeam, "jointeam");
  152.     HookEvent("player_connect_full", Event_OnFullConnect, EventHookMode_Pre);
  153.     HookEvent("player_team", Event_PlayerTeam_Post, EventHookMode_Post);
  154.     HookEvent("round_end", Event_RoundEnd_Post, EventHookMode_Post);
  155.    
  156.    
  157.     //FindConVar
  158.     gc_sAdminFlag.GetString(g_sAdminFlag, sizeof(g_sAdminFlag));
  159.    
  160.    
  161.     //Prepare
  162.     g_aGuardQueue = CreateArray();
  163.     g_aGuardList = CreateArray();
  164. }
  165.  
  166.  
  167. public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
  168. {
  169.     g_hOnClientJoinGuards = CreateGlobalForward("MyJailbreak_OnJoinGuardQueue", ET_Event, Param_Cell);
  170.    
  171.     RegPluginLibrary("myratio");
  172.     return APLRes_Success;
  173. }
  174.  
  175.  
  176. public void OnConfigsExecuted()
  177. {
  178.     Handle hConVar = FindConVar("mp_force_pick_time");
  179.     if (hConVar == INVALID_HANDLE)
  180.         return;
  181.    
  182.     HookConVarChange(hConVar, OnForcePickTimeChanged);
  183.     SetConVarInt(hConVar, 999999);
  184.    
  185.    
  186.     //Set custom Commands
  187.     int iCount = 0;
  188.     char sCommands[128], sCommandsL[12][32], sCommand[32];
  189.    
  190.     //Join Guardqueue
  191.     gc_sCustomCommandGuard.GetString(sCommands, sizeof(sCommands));
  192.     ReplaceString(sCommands, sizeof(sCommands), " ", "");
  193.     iCount = ExplodeString(sCommands, ",", sCommandsL, sizeof(sCommandsL), sizeof(sCommandsL[]));
  194.    
  195.     for (int i = 0; i < iCount; i++)
  196.     {
  197.         Format(sCommand, sizeof(sCommand), "sm_%s", sCommandsL[i]);
  198.         if (GetCommandFlags(sCommand) == INVALID_FCVAR_FLAGS)  //if command not already exist
  199.             RegConsoleCmd(sCommand, Command_JoinGuardQueue, "Allows the prisoners to queue to CT");
  200.     }
  201.    
  202.     //View guardqueue
  203.     gc_sCustomCommandQueue.GetString(sCommands, sizeof(sCommands));
  204.     ReplaceString(sCommands, sizeof(sCommands), " ", "");
  205.     iCount = ExplodeString(sCommands, ",", sCommandsL, sizeof(sCommandsL), sizeof(sCommandsL[]));
  206.    
  207.     for (int i = 0; i < iCount; i++)
  208.     {
  209.         Format(sCommand, sizeof(sCommand), "sm_%s", sCommandsL[i]);
  210.         if (GetCommandFlags(sCommand) == INVALID_FCVAR_FLAGS)  //if command not already exist
  211.             RegConsoleCmd(sCommand, Command_ViewGuardQueue, "Allows a player to show queue to CT");
  212.     }
  213.    
  214.     //leave guardqueue
  215.     gc_sCustomCommandLeave.GetString(sCommands, sizeof(sCommands));
  216.     ReplaceString(sCommands, sizeof(sCommands), " ", "");
  217.     iCount = ExplodeString(sCommands, ",", sCommandsL, sizeof(sCommandsL), sizeof(sCommandsL[]));
  218.    
  219.     for (int i = 0; i < iCount; i++)
  220.     {
  221.         Format(sCommand, sizeof(sCommand), "sm_%s", sCommandsL[i]);
  222.         if (GetCommandFlags(sCommand) == INVALID_FCVAR_FLAGS)  //if command not already exist
  223.             RegConsoleCmd(sCommand, Command_LeaveQueue, "Allows a player to leave queue to CT");
  224.     }
  225.    
  226.     //View/toggle ratio
  227.     gc_sCustomCommandRatio.GetString(sCommands, sizeof(sCommands));
  228.     ReplaceString(sCommands, sizeof(sCommands), " ", "");
  229.     iCount = ExplodeString(sCommands, ",", sCommandsL, sizeof(sCommandsL), sizeof(sCommandsL[]));
  230.    
  231.     for (int i = 0; i < iCount; i++)
  232.     {
  233.         Format(sCommand, sizeof(sCommand), "sm_%s", sCommandsL[i]);
  234.         if (GetCommandFlags(sCommand) == INVALID_FCVAR_FLAGS)  //if command not already exist
  235.             RegConsoleCmd(sCommand, Command_ToggleRatio, "Allows the admin toggle the ratio check and player to see if ratio is enabled");
  236.     }
  237.    
  238.     //Admin remove player from queue
  239.     gc_sCustomCommandRemove.GetString(sCommands, sizeof(sCommands));
  240.     ReplaceString(sCommands, sizeof(sCommands), " ", "");
  241.     iCount = ExplodeString(sCommands, ",", sCommandsL, sizeof(sCommandsL), sizeof(sCommandsL[]));
  242.    
  243.     for (int i = 0; i < iCount; i++)
  244.     {
  245.         Format(sCommand, sizeof(sCommand), "sm_%s", sCommandsL[i]);
  246.         if (GetCommandFlags(sCommand) == INVALID_FCVAR_FLAGS)  //if command not already exist
  247.             RegAdminCmd(sCommand, AdminCommand_RemoveFromQueue, ADMFLAG_GENERIC, "Allows the admin to remove player from queue to CT");
  248.     }
  249. }
  250.  
  251.  
  252. public void OnAllPluginsLoaded()
  253. {
  254.     gp_bWarden = LibraryExists("warden");
  255. }
  256.  
  257.  
  258. public void OnLibraryRemoved(const char[] name)
  259. {
  260.     if (StrEqual(name, "warden"))
  261.         gp_bWarden = false;
  262. }
  263.  
  264.  
  265. public void OnLibraryAdded(const char[] name)
  266. {
  267.     if (StrEqual(name, "warden"))
  268.         gp_bWarden = true;
  269. }
  270.  
  271.  
  272. /******************************************************************************
  273.                    COMMANDS
  274. ******************************************************************************/
  275.  
  276.  
  277. public Action Command_LeaveQueue(int client, int iArgNum)
  278. {
  279.     int iIndex = FindValueInArray(g_aGuardQueue, client);
  280.    
  281.     if (!g_bRatioEnable)
  282.     {
  283.         CReplyToCommand(client, "%t %t", "ratio_tag", "ratio_disabled");
  284.         return Plugin_Handled;
  285.     }
  286.    
  287.     if (iIndex == -1)
  288.     {
  289.         CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_notonqueue");
  290.         return Plugin_Handled;
  291.     }
  292.     else
  293.     {
  294.         RemovePlayerFromGuardQueue(client);
  295.         CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_leavedqueue");
  296.         return Plugin_Handled;
  297.     }
  298. }
  299.  
  300.  
  301. public Action Command_ViewGuardQueue(int client, int args)
  302. {
  303.     if (!IsValidClient(client, true, true))
  304.         return Plugin_Handled;
  305.    
  306.     if (!g_bRatioEnable)
  307.     {
  308.         CReplyToCommand(client, "%t %t", "ratio_tag", "ratio_disabled");
  309.         return Plugin_Handled;
  310.     }
  311.    
  312.     if (GetArraySize(g_aGuardQueue) < 1)
  313.     {
  314.         CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_empty");
  315.         return Plugin_Handled;
  316.     }
  317.     char info[64];
  318.    
  319.     Handle ViewQueueMenu = CreatePanel();
  320.    
  321.     Format(info, sizeof(info), "%T", "ratio_info_title", client);
  322.     SetPanelTitle(ViewQueueMenu, info);
  323.     DrawPanelText(ViewQueueMenu, "-----------------------------------");
  324.     DrawPanelText(ViewQueueMenu, "                                   ");
  325.    
  326.     for (int i; i < GetArraySize(g_aGuardQueue); i++)
  327.     {
  328.         if (!IsValidClient(GetArrayCell(g_aGuardQueue, i), true, true))
  329.             continue;
  330.        
  331.         char display[120];
  332.         Format(display, sizeof(display), "%N", GetArrayCell(g_aGuardQueue, i));
  333.         DrawPanelText(ViewQueueMenu, display);
  334.     }
  335.    
  336.     DrawPanelText(ViewQueueMenu, "                                   ");
  337.     DrawPanelText(ViewQueueMenu, "-----------------------------------");
  338.     Format(info, sizeof(info), "%T", "ratio_close", client);
  339.     DrawPanelItem(ViewQueueMenu, info);
  340.     SendPanelToClient(ViewQueueMenu, client, Handler_NullCancel, 12);
  341.    
  342.     return Plugin_Handled;
  343. }
  344.  
  345.  
  346. public Action Command_JoinGuardQueue(int client, int iArgNum)
  347. {
  348.     if (!IsValidClient(client, true, true))
  349.     {
  350.         return Plugin_Handled;
  351.     }
  352.    
  353.     if (!g_bRatioEnable)
  354.     {
  355.         CReplyToCommand(client, "%t %t", "ratio_tag", "ratio_disabled");
  356.         return Plugin_Handled;
  357.     }
  358.    
  359.     if (GetClientTeam(client) != CS_TEAM_T)
  360.     {
  361.         ClientCommand(client, "play %s", g_sRestrictedSound);
  362.         CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_noct");
  363.         return Plugin_Handled;
  364.     }
  365.    
  366.     if (g_bQueueCooldown[client])
  367.     {
  368.         CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_cooldown");
  369.         return Plugin_Handled;
  370.     }
  371.    
  372.    
  373.     Action res = Plugin_Continue;
  374.     Call_StartForward(g_hOnClientJoinGuards);
  375.     Call_PushCell(client);
  376.     Call_Finish(res);
  377.    
  378.     if (res >= Plugin_Handled)
  379.     {
  380.         ClientCommand(client, "play %s", g_sRestrictedSound);
  381.         return Plugin_Handled;
  382.     }
  383.    
  384.     if (!CanClientJoinGuards(client))
  385.     {
  386.         int iIndex = FindValueInArray(g_aGuardQueue, client);
  387.        
  388.         if (iIndex == -1)
  389.         {
  390.             if ((gc_iJoinMode.IntValue == 0) || (gc_bAdminBypass.BoolValue && CheckVipFlag(client, g_sAdminFlag))) AddToQueue(client);
  391.             if ((gc_iJoinMode.IntValue == 1) && ((gc_bAdminBypass.BoolValue && !CheckVipFlag(client, g_sAdminFlag)) || (!gc_bAdminBypass.BoolValue))) Menu_AcceptGuardRules(client);
  392.             if ((gc_iJoinMode.IntValue == 2) && ((gc_bAdminBypass.BoolValue && !CheckVipFlag(client, g_sAdminFlag)) || (!gc_bAdminBypass.BoolValue))) Menu_GuardQuestions(client);
  393.             g_iQuestionTimes[client] = gc_iQuestionTimes.IntValue-1;
  394.         }
  395.         else
  396.         {
  397.             CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_number", iIndex + 1);
  398.             if (gc_bAdsVIP.BoolValue && gc_bVIPQueue.BoolValue && !CheckVipFlag(client, g_sAdminFlag)) CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_advip");
  399.         }
  400.         return Plugin_Handled;
  401.     }
  402.     if ((gc_iJoinMode.IntValue == 0) || (gc_bAdminBypass.BoolValue && CheckVipFlag(client, g_sAdminFlag)))
  403.     {
  404.         if(gc_bRespawn.BoolValue)
  405.         {
  406.             ForcePlayerSuicide(client);
  407.             ChangeClientTeam(client, CS_TEAM_CT);
  408.             SetClientListeningFlags(client, VOICE_NORMAL); //unmute if sm_hosties or admin has muted prisoners on round start
  409.             MinusDeath(client);
  410.         }
  411.         else
  412.         {
  413.             int iIndex = FindValueInArray(g_aGuardQueue, client);
  414.             int iQueueSize = GetArraySize(g_aGuardQueue);
  415.            
  416.             if (iIndex == -1)
  417.             {
  418.                 if (CheckVipFlag(client, g_sAdminFlag) && gc_bVIPQueue.BoolValue)
  419.                 {
  420.                     if (iQueueSize == 0)
  421.                         iIndex = PushArrayCell(g_aGuardQueue, client);
  422.                     else
  423.                     {
  424.                         ShiftArrayUp(g_aGuardQueue, 0);
  425.                         SetArrayCell(g_aGuardQueue, 0, client);
  426.                     }
  427.                     CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_thxvip");
  428.                     CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_number", iIndex + 1);
  429.                 }
  430.                 else
  431.                 {
  432.                     iIndex = PushArrayCell(g_aGuardQueue, client);
  433.                    
  434.                     CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_number", iIndex + 1);
  435.                     if (gc_bAdsVIP.BoolValue && gc_bVIPQueue.BoolValue) CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_advip");
  436.                 }
  437.             }
  438.             else
  439.             {
  440.                 CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_number", iIndex + 1);
  441.                 if (gc_bAdsVIP.BoolValue && gc_bVIPQueue.BoolValue && !CheckVipFlag(client, g_sAdminFlag)) CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_advip");
  442.             }
  443.         }
  444.     }
  445.    
  446.     if ((gc_iJoinMode.IntValue == 1) && ((gc_bAdminBypass.BoolValue && !CheckVipFlag(client, g_sAdminFlag)) || (!gc_bAdminBypass.BoolValue))) Menu_AcceptGuardRules(client);
  447.     if ((gc_iJoinMode.IntValue == 2) && ((gc_bAdminBypass.BoolValue && !CheckVipFlag(client, g_sAdminFlag)) || (!gc_bAdminBypass.BoolValue))) Menu_GuardQuestions(client);
  448.     g_iQuestionTimes[client] = gc_iQuestionTimes.IntValue-1;
  449.    
  450.     return Plugin_Handled;
  451. }
  452.  
  453.  
  454. public Action AdminCommand_RemoveFromQueue(int client, int args)
  455. {
  456.     if (!IsValidClient(client, true, true))
  457.         return Plugin_Handled;
  458.    
  459.     if (!g_bRatioEnable)
  460.     {
  461.         CReplyToCommand(client, "%t %t", "ratio_tag", "ratio_disabled");
  462.         return Plugin_Handled;
  463.     }
  464.    
  465.     if (GetArraySize(g_aGuardQueue) < 1)
  466.     {
  467.         CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_empty");
  468.         return Plugin_Handled;
  469.     }
  470.    
  471.     Menu hMenu = CreateMenu(ViewQueueMenuHandle);
  472.    
  473.     char menuinfo[64];
  474.     Format(menuinfo, sizeof(menuinfo), "t", "ratio_remove", client);
  475.     SetMenuTitle(hMenu, menuinfo);
  476.    
  477.     for (int i; i < GetArraySize(g_aGuardQueue); i++)
  478.     {
  479.         if (!IsValidClient(GetArrayCell(g_aGuardQueue, i), true, true))
  480.             continue;
  481.        
  482.         char userid[11];
  483.         char username[MAX_NAME_LENGTH];
  484.         IntToString(GetClientUserId(i+1), userid, sizeof(userid));
  485.         Format(username, sizeof(username), "%N", GetArrayCell(g_aGuardQueue, i));
  486.         hMenu.AddItem(userid, username);
  487.     }
  488.     hMenu.ExitBackButton = true;
  489.     hMenu.ExitButton = true;
  490.     DisplayMenu(hMenu, client, 15);
  491.    
  492.     return Plugin_Handled;
  493. }
  494.  
  495.  
  496. public Action AdminCommand_ClearQueue(int client, int args)
  497. {
  498.     ClearArray(g_aGuardQueue);
  499.     CPrintToChatAll("%t %t", "ratio_tag", "ratio_clearqueue");
  500. }
  501.  
  502.  
  503. public Action Command_ToggleRatio(int client, int args)
  504. {
  505.     if (CheckVipFlag(client, g_sAdminFlag) && gc_bToggle.BoolValue)
  506.     {
  507.         if (g_bRatioEnable)
  508.         {
  509.             g_bRatioEnable = false;
  510.             CPrintToChatAll("%t %t", "ratio_tag", "ratio_hasdisabled");
  511.         }
  512.         else
  513.         {
  514.             g_bRatioEnable = true;
  515.             CPrintToChatAll("%t %t", "ratio_tag", "ratio_hasactivated");
  516.         }
  517.     }
  518.     else
  519.     {
  520.         if (g_bRatioEnable)
  521.         {
  522.             CReplyToCommand(client, "%t %t", "ratio_tag", "ratio_active", gc_fPrisonerPerGuard.FloatValue);
  523.         }
  524.         else
  525.         {
  526.             CReplyToCommand(client, "%t %t", "ratio_tag", "ratio_disabled");
  527.         }
  528.     }
  529.     return Plugin_Handled;
  530. }
  531.  
  532.  
  533. /******************************************************************************
  534.                    EVENTS
  535. ******************************************************************************/
  536.  
  537.  
  538. public void Event_PlayerTeam_Post(Event event, const char[] szName, bool bDontBroadcast)
  539. {
  540.     int client = GetClientOfUserId(event.GetInt("userid"));
  541.    
  542.     if (event.GetInt("team") == CS_TEAM_CT)
  543.     {
  544.         int iIndex = FindValueInArray(g_aGuardList, client);
  545.        
  546.         if (iIndex == -1)
  547.         {
  548.             iIndex = PushArrayCell(g_aGuardList, client);
  549.         }
  550.         RemovePlayerFromGuardQueue(client);
  551.        
  552.     }
  553.     else RemovePlayerFromGuardList(client);
  554.     return;
  555. }
  556.  
  557.  
  558. public Action Event_RoundEnd_Post(Event event, const char[] szName, bool bDontBroadcast)
  559. {
  560.     if (g_bRatioEnable) FixTeamRatio();
  561.     else if (gc_bToggleAnnounce.BoolValue) CPrintToChatAll("%t %t", "ratio_tag", "ratio_disabled");
  562.     LoopClients(i) g_bQueueCooldown[i] = false;
  563. }
  564.  
  565.  
  566. public Action Event_OnFullConnect(Event event, const char[] name, bool dontBroadcast)
  567. {
  568.     int client = GetClientOfUserId(event.GetInt("userid"));
  569.     if (gc_bForceTConnect.BoolValue && g_bRatioEnable && ((gc_bAdminBypass.BoolValue && !CheckVipFlag(client, g_sAdminFlag)) || !gc_bAdminBypass.BoolValue)) CreateTimer(1.0, Timer_ForceTSide, client);
  570.     return Plugin_Continue;
  571. }
  572.  
  573.  
  574. public Action Event_OnJoinTeam(int client, const char[] szCommand, int iArgCount)
  575. {
  576.     if (iArgCount < 1)
  577.         return Plugin_Continue;
  578.    
  579.     if (!g_bRatioEnable)
  580.     {
  581.         CPrintToChat(client, "%t %t", "ratio_tag", "ratio_disabled");
  582.         return Plugin_Continue;
  583.     }
  584.    
  585.     char szData[2];
  586.     GetCmdArg(1, szData, sizeof(szData));
  587.     int iTeam = StringToInt(szData);
  588.    
  589.     if (!iTeam)
  590.     {
  591.         ClientCommand(client, "play %s", g_sRestrictedSound);
  592.         CPrintToChat(client, "%t %t", "ratio_tag" , "ratio_auto");
  593.         return Plugin_Handled;
  594.     }
  595.    
  596.     if (iTeam != CS_TEAM_CT)
  597.         return Plugin_Continue;
  598.    
  599.     if (g_bQueueCooldown[client])
  600.     {
  601.         CReplyToCommand(client, "%t %t", "ratio_tag" , "ratio_cooldown");
  602.         return Plugin_Handled;
  603.     }
  604.    
  605.    
  606.     Action res = Plugin_Continue;
  607.     Call_StartForward(g_hOnClientJoinGuards);
  608.     Call_PushCell(client);
  609.     Call_Finish(res);
  610.    
  611.     if (res >= Plugin_Handled)
  612.     {
  613.         ClientCommand(client, "play %s", g_sRestrictedSound);
  614.         return Plugin_Handled;
  615.     }
  616.    
  617.    
  618.     if (!CanClientJoinGuards(client))
  619.     {
  620.         int iIndex = FindValueInArray(g_aGuardQueue, client);
  621.        
  622.         ClientCommand(client, "play %s", g_sRestrictedSound);
  623.        
  624.         if (iIndex == -1)
  625.         {
  626.             if ((gc_iJoinMode.IntValue == 0) || (gc_bAdminBypass.BoolValue && CheckVipFlag(client, g_sAdminFlag))) FullAddToQueue(client);
  627.             if ((gc_iJoinMode.IntValue == 1) && ((gc_bAdminBypass.BoolValue && !CheckVipFlag(client, g_sAdminFlag)) || (!gc_bAdminBypass.BoolValue))) Menu_AcceptGuardRules(client);
  628.             if ((gc_iJoinMode.IntValue == 2) && ((gc_bAdminBypass.BoolValue && !CheckVipFlag(client, g_sAdminFlag)) || (!gc_bAdminBypass.BoolValue))) Menu_GuardQuestions(client);
  629.             g_iQuestionTimes[client] = gc_iQuestionTimes.IntValue-1;
  630.         }
  631.         else
  632.         {
  633.             CPrintToChat(client, "%t %t", "ratio_tag" , "ratio_fullqueue", iIndex + 1);
  634.             if (gc_bAdsVIP.BoolValue && gc_bVIPQueue.BoolValue && !CheckVipFlag(client, g_sAdminFlag)) CPrintToChat(client, "%t %t", "ratio_tag" , "ratio_advip");
  635.         }
  636.         return Plugin_Handled;
  637.     }
  638.    
  639.     if ((gc_iJoinMode.IntValue == 0) || (gc_bAdminBypass.BoolValue && CheckVipFlag(client, g_sAdminFlag))) return Plugin_Continue;
  640.     if ((gc_iJoinMode.IntValue == 1) && ((gc_bAdminBypass.BoolValue && !CheckVipFlag(client, g_sAdminFlag)) || (!gc_bAdminBypass.BoolValue))) Menu_AcceptGuardRules(client);
  641.     if ((gc_iJoinMode.IntValue == 2) && ((gc_bAdminBypass.BoolValue && !CheckVipFlag(client, g_sAdminFlag)) || (!gc_bAdminBypass.BoolValue))) Menu_GuardQuestions(client);
  642.     g_iQuestionTimes[client] = gc_iQuestionTimes.IntValue-1;
  643.     return Plugin_Handled;
  644. }
  645.  
  646.  
  647. /******************************************************************************
  648.                    FUNCTIONS
  649. ******************************************************************************/
  650.  
  651.  
  652. void MinusDeath(int client)
  653. {
  654.     if (IsValidClient(client, true, true))
  655.     {
  656.         int frags = GetEntProp(client, Prop_Data, "m_iFrags");
  657.         int deaths = GetEntProp(client, Prop_Data, "m_iDeaths");
  658.         SetEntProp(client, Prop_Data, "m_iFrags", (frags+1));
  659.         SetEntProp(client, Prop_Data, "m_iDeaths", (deaths-1));
  660.     }
  661. }
  662.  
  663.  
  664. public void AddToQueue(int client)
  665. {
  666.     int iIndex = FindValueInArray(g_aGuardQueue, client);
  667.     int iQueueSize = GetArraySize(g_aGuardQueue);
  668.    
  669.     if (iIndex == -1)
  670.     {
  671.         if (CheckVipFlag(client, g_sAdminFlag) && gc_bVIPQueue.BoolValue)
  672.         {
  673.             if (iQueueSize == 0)
  674.                 iIndex = PushArrayCell(g_aGuardQueue, client);
  675.             else
  676.             {
  677.                 ShiftArrayUp(g_aGuardQueue, 0);
  678.                 SetArrayCell(g_aGuardQueue, 0, client);
  679.             }
  680.             CPrintToChat(client, "%t %t", "ratio_tag" , "ratio_thxvip");
  681.             CPrintToChat(client, "%t %t", "ratio_tag" , "ratio_number", iIndex + 1);
  682.         }
  683.         else
  684.         {
  685.             iIndex = PushArrayCell(g_aGuardQueue, client);
  686.            
  687.             CPrintToChat(client, "%t %t", "ratio_tag" , "ratio_number", iIndex + 1);
  688.             if (gc_bAdsVIP.BoolValue && gc_bVIPQueue.BoolValue) CPrintToChat(client, "%t %t", "ratio_tag" , "ratio_advip");
  689.         }
  690.     }
  691. }
  692.  
  693.  
  694. public void FullAddToQueue(int client)
  695. {
  696.     int iIndex = FindValueInArray(g_aGuardQueue, client);
  697.     int iQueueSize = GetArraySize(g_aGuardQueue);
  698.    
  699.     if (iIndex == -1)
  700.     {
  701.         if (CheckVipFlag(client, g_sAdminFlag) && gc_bVIPQueue.BoolValue)
  702.         {
  703.             if (iQueueSize == 0)
  704.                 iIndex = PushArrayCell(g_aGuardQueue, client);
  705.             else
  706.             {
  707.                 ShiftArrayUp(g_aGuardQueue, 0);
  708.                 SetArrayCell(g_aGuardQueue, 0, client);
  709.             }
  710.             CPrintToChat(client, "%t %t", "ratio_tag" , "ratio_thxvip");
  711.             CPrintToChat(client, "%t %t", "ratio_tag" , "ratio_number", iIndex + 1);
  712.         }
  713.         else
  714.         {
  715.             iIndex = PushArrayCell(g_aGuardQueue, client);
  716.            
  717.             CPrintToChat(client, "%t %t", "ratio_tag" , "ratio_number", iIndex + 1);
  718.             if (gc_bAdsVIP.BoolValue && gc_bVIPQueue.BoolValue) CPrintToChat(client, "%t %t", "ratio_tag" , "ratio_advip");
  719.         }
  720.     }
  721. }
  722.  
  723.  
  724. public void OnForcePickTimeChanged(Handle hConVar, const char[] szOldValue, const char[] szNewValue)
  725. {
  726.     SetConVarInt(hConVar, 999999);
  727. }
  728.  
  729.  
  730. /******************************************************************************
  731.                    FORWARDS LISTEN
  732. ******************************************************************************/
  733.  
  734.  
  735. public void OnClientDisconnect_Post(int client)
  736. {
  737.     RemovePlayerFromGuardQueue(client);
  738.     RemovePlayerFromGuardList(client);
  739. }
  740.  
  741.  
  742. public void OnMapStart()
  743. {
  744.     g_bRatioEnable = true;
  745. }
  746.  
  747.  
  748. /******************************************************************************
  749.                    MENUS
  750. ******************************************************************************/
  751.  
  752.  
  753. public Action Menu_AcceptGuardRules(int client)
  754. {
  755.     char info[64];
  756.    
  757.     Handle AcceptMenu = CreatePanel();
  758.    
  759.     Format(info, sizeof(info), "%T", "ratio_accept_title", client);
  760.     SetPanelTitle(AcceptMenu, info);
  761.     DrawPanelText(AcceptMenu, "-----------------------------------");
  762.     Format(info, sizeof(info), "%T", "ratio_accept_line1", client);
  763.     DrawPanelText(AcceptMenu, info);
  764.     DrawPanelText(AcceptMenu, "    ");
  765.     Format(info, sizeof(info), "%T", "ratio_accept_line2", client);
  766.     DrawPanelText(AcceptMenu, info);
  767.     Format(info, sizeof(info), "%T", "ratio_accept_line3", client);
  768.     DrawPanelText(AcceptMenu, info);
  769.     Format(info, sizeof(info), "%T", "ratio_accept_line4", client);
  770.     DrawPanelText(AcceptMenu, info);
  771.     Format(info, sizeof(info), "%T", "ratio_accept_line5", client);
  772.     DrawPanelText(AcceptMenu, info);
  773.     DrawPanelText(AcceptMenu, "    ");
  774.     DrawPanelText(AcceptMenu, "-----------------------------------");
  775.     DrawPanelText(AcceptMenu, "    ");
  776.     Format(info, sizeof(info), "%T", "ratio_accept", client);
  777.     DrawPanelItem(AcceptMenu, info);
  778.     Format(info, sizeof(info), "%T", "ratio_notaccept", client);
  779.     DrawPanelItem(AcceptMenu, info);
  780.     SendPanelToClient(AcceptMenu, client, Handler_AcceptGuardRules, 20);
  781. }
  782.  
  783.  
  784. public int Handler_AcceptGuardRules(Handle menu, MenuAction action, int param1, int param2)
  785. {
  786.     int client = param1;
  787.     if (action == MenuAction_Select)
  788.     {
  789.         switch(param2)
  790.         {
  791.             case 1:
  792.             {
  793.                 if (CanClientJoinGuards(client))
  794.                 {
  795.                     ForcePlayerSuicide(client);
  796.                     ChangeClientTeam(client, CS_TEAM_CT);
  797.                     if(gc_bRespawn.BoolValue)
  798.                     {
  799.                         SetClientListeningFlags(client, VOICE_NORMAL); //unmute if sm_hosties or admin has muted prisoners on round start
  800.                         MinusDeath(client);
  801.                         CS_RespawnPlayer(client);
  802.                     }
  803.                 }
  804.                 else AddToQueue(client);
  805.                 ClientCommand(client, "play %s", g_sRightAnswerSound);
  806.             }
  807.             case 2:
  808.             {
  809.                 ClientCommand(client, "play %s", g_sRestrictedSound);
  810.                 g_bQueueCooldown[client] = true;
  811.             }
  812.         }
  813.     }
  814. }
  815.  
  816.  
  817. public void Menu_GuardQuestions(int client)
  818. {
  819.     char info[64], random[64];
  820.    
  821.     Handle AcceptMenu = CreatePanel();
  822.     int randomquestion = GetRandomInt(1, 5);
  823.     g_iRandomAnswer[client] = GetRandomInt(1, 3);
  824.    
  825.     Format(info, sizeof(info), "%T", "ratio_question_title", client);
  826.     SetPanelTitle(AcceptMenu, info);
  827.     DrawPanelText(AcceptMenu, "-----------------------------------");
  828.     Format(random, sizeof(random), "ratio_question%i_line1", randomquestion);
  829.     Format(info, sizeof(info), "%T", random, client);
  830.     DrawPanelText(AcceptMenu, info);
  831.     Format(random, sizeof(random), "ratio_question%i_line2", randomquestion);
  832.     Format(info, sizeof(info), "%T", random, client);
  833.     DrawPanelText(AcceptMenu, info);
  834.     DrawPanelText(AcceptMenu, "-----------------------------------");
  835.    
  836.     if (g_iRandomAnswer[client] == 1)
  837.     {
  838.         DrawPanelText(AcceptMenu, "    ");
  839.         Format(random, sizeof(random), "ratio_question%i_right", randomquestion);
  840.         Format(info, sizeof(info), "%T", random, client);
  841.         DrawPanelItem(AcceptMenu, info);
  842.     }
  843.    
  844.     DrawPanelText(AcceptMenu, "    ");
  845.     Format(random, sizeof(random), "ratio_question%i_wrong1", randomquestion);
  846.     Format(info, sizeof(info), "%T", random, client);
  847.     DrawPanelItem(AcceptMenu, info);
  848.    
  849.     if (g_iRandomAnswer[client] == 2)
  850.     {
  851.         DrawPanelText(AcceptMenu, "    ");
  852.         Format(random, sizeof(random), "ratio_question%i_right", randomquestion);
  853.         Format(info, sizeof(info), "%T", random, client);
  854.         DrawPanelItem(AcceptMenu, info);
  855.     }
  856.    
  857.     DrawPanelText(AcceptMenu, "    ");
  858.     Format(random, sizeof(random), "ratio_question%i_wrong2", randomquestion);
  859.     Format(info, sizeof(info), "%T", random, client);
  860.     DrawPanelItem(AcceptMenu, info);
  861.    
  862.     if (g_iRandomAnswer[client] == 3)
  863.     {
  864.         DrawPanelText(AcceptMenu, "    ");
  865.         Format(random, sizeof(random), "ratio_question%i_right", randomquestion);
  866.         Format(info, sizeof(info), "%T", random, client);
  867.         DrawPanelItem(AcceptMenu, info);
  868.     }
  869.    
  870.     SendPanelToClient(AcceptMenu, client, Handler_GuardQuestions, 20);
  871. }
  872.  
  873.  
  874. public int Handler_GuardQuestions(Handle menu, MenuAction action, int param1, int param2)
  875. {
  876.     int client = param1;
  877.     if (action == MenuAction_Select)
  878.     {
  879.         switch(param2)
  880.         {
  881.             case 1:
  882.             {
  883.                 if (g_iRandomAnswer[client] == 1)
  884.                 {
  885.                     if (g_iQuestionTimes[client] <= 0)
  886.                     {
  887.                         if (CanClientJoinGuards(client))
  888.                         {
  889.                             ForcePlayerSuicide(client);
  890.                             ChangeClientTeam(client, CS_TEAM_CT);
  891.                             SetClientListeningFlags(client, VOICE_NORMAL); //unmute if sm_hosties or admin has muted prisoners on round start
  892.                             if(gc_bRespawn.BoolValue)
  893.                             {
  894.                                 MinusDeath(client);
  895.                                 CS_RespawnPlayer(client);
  896.                             }
  897.                         }
  898.                         else AddToQueue(client);
  899.                     }
  900.                     else Menu_GuardQuestions(client);
  901.                     ClientCommand(client, "play %s", g_sRightAnswerSound);
  902.                     g_iQuestionTimes[client]--;
  903.                 }
  904.                 else
  905.                 {
  906.                     ClientCommand(client, "play %s", g_sRestrictedSound);
  907.                     g_bQueueCooldown[client] = true;
  908.                 }
  909.             }
  910.             case 2:
  911.             {
  912.                 if (g_iRandomAnswer[client] == 2)
  913.                 {
  914.                     if (g_iQuestionTimes[client] <= 0)
  915.                     {
  916.                         if (CanClientJoinGuards(client))
  917.                         {
  918.                             ForcePlayerSuicide(client);
  919.                             ChangeClientTeam(client, CS_TEAM_CT);
  920.                             SetClientListeningFlags(client, VOICE_NORMAL); //unmute if sm_hosties or admin has muted prisoners on round start
  921.                             if(gc_bRespawn.BoolValue)
  922.                             {
  923.                                 MinusDeath(client);
  924.                                 CS_RespawnPlayer(client);
  925.                             }
  926.                         }
  927.                         else AddToQueue(client);
  928.                     }
  929.                     else Menu_GuardQuestions(client);
  930.                     ClientCommand(client, "play %s", g_sRightAnswerSound);
  931.                     g_iQuestionTimes[client]--;
  932.                 }
  933.                 else
  934.                 {
  935.                     ClientCommand(client, "play %s", g_sRestrictedSound);
  936.                     g_bQueueCooldown[client] = true;
  937.                 }
  938.             }
  939.             case 3:
  940.             {
  941.                 if (g_iRandomAnswer[client] == 3)
  942.                 {
  943.                     if (g_iQuestionTimes[client] <= 0)
  944.                     {
  945.                         if (CanClientJoinGuards(client))
  946.                         {
  947.                             ForcePlayerSuicide(client);
  948.                             ChangeClientTeam(client, CS_TEAM_CT);
  949.                             SetClientListeningFlags(client, VOICE_NORMAL); //unmute if sm_hosties or admin has muted prisoners on round start
  950.                             if(gc_bRespawn.BoolValue)
  951.                             {
  952.                                 MinusDeath(client);
  953.                                 CS_RespawnPlayer(client);
  954.                             }
  955.                         }
  956.                         else AddToQueue(client);
  957.                     }
  958.                     else Menu_GuardQuestions(client);
  959.                     ClientCommand(client, "play %s", g_sRightAnswerSound);
  960.                     g_iQuestionTimes[client]--;
  961.                 }
  962.                 else
  963.                 {
  964.                     ClientCommand(client, "play %s", g_sRestrictedSound);
  965.                     g_bQueueCooldown[client] = true;
  966.                 }
  967.             }
  968.         }
  969.     }
  970. }
  971.  
  972.  
  973. public int ViewQueueMenuHandle(Menu hMenu, MenuAction action, int client, int option)
  974. {
  975.     if (action == MenuAction_Select)
  976.     {
  977.         char info[32];
  978.         hMenu.GetItem(option, info, sizeof(info));
  979.         int user = GetClientOfUserId(StringToInt(info));
  980.        
  981.         RemovePlayerFromGuardQueue(user);
  982.        
  983.         CPrintToChatAll("%t %t", "ratio_tag", "ratio_removed", client, user);
  984.        
  985.     }
  986.     else if (action == MenuAction_Cancel)
  987.     {
  988.         if (option == MenuCancel_ExitBack)
  989.         {
  990.             FakeClientCommand(client, "sm_menu");
  991.         }
  992.     }
  993.     else if (action == MenuAction_End)
  994.     {
  995.         delete hMenu;
  996.     }
  997. }
  998.  
  999.  
  1000. /******************************************************************************
  1001.                    TIMER
  1002. ******************************************************************************/
  1003.  
  1004.  
  1005. public Action Timer_ForceTSide(Handle timer, any client)
  1006. {
  1007.     if (IsValidClient(client, true, true)) ChangeClientTeam(client, CS_TEAM_T);
  1008. }
  1009.  
  1010.  
  1011. /******************************************************************************
  1012.                    STOCKS
  1013. ******************************************************************************/
  1014.  
  1015.  
  1016. stock bool RemovePlayerFromGuardQueue(int client)
  1017. {
  1018.     int iIndex = FindValueInArray(g_aGuardQueue, client);
  1019.     if (iIndex == -1)
  1020.         return;
  1021.    
  1022.     RemoveFromArray(g_aGuardQueue, iIndex);
  1023. }
  1024.  
  1025.  
  1026. stock bool RemovePlayerFromGuardList(int client)
  1027. {
  1028.     int iIndex = FindValueInArray(g_aGuardList, client);
  1029.     if (iIndex == -1)
  1030.         return;
  1031.    
  1032.     RemoveFromArray(g_aGuardList, iIndex);
  1033. }
  1034.  
  1035.  
  1036. bool ShouldMoveGuardToPrisoner()
  1037. {
  1038.     int iNumGuards, iNumPrisoners;
  1039.    
  1040.     LoopValidClients(i, true, true)
  1041.     {  
  1042.         if (GetClientPendingTeam(i) == CS_TEAM_T)
  1043.             iNumPrisoners++;
  1044.         else if (GetClientPendingTeam(i) == CS_TEAM_CT)
  1045.              iNumGuards++;
  1046.     }
  1047.    
  1048.     if (iNumGuards <= 1)
  1049.         return false;
  1050.    
  1051.     if (iNumGuards <= RoundToFloor(float(iNumPrisoners) / gc_fPrisonerPerGuard.FloatValue))
  1052.         return false;
  1053.    
  1054.     return true;
  1055. }
  1056.  
  1057.  
  1058. bool ShouldMovePrisonerToGuard()
  1059. {
  1060.     int iNumGuards, iNumPrisoners;
  1061.    
  1062.     LoopValidClients(i, true, true)
  1063.     {  
  1064.         if (GetClientPendingTeam(i) == CS_TEAM_T)
  1065.             iNumPrisoners++;
  1066.         else if (GetClientPendingTeam(i) == CS_TEAM_CT)
  1067.              iNumGuards++;
  1068.     }
  1069.    
  1070.     iNumPrisoners--;
  1071.     iNumGuards++;
  1072.    
  1073.     if (iNumPrisoners < 1)
  1074.         return false;
  1075.    
  1076.     if (float(iNumPrisoners) / float(iNumGuards) < gc_fPrisonerPerGuard.FloatValue)
  1077.         return false;
  1078.    
  1079.     return true;
  1080. }
  1081.  
  1082.  
  1083. stock void FixTeamRatio()
  1084. {
  1085.     bool bMovedPlayers;
  1086.     while (ShouldMovePrisonerToGuard())
  1087.     {
  1088.         int client;
  1089.         if (GetArraySize(g_aGuardQueue))
  1090.         {
  1091.             client = GetArrayCell(g_aGuardQueue, 0);
  1092.             RemovePlayerFromGuardQueue(client);
  1093.            
  1094.             CPrintToChatAll("%t %t", "ratio_tag", "ratio_find", client);
  1095.         }
  1096.         else if (gc_bBalanceTerror.BoolValue)
  1097.         {
  1098.             client = GetRandomClientFromTeam(CS_TEAM_T);
  1099.             CPrintToChatAll("%t %t", "ratio_tag", "ratio_random", client);
  1100.         }
  1101.         else
  1102.         {
  1103.             return;
  1104.         }
  1105.        
  1106.         if (!IsValidClient(client, true, true))
  1107.         {
  1108.             CPrintToChatAll("%t %t", "ratio_tag", "ratio_novalid");
  1109.             break;
  1110.         }
  1111.        
  1112.         SetClientPendingTeam(client, CS_TEAM_CT);
  1113.         SetClientListeningFlags(client, VOICE_NORMAL); //unmute if sm_hosties or admin has muted prisoners on round start
  1114.         MinusDeath(client);
  1115.         bMovedPlayers = true;
  1116.     }
  1117.    
  1118.     if (bMovedPlayers)
  1119.         return;
  1120.    
  1121.     while (ShouldMoveGuardToPrisoner())
  1122.     {
  1123.         int client;
  1124.        
  1125.         if (gc_bBalanceGuards.BoolValue)
  1126.         {
  1127.             int iListSize = GetArraySize(g_aGuardList);
  1128.             int iListNum = iListSize-1;
  1129.            
  1130.             if (GetArraySize(g_aGuardList))
  1131.             {
  1132.                 client = GetArrayCell(g_aGuardList, iListNum);
  1133.                
  1134.                 if (gp_bWarden) if ((warden_iswarden(client) || warden_deputy_isdeputy(client) || (!warden_exist() && (warden_getlast() == client)) || (!warden_deputy_exist() && (warden_deputy_getlast() == client))) && gc_bBalanceWarden.BoolValue)
  1135.                 {
  1136.                     iListNum--;
  1137.                     client = GetArrayCell(g_aGuardList, iListNum);
  1138.                    
  1139.                     if (warden_iswarden(client) || warden_deputy_isdeputy(client) || (!warden_exist() && (warden_getlast() == client)) || (!warden_deputy_exist() && (warden_deputy_getlast() == client)))
  1140.                     {
  1141.                         iListNum--;
  1142.                         if (iListNum != -1) client = GetArrayCell(g_aGuardList, iListNum);
  1143.                     }
  1144.                 }
  1145.             }
  1146.            
  1147.             if (iListNum == -1)
  1148.                 break;
  1149.         }
  1150.         else client = GetRandomClientFromTeam(CS_TEAM_CT);
  1151.        
  1152.         if (!client)
  1153.             break;
  1154.        
  1155.         CPrintToChatAll("%t %t", "ratio_tag", "ratio_movetot" , client);
  1156.         SetClientPendingTeam(client, CS_TEAM_T);
  1157.         MinusDeath(client);
  1158.         RemovePlayerFromGuardList(client);
  1159.     }
  1160. }
  1161.  
  1162.  
  1163. stock int GetRandomClientFromTeam(int iTeam)
  1164. {
  1165.     int iNumFound;
  1166.     int clients[MAXPLAYERS];
  1167.    
  1168.     LoopValidClients(i, true, true)
  1169.     {
  1170.         if (!IsClientInGame(i))
  1171.             continue;
  1172.        
  1173.         if (GetClientPendingTeam(i) != iTeam)
  1174.             continue;
  1175.        
  1176.         if (gp_bWarden) if ((warden_iswarden(i) || warden_deputy_isdeputy(i)) && gc_bBalanceWarden.BoolValue)
  1177.             continue;
  1178.        
  1179.         Action res = Plugin_Continue;
  1180.         Call_StartForward(g_hOnClientJoinGuards);
  1181.         Call_PushCell(i);
  1182.         Call_Finish(res);
  1183.        
  1184.         if (res >= Plugin_Handled)
  1185.             continue;
  1186.        
  1187.         clients[iNumFound++] = i;
  1188.     }
  1189.    
  1190.     if (!iNumFound)
  1191.         return 0;
  1192.    
  1193.     return clients[GetRandomInt(0, iNumFound-1)];
  1194. }
  1195.  
  1196.  
  1197. stock bool CanClientJoinGuards(int client)
  1198. {
  1199.     int iNumGuards, iNumPrisoners;
  1200.    
  1201.     LoopValidClients(i, true, true)
  1202.     {  
  1203.         if (GetClientPendingTeam(i) == CS_TEAM_T)
  1204.             iNumPrisoners++;
  1205.         else if (GetClientPendingTeam(i) == CS_TEAM_CT)
  1206.              iNumGuards++;
  1207.     }
  1208.    
  1209.     iNumGuards++;
  1210.     if (GetClientPendingTeam(client) == CS_TEAM_T)
  1211.         iNumPrisoners--;
  1212.    
  1213.     if (iNumGuards <= 1)
  1214.         return true;
  1215.    
  1216.     float fNumPrisonersPerGuard = float(iNumPrisoners) / float(iNumGuards);
  1217.     if (fNumPrisonersPerGuard < gc_fPrisonerPerGuard.FloatValue)
  1218.         return false;
  1219.    
  1220.     int iGuardsNeeded = RoundToCeil(fNumPrisonersPerGuard - gc_fPrisonerPerGuard.FloatValue);
  1221.     if (iGuardsNeeded < 1)
  1222.         iGuardsNeeded = 1;
  1223.    
  1224.     int iQueueSize = GetArraySize(g_aGuardQueue);
  1225.     if (iGuardsNeeded > iQueueSize)
  1226.         return true;
  1227.    
  1228.     for (int i; i < iGuardsNeeded; i++)
  1229.     {
  1230.         if (!IsValidClient(i, true, true))
  1231.             continue;
  1232.        
  1233.         if (client == GetArrayCell(g_aGuardQueue, i))
  1234.             return true;
  1235.     }
  1236.    
  1237.     return false;
  1238. }
  1239.  
  1240.  
  1241. stock int GetClientPendingTeam(int client)
  1242. {
  1243.     return GetEntProp(client, Prop_Send, "m_iPendingTeamNum");
  1244. }
  1245.  
  1246.  
  1247. stock void SetClientPendingTeam(int client, int team)
  1248. {
  1249.     SetEntProp(client, Prop_Send, "m_iPendingTeamNum", team);
  1250.     // MinusDeath(client);
  1251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement