Advertisement
Guest User

blah

a guest
Mar 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.30 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.     static players[32], pnum, spec, una, i;
  316.     get_players(players, pnum, "h")
  317.    
  318.     spec = 0; una = 0;
  319.     for(i = 0; i < pnum; i++)
  320.     {
  321.         switch( fm_get_user_team(players[i]) )
  322.         {
  323.             case TEAM_SPECTATOR: spec++;
  324.             case TEAM_UNASSIGNED: una++;
  325.         }
  326.     }
  327.    
  328.     specnum = spec;
  329.     unassigned = una;
  330. }
  331.  
  332. check_teams()
  333. {
  334.     static ratio;
  335.     ratio = clamp(get_pcvar_num(g_cvar_ratio), 1, floatround(Float:(g_iMaxplayers/2.0), floatround_floor))
  336.    
  337.     // get players into teams..
  338.     static TPlayers[MAX_TEAMS][MAX_PLAYERS], ctsnum, tsnum, unassigned, specsnum;
  339.     get_players_inteams(TPlayers, ctsnum, tsnum, specsnum, unassigned)
  340.    
  341.     // no players..
  342.     if( ( ratio * 2 ) > ( ctsnum + tsnum ) )
  343.     {
  344.         team_avaialble[TEAM_CT] = true;
  345.         team_avaialble[TEAM_TERRORIST] = true;
  346.         return;
  347.     }
  348.    
  349.     // check teams if they are available..
  350.     team_avaialble[TEAM_CT] = (ctsnum < ratio) ? true:false
  351.     team_avaialble[TEAM_TERRORIST] = (tsnum < ratio) ? true:false
  352. }
  353.  
  354. check_ratio()
  355. {
  356.     new ratio = clamp(get_pcvar_num(g_cvar_ratio), 1, floatround(Float:(g_iMaxplayers/2.0), floatround_floor))
  357.    
  358.     // get players into teams..
  359.     new TPlayers[MAX_TEAMS][MAX_PLAYERS], ctsnum, tsnum, unassigned, specsnum;
  360.     get_players_inteams(TPlayers, ctsnum, tsnum, specsnum, unassigned)
  361.    
  362.     if((ratio*2) > (ctsnum+tsnum))
  363.         return;
  364.    
  365.     // check if teams are available!
  366.     check_teams();
  367.    
  368.     // few variables..
  369.     static sName[32], loop, chosen, player;
  370.    
  371.     if(ratio != ctsnum)
  372.     {
  373.         loop = (ratio - ctsnum);
  374.        
  375.         if(loop > 0)
  376.         {
  377.             while(loop)
  378.             {
  379.                 if(tsnum > ratio)
  380.                 {
  381.                     --tsnum;
  382.                     chosen = random(tsnum)
  383.                     player = TPlayers[TEAM_TERRORIST][chosen]
  384.                     TPlayers[TEAM_TERRORIST][chosen] = TPlayers[TEAM_TERRORIST][tsnum]
  385.                 }  
  386.                 else break;
  387.                
  388.                 TPlayers[TEAM_CT][ctsnum] = player;
  389.                 ++ctsnum;
  390.                 fm_set_user_team(player, TEAM_CT)
  391.                 get_user_name(player, sName, 31)
  392.                 client_print(0, print_chat, "%s has been transfered to counter-terrorist!", sName)
  393.                 loop--;
  394.             }
  395.         }
  396.         else //extra cts
  397.         {
  398.             while(loop < 0)
  399.             {
  400.                 --ctsnum;
  401.                 chosen = random(ctsnum);
  402.                 player = TPlayers[TEAM_CT][chosen];
  403.                 TPlayers[TEAM_CT][chosen] = TPlayers[TEAM_CT][ctsnum];
  404.                 get_user_name(player, sName, 31)
  405.                
  406.                 if(tsnum < ratio) // move them to terorist
  407.                 {
  408.                     TPlayers[TEAM_TERRORIST][tsnum] = player;
  409.                     ++tsnum;
  410.                     fm_set_user_team(player, TEAM_TERRORIST)
  411.                     client_print(0, print_chat, "%s has been transfered to terrorist!", sName)
  412.                 }
  413.                 else // move them to spectators
  414.                 {
  415.                     TPlayers[TEAM_SPECTATOR][specsnum] = player;
  416.                     ++specsnum;
  417.                     client_print(0, print_chat, "%s has been transfered to spectator!", sName)
  418.                     fm_set_user_team(player, TEAM_SPECTATOR)
  419.                 }
  420.                
  421.                 loop++;
  422.             }
  423.         }
  424.     }
  425.    
  426.     if(ratio != tsnum)
  427.     {
  428.         loop = (ratio - tsnum);
  429.        
  430.         if(loop > 0)
  431.         {
  432.             while(loop--)
  433.             {
  434.                 if(ctsnum > ratio)
  435.                 {
  436.                     --ctsnum;
  437.                     chosen = random(ctsnum)
  438.                     player = TPlayers[TEAM_CT][chosen]
  439.                     TPlayers[TEAM_CT][chosen] = TPlayers[TEAM_CT][ctsnum]
  440.                 }  
  441.                 else break;
  442.                
  443.                 TPlayers[TEAM_TERRORIST][tsnum] = player;
  444.                 ++tsnum;
  445.                 fm_set_user_team(player, TEAM_TERRORIST)
  446.                 get_user_name(player, sName, 31)
  447.                 client_print(0, print_chat, "%s has been transfered to terrorist!", sName)
  448.             }
  449.         }
  450.         else //extra ts
  451.         {
  452.             while(loop < 0)
  453.             {
  454.                 --tsnum;
  455.                 chosen = random(tsnum);
  456.                 player = TPlayers[TEAM_TERRORIST][chosen];
  457.                 TPlayers[TEAM_TERRORIST][chosen] = TPlayers[TEAM_TERRORIST][tsnum];
  458.                 get_user_name(player, sName, 31)
  459.                
  460.                 if(ctsnum < ratio) // move them to counter-terorist
  461.                 {
  462.                     TPlayers[TEAM_CT][ctsnum] = player;
  463.                     ++ctsnum;
  464.                     fm_set_user_team(player, TEAM_CT)
  465.                     client_print(0, print_chat, "%s has been transfered to counter-terrorist!", sName)
  466.                 }
  467.                 else // move them to spectators
  468.                 {
  469.                     TPlayers[TEAM_SPECTATOR][specsnum] = player;
  470.                     ++specsnum;
  471.                     client_print(0, print_chat, "%s has been transfered to spectator!", sName)
  472.                     fm_set_user_team(player, TEAM_SPECTATOR)
  473.                 }
  474.                
  475.                 loop++;
  476.             }
  477.         }
  478.     }
  479.    
  480.     if(ctsnum == ratio) team_avaialble[TEAM_CT] = false;
  481.     if(tsnum == ratio) team_avaialble[TEAM_TERRORIST] = false;
  482. }
  483.  
  484. stock fm_get_user_team(index)
  485. {
  486.     new iteam = get_user_team(index);
  487.    
  488.     switch( iteam )
  489.     {
  490.         case 1: return TEAM_TERRORIST;
  491.         case 2: return TEAM_CT;
  492.         case -1, 3: return TEAM_SPECTATOR;
  493.         case 0: return TEAM_UNASSIGNED
  494.     }
  495.    
  496.     return -2;
  497. }
  498.  
  499.  
  500. stock fm_set_user_team(id, team)
  501. {
  502.     switch( team )
  503.     {
  504.         case TEAM_CT: engclient_cmd(id, "jointeam", "2")
  505.         case TEAM_TERRORIST: engclient_cmd(id, "jointeam", "1")
  506.         case TEAM_SPECTATOR: engclient_cmd(id, "jointeam", "6")
  507.         case TEAM_AUTO_ASSIGN:
  508.         {
  509.             new sString[2]
  510.             team = random_num(TEAM_TERRORIST, TEAM_CT)
  511.             num_to_str(team, sString, charsmax(sString))
  512.             engclient_cmd(id, "jointeam", sString)
  513.         }
  514.         default: {
  515.             log_error(AMX_ERR_NOTFOUND, "Team with this id #%d is not found!", team)
  516.             return
  517.         }
  518.     }
  519.    
  520.     // set user team...
  521.     set_pdata_int(id, OFFSET_TEAM, team, PLAYER_LINUXDIFF)
  522.     set_pev(id, pev_team, team)
  523.    
  524.     static const TeamInfo[MAX_TEAMS][] =
  525.     {
  526.         "UNASSIGNED",
  527.         "TERRORIST",
  528.         "CT",
  529.         "SPECTATOR"
  530.     };
  531.    
  532.     message_begin(MSG_ALL, g_iMsgTeamInfo);
  533.     write_byte(id);
  534.     write_string(TeamInfo[team]);
  535.     message_end();
  536.    
  537.     if(is_user_alive(id))
  538.     {
  539.         user_kill(id)
  540.     }
  541. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement