Advertisement
Guest User

blah

a guest
Mar 24th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.25 KB | None | 0 0
  1. /* Plugin generated by AMXX-Studio */
  2.  
  3. #include <amxmodx>
  4. #include <fakemeta>
  5.  
  6. #define PLUGIN "::Fair-Match:."
  7. #define VERSION "1.0"
  8. #define AUTHOR "Natsheh"
  9.  
  10. #define MAX_TEAMS         4
  11. #define MAX_PLAYERS     32
  12. #define OFFSET_TEAM     114
  13. #define PLAYER_LINUXDIFF    5
  14. #define VGUI_JOIN_TEAM_NUM  2
  15.  
  16. // teams variables...
  17. new bool:team_avaialble[MAX_TEAMS];
  18.  
  19. enum
  20. {
  21.     TEAM_UNASSIGNED = 0,
  22.     TEAM_TERRORIST,
  23.     TEAM_CT,
  24.     TEAM_SPECTATOR,
  25.     TEAM_AUTO_ASSIGN
  26. }
  27.  
  28. // variables..
  29. new g_iMaxplayers, g_iMsgTeamInfo;
  30. new g_rounds, g_ctwin, g_terwin;
  31.  
  32. // cvars variables
  33. new g_cvar_enable, g_cvar_ratio, g_match_rounds;
  34.  
  35. #define NEWMENUID   get_user_msgid("VGUIMenu")
  36. #define OLDMENUID   get_user_msgid("ShowMenu")
  37.  
  38. public plugin_init()
  39. {
  40.     register_plugin(PLUGIN, VERSION, AUTHOR)
  41.    
  42.     g_cvar_enable = register_cvar("fmatch_enable", "1", ADMIN_BAN)
  43.     g_cvar_ratio = register_cvar("fmatch_ratio", "5", ADMIN_BAN)
  44.     g_match_rounds = register_cvar("fmatch_match_rounds", "15", ADMIN_BAN)
  45.    
  46.     //register_logevent("freezetime_end", 2, "1=Round_Start"); // after freezetime
  47.     register_event("HLTV", "round_start", "a", "1=0", "2=0") // before freezetime
  48.    
  49.     register_message(NEWMENUID, "MessageVGUIMenu")
  50.     register_message(OLDMENUID, "MessageShowMenu")
  51.     register_menucmd(register_menuid("Team_Select", true), (MENU_KEY_1|MENU_KEY_2|MENU_KEY_6|MENU_KEY_0), "old_jointeam_menu")
  52.    
  53.     register_clcmd("jointeam", "clcmd_join")
  54.     register_clcmd("chooseteam", "clcmd_join")
  55.    
  56.     register_event("TeamInfo", "event_TeamInfo", "a")
  57.    
  58.     register_event("SendAudio", "event_terwin", "a", "2&%!MRAD_terwin");
  59.     register_event("SendAudio", "event_ctwin", "a", "2&%!MRAD_ctwin");
  60.     register_logevent("round_end", 2, "0=World triggered", "1=Round_End")
  61.     register_logevent("match_started", 2, "0=World triggered", "1&Restart_Round")
  62.     register_logevent("match_started", 2, "0=World triggered", "1=Game_Commencing")
  63.     register_event("TextMsg","match_started","a","2&#Game_C","2&#Game_w")
  64.    
  65.     g_iMaxplayers = get_maxplayers();
  66.     g_iMsgTeamInfo = get_user_msgid("TeamInfo");
  67.    
  68.     for(new iTeam = 0; iTeam < MAX_TEAMS; iTeam++)
  69.     {
  70.         team_avaialble[iTeam] = true;
  71.     }
  72. }
  73.  
  74. public event_terwin()
  75. {
  76.     if(!get_pcvar_num(g_cvar_enable))
  77.         return;
  78.    
  79.     g_terwin++;
  80. }
  81.  
  82. public event_ctwin()
  83. {
  84.     if(!get_pcvar_num(g_cvar_enable))
  85.         return;
  86.    
  87.     g_ctwin++;
  88. }
  89.  
  90. public match_started()
  91. {
  92.     if(!get_pcvar_num(g_cvar_enable))
  93.         return;
  94.    
  95.     g_rounds = 0;
  96.     new g_match_rounds = get_pcvar_num(g_match_rounds);
  97. }
  98.  
  99. public event_TeamInfo()
  100. {
  101.     if(!get_pcvar_num(g_cvar_enable))
  102.         return;
  103.    
  104.     //new id = read_data(1);
  105.     new sTeam[32];
  106.     read_data(2, sTeam, charsmax(sTeam));
  107.    
  108.     if(equal(sTeam, "SPECTATOR"))
  109.     {
  110.         check_teams()
  111.     }
  112. }
  113.  
  114. public client_disconnect(id)
  115. {
  116.     if(!get_pcvar_num(g_cvar_enable))
  117.         return;
  118.    
  119.     check_teams()
  120. }
  121.  
  122. /*public round_end()
  123. {
  124.  
  125. }*/
  126.  
  127. public round_end()
  128. {
  129.     if(g_rounds >= get_pcvar_num(g_match_rounds))
  130.     {
  131.         client_print( 0, print_chat, "HALF-TIME Swap teams!!" );
  132.         server_cmd( "fmatch_ratio 20" );
  133.         server_cmd( "fmatch_enable 0" );
  134.        
  135.         check_teams();
  136.     }
  137. }
  138.  
  139. public round_start()
  140. {
  141.     if(!get_pcvar_num(g_cvar_enable))
  142.         return;
  143.    
  144.     new ratio = clamp(get_pcvar_num(g_cvar_ratio), 1, floatround(Float:(g_iMaxplayers/2.0), floatround_floor))
  145.     new cnum, tnum, players[32];
  146.     get_players(players, cnum, "he", "CT")
  147.     get_players(players, tnum, "he", "TERRORIST")
  148.     if((ratio*2) > (cnum+tnum))
  149.     {
  150.         check_teams();
  151.         return;
  152.     }
  153.     else if(!((ratio == cnum) && (ratio == tnum)))
  154.     {
  155.         server_cmd("sv_restart 3")
  156.     }
  157.    
  158.     check_ratio()
  159.    
  160.     // counting rounds..
  161.     g_rounds++;
  162. }
  163.  
  164. public client_putinserver(id)
  165. {
  166.     if(!get_pcvar_num(g_cvar_enable))
  167.         return;
  168.    
  169.     check_teams();
  170. }
  171.  
  172. public MessageShowMenu(msgid, msgdest, id)
  173. {
  174.     if(!get_pcvar_num(g_cvar_enable))
  175.         return PLUGIN_CONTINUE;
  176.    
  177.     if(!is_user_connected(id))
  178.         return PLUGIN_CONTINUE;
  179.    
  180.     if(get_msg_argtype(4) != ARG_STRING)
  181.         return PLUGIN_CONTINUE;
  182.    
  183.     static StrMessage[24]
  184.     get_msg_arg_string(4, StrMessage, charsmax(StrMessage))
  185.    
  186.     // join team
  187.     if(equal(StrMessage, "#Team_Select", strlen("#Team_Select")) || equal(StrMessage, "#IG_Team_Select", strlen("#IG_Team_Select")))
  188.     {
  189.         set_task(0.1, "oldstyle_newmenu", id)
  190.         return PLUGIN_HANDLED;
  191.     }
  192.    
  193.     return PLUGIN_CONTINUE;
  194. }
  195.  
  196. public oldstyle_newmenu(id)
  197. {
  198.     if(!is_user_connected(id))
  199.         return;
  200.    
  201.     // check teams..
  202.     check_teams();
  203.    
  204.     new sText[256], len, iKeys;
  205.    
  206.     len = formatex(sText, charsmax(sText), "Choose your team...^n^n")
  207.    
  208.     len += formatex(sText[len], charsmax(sText)-len, "\r1. %sTeam Terrorist^n", team_avaialble[TEAM_TERRORIST] ? "\w":"\d")
  209.     iKeys |= team_avaialble[TEAM_TERRORIST] ? MENU_KEY_1:~MENU_KEY_1
  210.     len += formatex(sText[len], charsmax(sText)-len, "\r2. %sTeam Counter-terrorist^n^n^n", team_avaialble[TEAM_CT] ? "\w":"\d")
  211.     iKeys |= team_avaialble[TEAM_CT] ? MENU_KEY_2:~MENU_KEY_2
  212.    
  213.     len += formatex(sText[len], charsmax(sText)-len, "\r6. %sSpectator^n^n^n", is_user_alive(id) ? "\d":"\w")
  214.     iKeys |= is_user_alive(id) ? ~MENU_KEY_6:MENU_KEY_6
  215.    
  216.     len += formatex(sText[len], charsmax(sText)-len, "\r0. \yExit")
  217.     iKeys |= MENU_KEY_0
  218.    
  219.     show_menu(id, iKeys, sText, _, "Team_Select")
  220. }
  221.  
  222. public old_jointeam_menu(id, ikey)
  223. {
  224.     switch(ikey)
  225.     {
  226.         case 0:
  227.         {
  228.             if(team_avaialble[TEAM_TERRORIST])
  229.             {
  230.                 fm_set_user_team(id, TEAM_TERRORIST)
  231.                 check_teams();
  232.             }
  233.             else
  234.             {
  235.                 client_print(id, print_center, "The Terrorist team is not available right now!")
  236.                 return PLUGIN_HANDLED;
  237.             }
  238.         }
  239.         case 1:
  240.         {
  241.             if(team_avaialble[TEAM_CT])
  242.             {
  243.                 fm_set_user_team(id, TEAM_CT)
  244.                 check_teams();
  245.             }
  246.             else
  247.             {
  248.                 client_print(id, print_center, "The Counter terrorist team is not available right now!")
  249.                 return PLUGIN_HANDLED;
  250.             }
  251.         }
  252.         case 5:
  253.         {
  254.             if(team_avaialble[TEAM_SPECTATOR] && !is_user_alive(id))
  255.             {
  256.                 fm_set_user_team(id, TEAM_SPECTATOR)
  257.                 check_teams();
  258.             }
  259.             else
  260.             {
  261.                 return PLUGIN_HANDLED;
  262.             }
  263.         }
  264.         case 9:
  265.         {
  266.             return PLUGIN_CONTINUE;
  267.         }
  268.     }
  269.    
  270.     return PLUGIN_CONTINUE;
  271. }
  272.  
  273. public MessageVGUIMenu(msgid, msgdest, id)
  274. {
  275.     if(!get_pcvar_num(g_cvar_enable) || !is_user_connected(id))
  276.         return PLUGIN_CONTINUE;
  277.    
  278.     if(get_msg_arg_int(1) == VGUI_JOIN_TEAM_NUM) // user joined a team (NewMenu)
  279.     {
  280.         // user joined a team. (NewMenu)
  281.         set_task(0.1, "oldstyle_newmenu", id)
  282.         return PLUGIN_HANDLED;
  283.     }
  284.     return PLUGIN_CONTINUE;
  285. }
  286.  
  287. public task_joinclass(id)
  288. {
  289.     engclient_cmd(id, "joinclass", "5")
  290. }
  291.  
  292. public clcmd_join(id)
  293. {
  294.     if(!get_pcvar_num(g_cvar_enable))
  295.         return PLUGIN_CONTINUE;
  296.    
  297.     new sArg[5]
  298.     read_argv(1, sArg, 4)
  299.     switch( str_to_num(sArg) )
  300.     {
  301.         case 1: if(!team_avaialble[TEAM_TERRORIST]) return PLUGIN_HANDLED;
  302.         case 2: if(!team_avaialble[TEAM_CT]) return PLUGIN_HANDLED;
  303.         case 5: return PLUGIN_HANDLED;
  304.         default : return PLUGIN_CONTINUE;
  305.     }
  306.    
  307.     return PLUGIN_CONTINUE;
  308. }
  309.  
  310. get_players_inteams(Players[MAX_TEAMS][MAX_PLAYERS], &ctnum, &tsnum, &specnum, &unassigned)
  311. {
  312.     get_players(Players[TEAM_CT], ctnum, "eh", "CT")
  313.     get_players(Players[TEAM_TERRORIST], tsnum, "eh", "TERRORIST")
  314.    
  315.     new players[32], pnum, spec, una;
  316.     get_players(players, pnum, "h")
  317.     for(new i = 0; i < pnum; i++)
  318.     {
  319.         switch( fm_get_user_team(players[i]) )
  320.         {
  321.             case TEAM_SPECTATOR: spec++;
  322.             case TEAM_UNASSIGNED: una++;
  323.         }
  324.     }
  325.    
  326.     specnum = spec;
  327.     unassigned = una;
  328. }
  329.  
  330. check_teams()
  331. {
  332.     new ratio = clamp(get_pcvar_num(g_cvar_ratio), 1, floatround(Float:(g_iMaxplayers/2.0), floatround_floor))
  333.    
  334.     // get players into teams..
  335.     new TPlayers[MAX_TEAMS][MAX_PLAYERS], ctsnum, tsnum, unassigned, specsnum;
  336.     get_players_inteams(TPlayers, ctsnum, tsnum, specsnum, unassigned)
  337.    
  338.     // no players..
  339.     if((ratio*2) > (ctsnum+tsnum))
  340.     {
  341.         team_avaialble[TEAM_CT] = true;
  342.         team_avaialble[TEAM_TERRORIST] = true;
  343.         return;
  344.     }
  345.    
  346.     // check teams if they are available..
  347.     team_avaialble[TEAM_CT] = (ctsnum < ratio) ? true:false
  348.     team_avaialble[TEAM_TERRORIST] = (tsnum < ratio) ? true:false
  349. }
  350.  
  351. check_ratio()
  352. {
  353.     new ratio = clamp(get_pcvar_num(g_cvar_ratio), 1, floatround(Float:(g_iMaxplayers/2.0), floatround_floor))
  354.    
  355.     // get players into teams..
  356.     new TPlayers[MAX_TEAMS][MAX_PLAYERS], ctsnum, tsnum, unassigned, specsnum;
  357.     get_players_inteams(TPlayers, ctsnum, tsnum, specsnum, unassigned)
  358.    
  359.     if((ratio*2) > (ctsnum+tsnum))
  360.         return;
  361.    
  362.     // check if teams are available!
  363.     check_teams();
  364.    
  365.     // few variables..
  366.     static sName[32], loop, chosen, player;
  367.    
  368.     if(ratio != ctsnum)
  369.     {
  370.         loop = (ratio - ctsnum);
  371.        
  372.         if(loop > 0)
  373.         {
  374.             while(loop)
  375.             {
  376.                 if(tsnum > ratio)
  377.                 {
  378.                     --tsnum;
  379.                     chosen = random(tsnum)
  380.                     player = TPlayers[TEAM_TERRORIST][chosen]
  381.                     TPlayers[TEAM_TERRORIST][chosen] = TPlayers[TEAM_TERRORIST][tsnum]
  382.                 }  
  383.                 else break;
  384.                
  385.                 TPlayers[TEAM_CT][ctsnum] = player;
  386.                 ++ctsnum;
  387.                 fm_set_user_team(player, TEAM_CT)
  388.                 get_user_name(player, sName, 31)
  389.                 client_print(0, print_chat, "%s has been transfered to counter-terrorist!", sName)
  390.                 loop--;
  391.             }
  392.         }
  393.         else //extra cts
  394.         {
  395.             while(loop < 0)
  396.             {
  397.                 --ctsnum;
  398.                 chosen = random(ctsnum);
  399.                 player = TPlayers[TEAM_CT][chosen];
  400.                 TPlayers[TEAM_CT][chosen] = TPlayers[TEAM_CT][ctsnum];
  401.                 get_user_name(player, sName, 31)
  402.                
  403.                 if(tsnum < ratio) // move them to terorist
  404.                 {
  405.                     TPlayers[TEAM_TERRORIST][tsnum] = player;
  406.                     ++tsnum;
  407.                     fm_set_user_team(player, TEAM_TERRORIST)
  408.                     client_print(0, print_chat, "%s has been transfered to terrorist!", sName)
  409.                 }
  410.                 else // move them to spectators
  411.                 {
  412.                     TPlayers[TEAM_SPECTATOR][specsnum] = player;
  413.                     ++specsnum;
  414.                     client_print(0, print_chat, "%s has been transfered to spectator!", sName)
  415.                     fm_set_user_team(player, TEAM_SPECTATOR)
  416.                 }
  417.                
  418.                 loop++;
  419.             }
  420.         }
  421.     }
  422.    
  423.     if(ratio != tsnum)
  424.     {
  425.         loop = (ratio - tsnum);
  426.        
  427.         if(loop > 0)
  428.         {
  429.             while(loop--)
  430.             {
  431.                 if(ctsnum > ratio)
  432.                 {
  433.                     --ctsnum;
  434.                     chosen = random(ctsnum)
  435.                     player = TPlayers[TEAM_CT][chosen]
  436.                     TPlayers[TEAM_CT][chosen] = TPlayers[TEAM_CT][ctsnum]
  437.                 }  
  438.                 else break;
  439.                
  440.                 TPlayers[TEAM_TERRORIST][tsnum] = player;
  441.                 ++tsnum;
  442.                 fm_set_user_team(player, TEAM_TERRORIST)
  443.                 get_user_name(player, sName, 31)
  444.                 client_print(0, print_chat, "%s has been transfered to terrorist!", sName)
  445.             }
  446.         }
  447.         else //extra ts
  448.         {
  449.             while(loop < 0)
  450.             {
  451.                 --tsnum;
  452.                 chosen = random(tsnum);
  453.                 player = TPlayers[TEAM_TERRORIST][chosen];
  454.                 TPlayers[TEAM_TERRORIST][chosen] = TPlayers[TEAM_TERRORIST][tsnum];
  455.                 get_user_name(player, sName, 31)
  456.                
  457.                 if(ctsnum < ratio) // move them to counter-terorist
  458.                 {
  459.                     TPlayers[TEAM_CT][ctsnum] = player;
  460.                     ++ctsnum;
  461.                     fm_set_user_team(player, TEAM_CT)
  462.                     client_print(0, print_chat, "%s has been transfered to counter-terrorist!", sName)
  463.                 }
  464.                 else // move them to spectators
  465.                 {
  466.                     TPlayers[TEAM_SPECTATOR][specsnum] = player;
  467.                     ++specsnum;
  468.                     client_print(0, print_chat, "%s has been transfered to spectator!", sName)
  469.                     fm_set_user_team(player, TEAM_SPECTATOR)
  470.                 }
  471.                
  472.                 loop++;
  473.             }
  474.         }
  475.     }
  476.    
  477.     if(ctsnum == ratio) team_avaialble[TEAM_CT] = false;
  478.     if(tsnum == ratio) team_avaialble[TEAM_TERRORIST] = false;
  479. }
  480.  
  481. stock fm_get_user_team(index)
  482. {
  483.     new iteam = get_user_team(index);
  484.    
  485.     switch( iteam )
  486.     {
  487.         case 1: return TEAM_TERRORIST;
  488.         case 2: return TEAM_CT;
  489.         case -1, 3: return TEAM_SPECTATOR;
  490.         case 0: return TEAM_UNASSIGNED
  491.     }
  492.    
  493.     return -2;
  494. }
  495.  
  496.  
  497. stock fm_set_user_team(id, team)
  498. {
  499.     switch( team )
  500.     {
  501.         case TEAM_CT: engclient_cmd(id, "jointeam", "2")
  502.         case TEAM_TERRORIST: engclient_cmd(id, "jointeam", "1")
  503.         case TEAM_SPECTATOR: engclient_cmd(id, "jointeam", "6")
  504.         case TEAM_AUTO_ASSIGN:
  505.         {
  506.             new sString[2]
  507.             team = random_num(TEAM_TERRORIST, TEAM_CT)
  508.             num_to_str(team, sString, charsmax(sString))
  509.             engclient_cmd(id, "jointeam", sString)
  510.         }
  511.         default: {
  512.             log_error(AMX_ERR_NOTFOUND, "Team with this id #%d is not found!", team)
  513.             return
  514.         }
  515.     }
  516.    
  517.     // set user team...
  518.     set_pdata_int(id, OFFSET_TEAM, team, PLAYER_LINUXDIFF)
  519.     set_pev(id, pev_team, team)
  520.    
  521.     static const TeamInfo[MAX_TEAMS][] =
  522.     {
  523.         "UNASSIGNED",
  524.         "TERRORIST",
  525.         "CT",
  526.         "SPECTATOR"
  527.     };
  528.    
  529.     message_begin(MSG_ALL, g_iMsgTeamInfo);
  530.     write_byte(id);
  531.     write_string(TeamInfo[team]);
  532.     message_end();
  533.    
  534.     if(is_user_alive(id))
  535.     {
  536.         user_kill(id)
  537.     }
  538. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement