Advertisement
Guest User

Untitled

a guest
Aug 29th, 2012
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 46.85 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <cstrike>
  3. #include <sdktools>
  4. #include <sdktools_functions>
  5.  
  6. #if defined MAXPLAYERS
  7. #undef MAXPLAYERS
  8. #define MAXPLAYERS 64
  9. #endif
  10.  
  11. new Handle:hTVEnabled;
  12. new Handle:RestartTimers = INVALID_HANDLE;
  13. new Handle:hMaxPlayers;
  14. #define MAX_PLAYERS_DEFAULT "10"
  15. new OffsetAccount; // MONEY OFFSET
  16. new bool:bPubChatMuted[MAXPLAYERS+1]=false;
  17. new bool:bTeamChatMuted[MAXPLAYERS+1]=false;
  18. new bool:bMuted[MAXPLAYERS+1][MAXPLAYERS+1];
  19. new Float:fLastMessage[MAXPLAYERS+1];
  20. new bool:bAuthed[MAXPLAYERS+1];
  21. new Handle:hBotQuota = INVALID_HANDLE;
  22.  
  23.  
  24. public Plugin:myinfo =
  25. {
  26.     name = "Auto-Mix [PUG]",
  27.     author = "pimpinjuice",
  28.     description = "AutoMix plugin",
  29.     version = "1.0"
  30. }
  31.  
  32. // Current match stuff
  33. enum MatchState
  34. {
  35.     MS_Pre_Setup = 0,
  36.     MS_Setup,
  37.     MS_Before_First_Half, // This is only used if the map changes.
  38.     MS_Live_First_Half,
  39.     MS_Before_Second_Half, // Always used.
  40.     MS_Live_Second_Half,
  41.     MS_Before_Overtime_First_Half,
  42.     MS_Live_Overtime_First_Half,
  43.     MS_Before_Overtime_Second_Half,
  44.     MS_Live_Overtime_Second_Half,
  45.     MS_Post_Match,
  46. };
  47.  
  48. new MatchState:gMatchState = MS_Pre_Setup;
  49. new TeamAScore; // Team A goes CT first.
  50. new TeamBScore; // Team B goes T first.
  51. // Keep in mind team A and B are always randomized / captains.
  52. // In the case of captains, it is still random which captains will be on which team, A or B.
  53. new CurrentRound = 0;
  54. new String:MatchMap[32] = ""; // Map name.
  55. enum RuleType
  56. {
  57.     Rules_PUG = 0,
  58.     Rules_CGS,
  59. };
  60. new RuleType:Ruleset = Rules_PUG;
  61. #define ROUNDS_HALF_PUG 15
  62. #define ROUNDS_HALF_CGS 11
  63. #define ROUNDS_OVERTIME_HALF_PUG 5
  64. #define ROUNDS_OVERTIME_HALF_CGS 1  
  65. #define MAX_ROUNDS 50 // We won't exceed 50 rounds for now.
  66. new Handle:hMatchDamage[MAX_ROUNDS]; // Vector of all the damage.
  67. new Handle:hMatchKills[MAX_ROUNDS]; // Vector of all the kills.
  68. new bool:CaptainMode = false;
  69. new bool:BunnyHopMode = false;
  70. #define MAX_MAPS 50 // For now.
  71. new String:MapNames[MAX_MAPS][32]; // Loaded OnPluginStart()
  72. #define TEAM_A 0
  73. #define TEAM_B 1
  74. #define TEAM_COUNT 2
  75. #define TEAM_CAPTAIN 0
  76. new String:TeamPlayers[TEAM_COUNT][5][24]; // Steam ID's. Cached before map change.
  77. new bool:RoundCounterOn = false;
  78.  
  79. //Clients
  80. new bool:bReady[MAXPLAYERS+1];
  81. new String:clientUsername[MAXPLAYERS+1][24];
  82. new readyUpTime[MAXPLAYERS+1];
  83. new notReadyTime[MAXPLAYERS+1];
  84. new bool:FirstSpawn[MAXPLAYERS+1] = true;
  85. new bool:AutoDmg[MAXPLAYERS+1] = false;
  86. new bool:bDisconnecting[MAXPLAYERS+1] = true;
  87.  
  88. OnAllReady()
  89. {
  90.     /*
  91.     enum MatchState
  92.     {
  93.     MS_Pre_Setup = 0,
  94.     MS_Setup_Up,
  95.     MS_Before_First_Half, // This is only used if the map changes.
  96.     MS_Live_First_Half,
  97.     MS_Before_Second_Half, // Always used.
  98.     MS_Live_Second_Half,
  99.     MS_Before_Overtime_First_Half,
  100.     MS_Live_Overtime_First_Half,
  101.     MS_Before_Overtime_Second_Half,
  102.     MS_Live_Overtime_Second_Half,
  103.     MS_Post_Match,
  104.     };
  105.     */
  106.     if(gMatchState == MS_Pre_Setup)
  107.     {
  108.         StartMatchSetup();
  109.     }
  110.     else if(gMatchState == MS_Before_First_Half)
  111.     {
  112.         StartFirstHalf();
  113.     }
  114.     else if(gMatchState == MS_Before_Second_Half)
  115.     {
  116.         StartSecondHalf();
  117.     }
  118.     else if(gMatchState == MS_Before_Overtime_First_Half)
  119.     {
  120.         StartOTFirstHalf();
  121.     }
  122.     else if(gMatchState == MS_Before_Overtime_Second_Half)
  123.     {
  124.         StartOTSecondHalf();
  125.     }
  126. }
  127.  
  128. CSLTeam(client)
  129. {
  130.     if(!ValidClient(client) || IsSourceTV(client))
  131.     {
  132.         return -1;
  133.     }
  134.     new String:steamID[24];
  135.     GetClientAuthString(client, steamID, 24);
  136.     return CSLTeamOfSteam(steamID);
  137. }
  138.  
  139. CSLTeamOfSteam(const String:steamID[])
  140. {
  141.     for(new x=0;x<5;x++)
  142.     {
  143.         if(StrEqual(steamID, TeamPlayers[TEAM_A][x]))
  144.         {
  145.             return TEAM_A;
  146.         }        
  147.     }
  148.     for(new x=0;x<5;x++)
  149.     {
  150.         if(StrEqual(steamID, TeamPlayers[TEAM_B][x]))
  151.         {
  152.             return TEAM_B;
  153.         }        
  154.     }
  155.     return -1;
  156. }
  157.  
  158. bool:AllowBots()
  159. {
  160.     return false; // Temp.
  161. }
  162.  
  163. ClientDefaults(client)
  164. {
  165.     fLastMessage[client] = 0.0;
  166.     AutoDmg[client] = false;
  167.     FirstSpawn[client] = true;
  168.     if(ValidClient(client)) {
  169.         GetClientName(client, clientUsername[client], 24);
  170.     }
  171.     bAuthed[client] = false;
  172.     bReady[client] = false;
  173.     readyUpTime[client] = 0;
  174.     notReadyTime[client] = 0;
  175.     bDisconnecting[client] = true;
  176.     bPubChatMuted[client] = false;
  177.     bTeamChatMuted[client] = false;
  178.     for(new x=0;x<=MAXPLAYERS;x++)
  179.     {
  180.         bMuted[client][x] = false;
  181.     }
  182. }
  183.  
  184. Kick(client, String:format[], any:...)
  185. {
  186.     if(!ValidClient(client))
  187.     {
  188.         return;
  189.     }
  190.     new String:reason[256];
  191.     VFormat(reason, sizeof(reason), format, 3);
  192.     if(StrEqual(reason,""))
  193.     {
  194.         KickClient(client);
  195.     }
  196.     else
  197.     {
  198.         KickClient(client,"%s",reason);
  199.     }
  200.     PrintToServer("KICK (%d): %s",client,reason);
  201. }
  202.  
  203. bool:ReadyUpState()
  204. {
  205.     if(gMatchState==MS_Pre_Setup || gMatchState==MS_Before_First_Half || gMatchState==MS_Before_Second_Half
  206.     || gMatchState==MS_Before_Overtime_First_Half || gMatchState==MS_Before_Overtime_Second_Half)
  207.     {
  208.         return true;
  209.     }
  210.     return false;
  211. }
  212.  
  213. ChangeCvar(const String:cvarName[], const String:newValue[])
  214. {
  215.     new Handle:hVar = FindConVar(cvarName);
  216.     new oldFlags = GetConVarFlags(hVar);
  217.     new newFlags = oldFlags;
  218.     newFlags &= ~FCVAR_NOTIFY;
  219.     SetConVarFlags(hVar, newFlags);
  220.     SetConVarString(hVar, newValue);
  221.     SetConVarFlags(hVar, oldFlags);
  222. }
  223.  
  224. EnterReadyUpState()
  225. {
  226.     // Just a hack for freeze time.
  227.     ChangeCvar("mp_freezetime", "3");
  228.     ChangeCvar("mp_buytime", "999");
  229.     ChangeCvar("mp_forcecamera", "0");
  230.     for(new x=0;x<=MAXPLAYERS;x++)
  231.     {
  232.         notReadyTime[x] = GetTime();
  233.         bReady[x] = false;
  234.     }
  235. }
  236.  
  237. public Action:WarmUpSpawner(Handle:timer)
  238. {
  239.     if(ReadyUpState())
  240.     {
  241.         DeleteBomb();
  242.         for(new x=1;x<=MAXPLAYERS;x++)
  243.         {
  244.             if(ValidClient(x) && !IsSourceTV(x) && GetClientTeam(x)>=CS_TEAM_T && !IsPlayerAlive(x))
  245.             {
  246.                 // Is it warm up?
  247.                 if(ReadyUpState())
  248.                 {
  249.                     CS_RespawnPlayer(x);
  250.                 }
  251.             }
  252.         }
  253.     }
  254. }
  255.  
  256. public Action:OneSecCheck(Handle:timer)
  257. {
  258.     for(new x=1;x<=MAXPLAYERS;x++)
  259.     {
  260.         if(ValidClient(x) && !IsFakeClient(x))
  261.         {
  262.             if(ReadyUpState())
  263.             {
  264.                 if(bAuthed[x] && !bReady[x] && notReadyTime[x] + 120 <= GetTime())
  265.                 {
  266.                     Kick(x, "You must ready up within 2 minutes");
  267.                     continue;
  268.                 }            
  269.                 new Handle:hBuffer = StartMessageOne("KeyHintText", x);
  270.                 new String:tmptext[256];
  271.                 Format(tmptext, 256, "READY: ");
  272.                 new String:optComma[32] = "";
  273.                 for(new y=1;y<=MAXPLAYERS;y++)
  274.                 {
  275.                     if(ValidClient(y) && !IsSourceTV(y))
  276.                     {
  277.                         if(bReady[y])
  278.                         {
  279.                             new String:plName[32];
  280.                             new String:plNameTrun[24];
  281.                             GetClientName(y, plName, 32);
  282.                             if(strlen(plName)>7)
  283.                             {
  284.                                 for(new z=0;z<4;z++)
  285.                                 {
  286.                                     plNameTrun[z] = plName[z];
  287.                                 }
  288.                                 plNameTrun[4] = '.';
  289.                                 plNameTrun[5] = '.';
  290.                                 plNameTrun[6] = '.';
  291.                             }
  292.                             else
  293.                             {
  294.                                 Format(plNameTrun, 20, "%s", plName);
  295.                             }
  296.                             Format(tmptext, 256, "%s%s%s", tmptext, optComma, plNameTrun);
  297.                             Format(optComma, 32, ", ");
  298.                         }
  299.                     }
  300.                 }
  301.                
  302.                 BfWriteByte(hBuffer, 1);
  303.                 BfWriteString(hBuffer, tmptext);
  304.                 EndMessage();
  305.             }
  306.         }
  307.     }
  308.     return Plugin_Continue;
  309. }
  310.  
  311. // This function checks if a STEAMID is valid.
  312. // AS VALVE UPDATES THEIR STANDARDS CHANGE THIS
  313. bool:BadSteamId(const String:steamID[])
  314. {
  315.     if(!AllowBots() && StrEqual(steamID,"BOT"))
  316.         return true;
  317.    
  318.     return false; // It's good.
  319. }
  320.  
  321. bool:ValidClient(client,bool:check_alive=false)
  322. {
  323.     if(client>0 && client<=MaxClients && IsClientConnected(client) && IsClientInGame(client))
  324.     {
  325.         if(check_alive && !IsPlayerAlive(client))
  326.         {
  327.             return false;
  328.         }
  329.         return true;
  330.     }
  331.     return false;
  332. }
  333.  
  334. public Action:MapDelayed(Handle:timer)
  335. {
  336.     ChangeMatchState(MS_Before_First_Half);
  337.     new String:curmap[32];
  338.     GetCurrentMap(curmap, 32);
  339.     if(!StrEqual(curmap, MatchMap))
  340.     {
  341.         ForceChangeLevel(MatchMap, "Setting up match");
  342.     }
  343. }
  344.  
  345. TeamSize(teamCSL)
  346. {
  347.     new i = 0;
  348.     for(new x=0;x<5;x++)
  349.     {
  350.         if(!StrEqual(TeamPlayers[teamCSL][x],""))
  351.         {
  352.             i++;
  353.         }
  354.     }
  355.     return i;
  356. }
  357.  
  358. TeamSizeActive(teamCSL)
  359. {
  360.     new i = 0;
  361.     for(new x=0;x<5;x++)
  362.     {
  363.         if(!StrEqual(TeamPlayers[teamCSL][x],""))
  364.         {
  365.             new cAtX = ClientOfSteamId(TeamPlayers[teamCSL][x]);
  366.             if(ValidClient(cAtX))
  367.             {
  368.                 i++;
  369.             }
  370.         }
  371.     }
  372.     return i;
  373. }
  374.  
  375. AddSteamToTeam(const String:steamID[], teamNum)
  376. {
  377.     // If the team is full, look for a disconnect. They are going to be replaced and will probably be penelized.
  378.     new TeamCount = TeamSize(teamNum);
  379.     if(TeamCount<5)
  380.     {
  381.         for(new x=0;x<5;x++)
  382.         {
  383.             if(StrEqual(TeamPlayers[teamNum][x],""))
  384.             {
  385.                 Format(TeamPlayers[teamNum][x], 24, "%s", steamID);
  386.                 return;
  387.             }
  388.         }
  389.     }
  390.     else
  391.     {
  392.         // Sorry, whoever left is bound to cry if they were trying to come back :(
  393.         for(new x=0;x<5;x++)
  394.         {
  395.             new ClientAt = ClientOfSteamId(TeamPlayers[teamNum][x]);
  396.             if(!ValidClient(ClientAt))
  397.             {
  398.                 Format(TeamPlayers[teamNum][x], 24, "%s", steamID);
  399.                 return;
  400.             }
  401.         }
  402.     }    
  403. }
  404.  
  405. StartFirstHalf()
  406. {
  407.     // Record.
  408.     // Map.
  409.     ServerCommand("tv_record %d_%s\n", GetTime(), MatchMap);
  410.     if(!CaptainMode)
  411.     {
  412.         // Go through each person (random order), if they aren't on a team assign them to the team lacking players, or random.
  413.         new bool:ClientIterated[MAXPLAYERS+1] = false;
  414.         for(new i=1;i<=MAXPLAYERS;i++)
  415.         {
  416.             new RandClient = GetRandomInt(1,MAXPLAYERS);
  417.             while(ClientIterated[RandClient])
  418.             {
  419.                 RandClient = GetRandomInt(1,MAXPLAYERS);
  420.             }
  421.             ClientIterated[RandClient] = true;
  422.             if(!ValidClient(RandClient) || IsSourceTV(RandClient))
  423.             {
  424.                 continue;
  425.             }
  426.             new String:steamID[24];
  427.             GetClientAuthString(RandClient, steamID, 24);
  428.             if(CSLTeam(RandClient)!=-1)
  429.             {
  430.                 continue; // Already on a team, on a group likely.
  431.             }
  432.             // Now put them on a team.
  433.             new TeamACount = TeamSizeActive(TEAM_A);
  434.             new TeamBCount = TeamSizeActive(TEAM_B);
  435.             if(TeamACount < TeamBCount)
  436.             {
  437.                 AddSteamToTeam(steamID, TEAM_A);
  438.             }
  439.             else if(TeamBCount < TeamACount)
  440.             {
  441.                 AddSteamToTeam(steamID, TEAM_B);
  442.             }
  443.             else
  444.             {
  445.                 new RandTeam = GetRandomInt(TEAM_A, TEAM_B);
  446.                 AddSteamToTeam(steamID, RandTeam);
  447.             }
  448.         }
  449.     }
  450.     /*
  451.     else
  452.     {
  453.     Later
  454.     }    
  455.     */
  456.     // Clear scores just incase.
  457.     TeamAScore = 0;
  458.     TeamBScore = 0;
  459.     // Team A goes T first
  460.     for(new x=1;x<=MAXPLAYERS;x++)
  461.     {
  462.         if(ValidClient(x) && !IsSourceTV(x))
  463.         {
  464.             new Team = CSLTeam(x);
  465.             if(Team==TEAM_A)
  466.             {
  467.                 CS_SwitchTeam(x, CS_TEAM_T);
  468.             }
  469.             else if(Team==TEAM_B)
  470.             {
  471.                 CS_SwitchTeam(x, CS_TEAM_CT);
  472.             }
  473.             else
  474.             {
  475.                 Kick(x, "Sorry, you aren't supposed to be here");
  476.             }
  477.         }        
  478.     }
  479.    
  480.     ChangeMatchState(MS_Live_First_Half);
  481.    
  482.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Starting the first half...");
  483.     EnforceMatchCvars();
  484.     ServerCommand("mp_restartgame 1\n");
  485.     RestartTimers = CreateTimer(2.0, RestartSecondTime);
  486. }
  487.  
  488. public Action:RestartSecondTime(Handle:timer)
  489. {
  490.     ServerCommand("mp_restartgame 5\n");
  491.     RestartTimers = CreateTimer(6.0, RestartThirdTime)
  492. }
  493.  
  494. public Action:RestartThirdTime(Handle:timer)
  495. {
  496.     ServerCommand("mp_restartgame 5\n");
  497.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Next round is live.");
  498.     RestartTimers = CreateTimer(4.5, LiveMessageTimer);
  499. }
  500.  
  501. public Action:LiveMessageTimer(Handle:timer)
  502. {
  503.     RestartTimers = INVALID_HANDLE;
  504.     PrintCenterTextAll("MATCH IS LIVE!");
  505.     RoundCounterOn = true;
  506.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Match is live!");
  507. }
  508.  
  509. bool:TeamsSetup()
  510. {
  511.     if(gMatchState>=MS_Live_First_Half && gMatchState<MS_Post_Match)
  512.     {
  513.         return true;
  514.     }
  515.     return false;
  516. }
  517.  
  518. EnforceMatchCvars(bool:ot = false)
  519. {
  520.     ChangeCvar("mp_freezetime", "8");
  521.     ChangeCvar("mp_forcecamera", "1");
  522.     ChangeCvar("mp_buytime", "15");
  523.     if(BunnyHopMode)
  524.     {
  525.         ChangeCvar("sv_enablebunnyhopping", "1");
  526.     }
  527.     else
  528.     {
  529.         ChangeCvar("sv_enablebunnyhopping", "0");
  530.     }
  531.     if(Ruleset==Rules_PUG)
  532.     {
  533.         ChangeCvar("mp_roundtime", "1.75");
  534.     }
  535.     else if(Ruleset==Rules_CGS)
  536.     {
  537.         ChangeCvar("mp_roundtime", "1.50");
  538.     }
  539.     if(ot)
  540.     {
  541.         if(Ruleset==Rules_PUG)
  542.         {
  543.             ChangeCvar("mp_startmoney", "8000");
  544.         }
  545.         else if(Ruleset==Rules_CGS)
  546.         {
  547.             ChangeCvar("mp_startmoney", "16000");
  548.         }
  549.     }
  550.     else
  551.     {
  552.         if(Ruleset==Rules_PUG)
  553.         {
  554.             ChangeCvar("mp_startmoney", "800");
  555.         }
  556.         else if(Ruleset==Rules_CGS)
  557.         {
  558.             ChangeCvar("mp_startmoney", "8000");
  559.         }
  560.     }
  561. }
  562.  
  563. StartSecondHalf()
  564. {
  565.     ChangeMatchState(MS_Live_Second_Half);
  566.     EnforceMatchCvars();
  567.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Starting the second half...");
  568.     ServerCommand("mp_restartgame 1\n");
  569.     RestartTimers = CreateTimer(2.0, RestartSecondTime);
  570. }
  571.  
  572. StartOTFirstHalf()
  573. {
  574.     ChangeMatchState(MS_Live_Overtime_First_Half);
  575.    
  576.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Starting the first half of overtime...");
  577.     EnforceMatchCvars(true);
  578.     ServerCommand("mp_restartgame 1\n");
  579.     RestartTimers = CreateTimer(2.0, RestartSecondTime);
  580. }
  581.  
  582. StartOTSecondHalf()
  583. {
  584.     ChangeMatchState(MS_Live_Overtime_Second_Half);
  585.    
  586.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Starting the second half of overtime...");
  587.     EnforceMatchCvars(true);
  588.     ServerCommand("mp_restartgame 1\n");
  589.     RestartTimers = CreateTimer(2.0, RestartSecondTime);
  590. }
  591.  
  592. // BUG: Votes dont continue if failed.
  593. TryStartMatch()
  594. {
  595.     // Are we on the correct map?
  596.     new String:curmap[32];
  597.     GetCurrentMap(curmap, 32);
  598.     if(!StrEqual(curmap, MatchMap))
  599.     {
  600.         PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Map is changing in 5 seconds, brace yourselves.");
  601.         CreateTimer(5.0, MapDelayed);
  602.     }
  603.     else
  604.     {
  605.         StartFirstHalf();
  606.     }                                                                                                  
  607. }
  608.  
  609. RulesCSL()
  610. {
  611.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Ruleset will be: PUG");
  612.     Ruleset = Rules_PUG;
  613.     TeamVote();
  614. }
  615.  
  616. SetMatchMap(const String:mapname[])
  617. {
  618.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Map will be: %s", mapname);
  619.     Format(MatchMap, 32, mapname);
  620.     TryStartMatch();
  621. }
  622.  
  623. public Handle_MapVote(Handle:menu, MenuAction:action, param1, param2)
  624. {
  625.     if (action == MenuAction_End)
  626.     {
  627.         CloseHandle(menu);
  628.     } else if (action == MenuAction_VoteEnd) {
  629.         new String:map[32];
  630.         GetMenuItem(menu, param1, map, sizeof(map));
  631.         if(StrEqual(map,"Random"))
  632.         {
  633.             SetMatchMap(MapNames[GetRandomInt(0, GetMapCount()-1)]);        
  634.         }
  635.         else
  636.         {
  637.             SetMatchMap(map);
  638.         }
  639.     }
  640.     else if(action==MenuAction_VoteCancel)
  641.     {
  642.         // Choose a random map.
  643.         SetMatchMap(MapNames[GetRandomInt(0, GetMapCount()-1)]);
  644.     }
  645. }
  646.  
  647. StartMapVote()
  648. {
  649.     // Choose a rule set.
  650.     if (IsVoteInProgress())
  651.     {
  652.         CancelVote();
  653.     }
  654.    
  655.     new Handle:menu = CreateMenu(Handle_MapVote);
  656.     SetMenuTitle(menu, "Vote for the map");
  657.     // Random order.
  658.     new bool:bShowed[MAX_MAPS];
  659.     for(new x=0;x<GetMapCount();x++)
  660.     {        
  661.         new Rand = GetRandomInt(0, GetMapCount()-1);
  662.         while(bShowed[Rand])
  663.         {
  664.             Rand = GetRandomInt(0, GetMapCount()-1);
  665.         }
  666.         bShowed[Rand] = true;
  667.         AddMenuItem(menu, MapNames[Rand], MapNames[Rand]);
  668.     }
  669.     SetMenuExitButton(menu, false);
  670.     VoteMenuToAll(menu, 15);
  671. }
  672.  
  673. BHopOn()
  674. {
  675.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Bunnyhopping will be enabled.");
  676.     BunnyHopMode = true;
  677.     StartMapVote();
  678. }
  679.  
  680. BHopOff()
  681. {
  682.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Bunnyhopping will be disabled.");
  683.     BunnyHopMode = false;
  684.     StartMapVote();
  685. }
  686.  
  687. public Handle_BHopVote(Handle:menu, MenuAction:action, param1, param2)
  688. {
  689.     if (action == MenuAction_End)
  690.     {
  691.         CloseHandle(menu);
  692.     } else if (action == MenuAction_VoteEnd) {
  693.         // 0 = Off
  694.         // 1 = On
  695.         if(param1 == 0)
  696.         {
  697.             BHopOff();
  698.         }
  699.         else
  700.         {
  701.             BHopOn();
  702.         }
  703.     }
  704.     else if(action==MenuAction_VoteCancel)
  705.     {
  706.         BHopOff();
  707.     }
  708. }
  709.  
  710. BHopVote()
  711. {
  712.     if(IsVoteInProgress())
  713.     {
  714.         CancelVote();
  715.     }
  716.    
  717.     new Handle:menu = CreateMenu(Handle_BHopVote);
  718.     SetMenuTitle(menu, "Vote for bunny hopping");
  719.     AddMenuItem(menu, "off", "Off");
  720.     AddMenuItem(menu, "on", "On");
  721.     SetMenuExitButton(menu, false);
  722.     VoteMenuToAll(menu, 15);
  723. }
  724.  
  725. TeamsRandom()
  726. {
  727.     CaptainMode = false;
  728.     BHopVote();
  729. }
  730.  
  731. /*public Handle_TeamVote(Handle:menu, MenuAction:action, param1, param2)
  732. {
  733. if (action == MenuAction_End)
  734. {
  735. CloseHandle(menu);
  736. } else if (action == MenuAction_VoteEnd) {
  737. // 0 = Random
  738. // 1 = Captains
  739. if(param1 == 0)
  740. {
  741. TeamsRandom();
  742. }
  743. else
  744. {
  745. TeamsCaptains();
  746. }
  747. }
  748. }*/
  749.  
  750. TeamVote()
  751. {
  752.     // For now random teams.
  753.     TeamsRandom();
  754.     /*// Choose a team set.
  755.     if (IsVoteInProgress())
  756.     {
  757.         CancelVote();
  758.     }
  759.    
  760.     new Handle:menu = CreateMenu(Handle_TeamVote);
  761.     SetMenuTitle(menu, "Vote for team sorting");
  762.     AddMenuItem(menu, "rand", "Random");
  763.     AddMenuItem(menu, "capt", "Captains");
  764.     SetMenuExitButton(menu, false);
  765.     VoteMenuToAll(menu, 15);*/
  766. }
  767.  
  768. RulesCGS()
  769. {
  770.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Ruleset will be: CGS");
  771.     Ruleset = Rules_CGS;
  772.     TeamVote();
  773. }
  774.  
  775. public Handle_RulesVote(Handle:menu, MenuAction:action, param1, param2)
  776. {
  777.     if (action == MenuAction_End)
  778.     {
  779.         CloseHandle(menu);
  780.     } else if (action == MenuAction_VoteEnd) {
  781.         // 0 = CSL
  782.         // 1 = Pug
  783.         if(param1 == 0)
  784.         {
  785.             RulesCSL();
  786.         }
  787.         else
  788.         {
  789.             RulesCGS();
  790.         }
  791.     }
  792.     else if(action==MenuAction_VoteCancel)
  793.     {
  794.         RulesCSL();
  795.     }
  796. }
  797.  
  798. StartRulesVote()
  799. {
  800.     // Choose a rule set.
  801.     if (IsVoteInProgress())
  802.     {
  803.         CancelVote();
  804.     }
  805.    
  806.     new Handle:menu = CreateMenu(Handle_RulesVote);
  807.     SetMenuTitle(menu, "Vote for rule set");
  808.     AddMenuItem(menu, "csl", "CSL (15 Round Halves, $800)");
  809.     AddMenuItem(menu, "cgs", "CGS (9 Round Halves, $8000)");
  810.     SetMenuExitButton(menu, false);
  811.     VoteMenuToAll(menu, 15);
  812. }
  813.  
  814. ChangeMatchState(MatchState:newState)
  815. {
  816.     gMatchState = newState;
  817.    
  818.     if(ReadyUpState())
  819.     {
  820.         EnterReadyUpState();
  821.     }
  822. }
  823.  
  824. StartMatchSetup()
  825. {
  826.     // Vote for rule set.
  827.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Starting match setup and votes.");
  828.     ChangeMatchState(MS_Setup);
  829.     StartRulesVote();
  830. }
  831.  
  832. public OnPluginStart()
  833. {
  834.     ServerCommand("exec server_pug.cfg\n");
  835.     OffsetAccount = FindSendPropOffs("CCSPlayer", "m_iAccount");
  836.     hMaxPlayers = CreateConVar("sv_maxplayers", MAX_PLAYERS_DEFAULT, "Match size.", FCVAR_PLUGIN|FCVAR_REPLICATED|FCVAR_SPONLY|FCVAR_NOTIFY);
  837.     CreateConVar("sm_pug_version", "0.1", "PUG Plugin Version",FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
  838.     hTVEnabled = FindConVar("tv_enable");
  839.     hBotQuota = FindConVar("bot_quota");
  840.     SetConVarInt(hBotQuota, 0);
  841.    
  842.     //SetConVarInt(hTVEnabled, 1);
  843.     ClearMatch();
  844.     new Handle:hTagsCvar = FindConVar("sv_tags");
  845.     new oldFlags = GetConVarFlags(hTagsCvar);
  846.     new newFlags = oldFlags;
  847.     newFlags &= ~FCVAR_NOTIFY;
  848.     SetConVarFlags(hTagsCvar, newFlags);
  849.     //new Handle:hTVName = FindConVar("tv_name");
  850.     //SetConVarString(hTVName, "CSL SourceTV");
  851.     //new Handle:hTVTrans = FindConVar("tv_transmitall");
  852.     CreateTimer(4.0, WarmUpSpawner, _, TIMER_REPEAT);
  853.     //SetConVarInt(hTVTrans, 1);
  854.     LoadMapsDir();
  855.     HookEvent("player_spawn",SpawnCallback);
  856.     HookEvent("player_death",DeathCallback);
  857.     HookEvent("player_hurt",HurtCallback);
  858.     HookEvent("round_start",RoundStartCallback);
  859.     HookEvent("round_end",RoundEndCallback);
  860.     AddCommandListener(HookJoinTeam, "jointeam");
  861.     AddCommandListener(HookSpectate, "spectate");
  862.     AddCommandListener(HookBuy, "buy");
  863.     for(new x=0;x<MAXPLAYERS+1;x++) //[0-64]
  864.     {
  865.         ClientDefaults(x);
  866.     }
  867.     // Hooks
  868.     RegConsoleCmd("sm_add", Ready);
  869.     RegConsoleCmd("sm_ready", Ready);
  870.     RegConsoleCmd("sm_rdy", Ready);
  871.     RegConsoleCmd("sm_dmg", Damage);
  872.     RegConsoleCmd("sm_damage", Damage);
  873.     RegConsoleCmd("sm_autodamage", AutoDamage);
  874.     RegConsoleCmd("sm_autodmg", AutoDamage);
  875.     AddCommandListener(Help, "sm_help");
  876.     CreateTimer(1.0, OneSecCheck, _, TIMER_REPEAT);
  877. }
  878.  
  879. public Action:Help(client, const String:command[], args)
  880. {
  881.     PrintToChat(client, "\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Commands: /ready, /rdy, /add, /noready, /help, /dmg, /damage, /autodamage, /autodmg");
  882.     return Plugin_Handled;
  883. }
  884.  
  885. public Action:Damage(client, args)
  886. {
  887.     if(!MatchLive())
  888.     {
  889.         PrintToChat(client, "\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 You can't use this now.");
  890.     }
  891.     else
  892.     {
  893.         if(IsPlayerAlive(client))
  894.         {
  895.             PrintToChat(client, "\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 You must be dead to use this.");
  896.         }
  897.         else
  898.         {
  899.             PrintDmgReport(client);
  900.         }
  901.     }
  902. }
  903.  
  904. public Action:AutoDamage(client, args)
  905. {
  906.     if(AutoDmg[client])
  907.     {
  908.         AutoDmg[client] = false;
  909.         PrintToChat(client, "\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Auto /dmg has been toggled off.");
  910.     }
  911.     else
  912.     {
  913.         AutoDmg[client] = true;
  914.         PrintToChat(client, "\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Auto /dmg has been toggled on.");
  915.     }
  916. }
  917.  
  918. public Action:Ready(client, args)
  919. {
  920.     if(!ReadyUpState())
  921.     {
  922.         PrintToChat(client, "\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 You don't need to ready up right now.");
  923.     }
  924.     else
  925.     {
  926.         if(bReady[client])
  927.         {
  928.             PrintToChat(client,"\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 You are already ready.");
  929.         }
  930.         else
  931.         {
  932.             ReadyUp(client);
  933.         }
  934.     }
  935.     return Plugin_Handled;
  936. }
  937.  
  938. ReadyUp(client) {
  939.     new String:plName[32];
  940.     GetClientName(client, plName, 32);
  941.     bReady[client] = true;
  942.     readyUpTime[client] = GetTime();
  943.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 %s is now ready.", plName);
  944.     // If this is the last ready up.
  945.     new bool:bStillMore = false;
  946.     new PlCount = 0;
  947.     for(new a=1;a<=MAXPLAYERS;a++)
  948.     {
  949.         if(ValidClient(a) && !IsSourceTV(a))
  950.         {
  951.             PlCount++;
  952.             if(!bReady[a])
  953.             {
  954.                 bStillMore = true;
  955.             }
  956.         }
  957.     }
  958.     if(!bStillMore)
  959.     {
  960.         if(PlCount == GetConVarInt(hMaxPlayers))
  961.         {
  962.             OnAllReady();
  963.         }
  964.         else
  965.         {
  966.             new NeedPl = GetConVarInt(hMaxPlayers) - PlCount;
  967.             PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Still waiting on %d players...", NeedPl);
  968.         }
  969.     }
  970. }
  971.  
  972. public Action:RespawnCheck(Handle:timer, any:userid)
  973. {
  974.     new client = GetClientOfUserId(userid);
  975.     if(ReadyUpState() && ValidClient(client) && !IsSourceTV(client) && !IsPlayerAlive(client))
  976.     {
  977.         CS_RespawnPlayer(client);
  978.     }    
  979. }
  980.  
  981. LogKillLocalStats(const String:steamAttacker[], const String:steamVictim[], const String:weapon[], bool:headshot)
  982. {
  983.     if(!MatchLive())
  984.     {
  985.         return;
  986.     }
  987.     if(CurrentRound<1)
  988.     {
  989.         return;
  990.     }
  991.     // Create a new array.
  992.     new Handle:newArray = CreateArray(24);
  993.     PushArrayString(newArray, steamAttacker);
  994.     PushArrayString(newArray, steamVictim);
  995.     PushArrayString(newArray, weapon);
  996.     PushArrayCell(newArray, headshot);
  997. }
  998.  
  999. LogKill(attacker, victim, const String:weapon[], bool:headshot)
  1000. {
  1001.     if(MatchLive())
  1002.     {
  1003.         new String:steamAttacker[24];
  1004.         new String:steamVictim[24];
  1005.         GetClientAuthString(attacker, steamAttacker, 24);
  1006.         GetClientAuthString(victim, steamVictim, 24);
  1007.         LogKillLocalStats(steamAttacker, steamVictim, weapon, headshot);
  1008.     }
  1009. }
  1010.  
  1011. public Action:DeathCallback(Handle:event, const String:name[], bool:dontBroadcast)
  1012. {
  1013.     new userid = GetEventInt(event, "userid");
  1014.     CreateTimer(2.0, RespawnCheck, userid);
  1015.     new client = GetClientOfUserId(userid);
  1016.     new attacker_userid = GetEventInt(event, "attacker");
  1017.     new attacker = GetClientOfUserId(attacker_userid);
  1018.     new String:weapon[64];
  1019.     GetEventString(event, "weapon", weapon, 64);
  1020.     new bool:Headshot = (GetEventInt(event, "headshot")==0)?false:true;
  1021.     if(ValidClient(client))
  1022.     {
  1023.         if(attacker==client || attacker==0)
  1024.         {
  1025.             LogKill(client, client, weapon, false);
  1026.         }
  1027.         else if(ValidClient(attacker))
  1028.         {
  1029.             LogKill(attacker, client, weapon, Headshot);
  1030.         }
  1031.     }
  1032.    
  1033.     if(MatchLive() && AutoDmg[client])
  1034.     {
  1035.         PrintDmgReport(client);
  1036.     }
  1037.    
  1038.     return Plugin_Continue;
  1039. }
  1040.  
  1041. public Action:RoundStartCallback(Handle:event, const String:name[], bool:dontBroadcast)
  1042. {
  1043.     if(RoundCounterOn == true)
  1044.     {
  1045.         CurrentRound++;
  1046.         // Create an array here.
  1047.         hMatchDamage[CurrentRound] = CreateArray();
  1048.         hMatchKills[CurrentRound] = CreateArray();
  1049.         // Who is winning?
  1050.         if(TeamAScore>TeamBScore)
  1051.         {
  1052.             // Is team A ct or t?
  1053.             if(CSTeamToCSL(CS_TEAM_CT) == TEAM_A)
  1054.             {
  1055.                 // They are CT's.
  1056.                 PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Round %d. CT's winning %d - %d", CurrentRound, TeamAScore, TeamBScore);
  1057.             }
  1058.             else
  1059.             {
  1060.                 PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Round %d. T's winning %d - %d", CurrentRound, TeamAScore, TeamBScore);
  1061.             }
  1062.         }
  1063.         else if(TeamBScore>TeamAScore)
  1064.         {
  1065.             if(CSTeamToCSL(CS_TEAM_CT) == TEAM_B)
  1066.             {
  1067.                 // They are CT's.
  1068.                 PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Round %d. CT's winning %d - %d", CurrentRound, TeamBScore, TeamAScore);
  1069.             }
  1070.             else
  1071.             {
  1072.                 PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Round %d. T's winning %d - %d", CurrentRound, TeamBScore, TeamAScore);
  1073.             }
  1074.         }
  1075.         else
  1076.         {
  1077.             PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Round %d. Tie game, %d - %d", CurrentRound, TeamAScore, TeamBScore);
  1078.         }
  1079.     }
  1080.     return Plugin_Continue;
  1081. }
  1082.  
  1083. public Action:RoundEndCallback(Handle:event, const String:name[], bool:dontBroadcast)
  1084. {
  1085.     //new reason = GetEventInt(event, "reason");
  1086.     new winner = GetEventInt(event, "winner");
  1087.     if(RoundCounterOn == true)
  1088.     {
  1089.         if(winner==CS_TEAM_T)
  1090.         {
  1091.             new CSLT = CSTeamToCSL(CS_TEAM_T);
  1092.             if(CSLT == TEAM_A)
  1093.             {
  1094.                 TeamAScore++;
  1095.             }
  1096.             else
  1097.             {
  1098.                 TeamBScore++;
  1099.             }
  1100.         }
  1101.         else if(winner==CS_TEAM_CT)
  1102.         {
  1103.             new CSLCT = CSTeamToCSL(CS_TEAM_CT);
  1104.             if(CSLCT == TEAM_A)
  1105.             {
  1106.                 TeamAScore++;
  1107.             }
  1108.             else
  1109.             {
  1110.                 TeamBScore++;
  1111.             }
  1112.         }
  1113.        
  1114.         // Is this CSL or CGS rules?
  1115.         // Check score first, if there is a winner call WinLegit or whatever.
  1116.         // Are we in overtime?
  1117.         // Check for a winner, then check for transitioning stuff. If there is a winner, no need to go to Half, etc...
  1118.         if(gMatchState >= MS_Before_Overtime_First_Half && gMatchState!=MS_Post_Match)
  1119.         {
  1120.             // If CSL, overtime start score is 15-15
  1121.             // Otherwise, 9 - 9
  1122.             if(Ruleset==Rules_PUG)
  1123.             {
  1124.                 if(TeamAScore >= 21)
  1125.                 {
  1126.                     MatchWinOT(TEAM_A);
  1127.                     return Plugin_Continue;
  1128.                 }
  1129.                 else if(TeamBScore >= 21)
  1130.                 {
  1131.                     MatchWinOT(TEAM_B);
  1132.                     return Plugin_Continue;
  1133.                 }
  1134.                 else if(TeamAScore == 20 && TeamBScore == 20)
  1135.                 {
  1136.                     // Tie.
  1137.                     MatchTieOT();
  1138.                     return Plugin_Continue;
  1139.                 }
  1140.             }
  1141.             else if(Ruleset==Rules_CGS)
  1142.             {
  1143.                 if(TeamAScore >= 13)
  1144.                 {
  1145.                     MatchWinOT(TEAM_A);
  1146.                     return Plugin_Continue;
  1147.                 }
  1148.                 else if(TeamBScore >= 13)
  1149.                 {
  1150.                     MatchWinOT(TEAM_B);
  1151.                     return Plugin_Continue;
  1152.                 }
  1153.                 else if(TeamAScore == 12 && TeamBScore == 12)
  1154.                 {
  1155.                     // Tie.
  1156.                     MatchTieOT();
  1157.                     return Plugin_Continue;
  1158.                 }
  1159.             }
  1160.         }
  1161.         else
  1162.         {
  1163.             if(Ruleset==Rules_PUG)
  1164.             {
  1165.                 // Check of score >=16.
  1166.                 if(TeamAScore>=16)
  1167.                 {
  1168.                     MatchWin(TEAM_A);
  1169.                 }
  1170.                 else if(TeamBScore>=16)
  1171.                 {
  1172.                     MatchWin(TEAM_B);
  1173.                 }
  1174.             }
  1175.             else if(Ruleset==Rules_CGS)
  1176.             {
  1177.                 // Check of score >=10.
  1178.                 if(TeamAScore>=10)
  1179.                 {
  1180.                     MatchWin(TEAM_A);
  1181.                 }
  1182.                 else if(TeamBScore>=10)
  1183.                 {
  1184.                     MatchWin(TEAM_B);
  1185.                 }
  1186.             }
  1187.         }
  1188.        
  1189.         // Now do our checks for transitions.
  1190.         if(Ruleset==Rules_PUG)
  1191.         {
  1192.             if(CurrentRound==15)
  1193.             {
  1194.                 // Go to second half.
  1195.                 TransSecondHalfWarmup();
  1196.                 return Plugin_Continue;
  1197.             }
  1198.             else if(CurrentRound==30)
  1199.             {
  1200.                 // Previous checks allow for no use of ==15, ==15
  1201.                 TransOTFirstHalfWarmup();
  1202.                 return Plugin_Continue;
  1203.             }
  1204.             else if(CurrentRound==35)
  1205.             {
  1206.                 TransOTSecondHalfWarmup();
  1207.                 return Plugin_Continue;
  1208.             }
  1209.         }
  1210.         else if(Ruleset==Rules_CGS)
  1211.         {
  1212.             if(CurrentRound==9)
  1213.             {
  1214.                 // Go to second half.
  1215.                 TransSecondHalfWarmup();
  1216.                 return Plugin_Continue;
  1217.             }
  1218.             else if(CurrentRound==18)
  1219.             {
  1220.                 // Previous checks allow for no use of ==15, ==15
  1221.                 TransOTFirstHalfWarmup();
  1222.                 return Plugin_Continue;
  1223.             }
  1224.             else if(CurrentRound==21)
  1225.             {
  1226.                 TransOTSecondHalfWarmup();
  1227.                 return Plugin_Continue;
  1228.             }
  1229.         }
  1230.     }
  1231.     return Plugin_Continue;
  1232. }
  1233.  
  1234. MoveAfterTrans()
  1235. {
  1236.     for(new x=1;x<=MAXPLAYERS;x++)
  1237.     {
  1238.         if(ValidClient(x) && !IsSourceTV(x))
  1239.         {
  1240.             new cslTeam = CSLTeam(x);
  1241.             if(cslTeam!=TEAM_A && cslTeam!=TEAM_B)
  1242.             {
  1243.                 continue; // Should we kick him? Probably not. This shouldn't happen.
  1244.             }
  1245.             else
  1246.             {
  1247.                 new csTeam = CSLToCSTeam(cslTeam);
  1248.                 new curTeam = GetClientTeam(x);
  1249.                 if(curTeam!=csTeam)
  1250.                 {
  1251.                     CS_SwitchTeam(x, csTeam);
  1252.                 }
  1253.             }
  1254.         }
  1255.     }
  1256. }
  1257.  
  1258. TransSecondHalfWarmup()
  1259. {
  1260.     // All stop the round counter.
  1261.     RoundCounterOn = false;
  1262.     // Change state.
  1263.     ChangeMatchState(MS_Before_Second_Half);
  1264.     // Move them.
  1265.     MoveAfterTrans();
  1266. }
  1267.  
  1268. TransOTFirstHalfWarmup()
  1269. {
  1270.     RoundCounterOn = false;
  1271.     ChangeMatchState(MS_Before_Overtime_First_Half);
  1272.     MoveAfterTrans();
  1273. }
  1274.  
  1275. TransOTSecondHalfWarmup()
  1276. {
  1277.     RoundCounterOn = false;
  1278.     ChangeMatchState(MS_Before_Overtime_Second_Half);
  1279.     MoveAfterTrans();
  1280. }
  1281.  
  1282. public Action:ReduceToOneHundred(Handle:timer, any:userid)
  1283. {
  1284.     new client = GetClientOfUserId(userid);
  1285.     if(ValidClient(client) && ReadyUpState() && IsPlayerAlive(client))
  1286.     {
  1287.         if(GetClientHealth(client)>100)
  1288.         {
  1289.             SetEntityHealth(client, 100);
  1290.         }
  1291.     }
  1292. }
  1293.  
  1294. public Action:SpawnCallback(Handle:event, const String:name[], bool:dontBroadcast)
  1295. {
  1296.     new userid = GetEventInt(event, "userid");
  1297.     new client = GetClientOfUserId(userid);
  1298.     if(!ValidClient(client) || IsSourceTV(client))
  1299.     {
  1300.         return Plugin_Continue;
  1301.     }
  1302.     if(ReadyUpState())
  1303.     {
  1304.         if(FirstSpawn[client])
  1305.         {
  1306.             FirstSpawn[client] = false;
  1307.             PrintToChat(client, "\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Welcome! Please /ready (/add) (/rdy) up and type /help if you need help.");
  1308.         }
  1309.         else if(!bReady[client])
  1310.         {
  1311.             PrintToChat(client, "\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Type /ready (/add) (/rdy) in chat when you are ready.");
  1312.         }
  1313.         if(GetMoney(client)!=16000)
  1314.         {
  1315.             SetMoney(client, 16000);
  1316.         }
  1317.        
  1318.         if(!bReady[client] && IsFakeClient(client)) {
  1319.             ReadyUp(client);
  1320.         }
  1321.        
  1322.         // Spawn protection.
  1323.         SetEntityHealth(client, 500);
  1324.         CreateTimer(2.0, ReduceToOneHundred, userid);
  1325.     }
  1326.     else
  1327.     {
  1328.         if(FirstSpawn[client])
  1329.         {
  1330.             PrintToChat(client, "\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Welcome! Match is LIVE, type /help for help.");
  1331.             FirstSpawn[client] = false;
  1332.         }
  1333.     }
  1334.     return Plugin_Continue;
  1335. }
  1336.  
  1337. PrintDmgReport(client)
  1338. {
  1339.     // Get current round.
  1340.     new OurTeam = GetClientTeam(client);
  1341.     for(new x=1;x<=MAXPLAYERS;x++)
  1342.     {
  1343.         if(ValidClient(x) && !IsSourceTV(x) && GetClientTeam(x)!=OurTeam)
  1344.         {
  1345.             new Handle:dmgRound = hMatchDamage[CurrentRound];
  1346.             new dmgSize = GetArraySize(dmgRound);
  1347.             new dmgTo = 0;
  1348.             new dmgHits = 0;
  1349.             new String:clName[24];
  1350.             GetClientName(x, clName, 24);
  1351.             for(new y=0;y<dmgSize;y++)
  1352.             {
  1353.                 new String:Att[24];
  1354.                 new String:Vic[24];
  1355.                 new Handle:singleDmg = GetArrayCell(dmgRound, y);
  1356.                 GetArrayString(singleDmg, 0, Att, 24);
  1357.                 GetArrayString(singleDmg, 1, Vic, 24);
  1358.                 new dM = GetArrayCell(singleDmg, 2);
  1359.                 new IndAtt = ClientOfSteamId(Att);
  1360.                 new IndVic = ClientOfSteamId(Vic);
  1361.                 if(ValidClient(IndAtt) && ValidClient(IndVic) && IndAtt==client && IndVic==x)
  1362.                 {
  1363.                     dmgTo+=dM;
  1364.                     dmgHits++;
  1365.                 }
  1366.             }
  1367.             PrintToChat(client, "\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 %s - Damage Given: %d (%d hits)", clName, dmgTo, dmgHits);
  1368.         }
  1369.     }
  1370.    
  1371. }
  1372.  
  1373. LogDmg(Attacker, Victim, Dmg)
  1374. {
  1375.     if(!MatchLive())
  1376.     {
  1377.         return;
  1378.     }
  1379.     if(CurrentRound<1)
  1380.     {
  1381.         return;
  1382.     }
  1383.     new String:AttackerSteam[24];
  1384.     new String:VictimSteam[24];
  1385.     GetClientAuthString(Attacker, AttackerSteam, 24);
  1386.     GetClientAuthString(Victim, VictimSteam, 24);
  1387.     // Create a new array.
  1388.     new Handle:newArray = CreateArray(24);
  1389.     PushArrayString(newArray, AttackerSteam);
  1390.     PushArrayString(newArray, VictimSteam);
  1391.     PushArrayCell(newArray, Dmg);
  1392.     PushArrayCell(hMatchDamage[CurrentRound], newArray);
  1393. }
  1394.  
  1395. public Action:HurtCallback(Handle:event, const String:name[], bool:dontBroadcast)
  1396. {
  1397.     // userid, attacker, dmg_health
  1398.     new VictimUserid = GetEventInt(event, "userid");
  1399.     new AttackerUserid = GetEventInt(event, "attacker");
  1400.     new VictimIndex = GetClientOfUserId(VictimUserid);
  1401.     new AttackerIndex = GetClientOfUserId(AttackerUserid);
  1402.     new Dmg = GetEventInt(event, "dmg_health");
  1403.     if(VictimIndex>0 && AttackerIndex>0 && ValidClient(VictimIndex) && ValidClient(AttackerIndex) && AttackerIndex!=VictimIndex)
  1404.     {
  1405.         LogDmg(AttackerIndex, VictimIndex, Dmg);        
  1406.     }
  1407.     return Plugin_Continue;
  1408. }
  1409.  
  1410. SetMoney(client, money)
  1411. {
  1412.     if(ValidClient(client) && !IsSourceTV(client))
  1413.     {
  1414.         SetEntData(client, OffsetAccount, money);
  1415.     }
  1416. }
  1417.  
  1418. GetMoney(client)
  1419. {
  1420.     if(ValidClient(client) && !IsSourceTV(client))
  1421.     {
  1422.         return GetEntData(client, OffsetAccount);
  1423.     }
  1424.     return 0;
  1425. }
  1426.  
  1427. #define CS_TEAM_T 2
  1428. #define CS_TEAM_CT 3
  1429. #define CS_TEAM_SPEC 1
  1430. #define CS_TEAM_AUTO 0
  1431.  
  1432. public Action:HookSpectate(client, const String:command[], argc)
  1433. {
  1434.     PrintCenterText(client, "CSL: You can't join spectator.");
  1435.     return Plugin_Handled;
  1436. }
  1437.  
  1438. OurAutojoin(client)
  1439. {
  1440.     // Which team are we supposed to be on?
  1441.     // Have the teams been setup yet?
  1442.     if(TeamsSetup())
  1443.     {
  1444.         new MyTeam = CSLTeam(client);
  1445.         if(MyTeam!=-1)
  1446.         {
  1447.             // Join the team we are on.
  1448.             if(GetClientTeam(client)!=CSLToCSTeam(MyTeam))
  1449.             {
  1450.                 CS_SwitchTeam(client, CSLToCSTeam(MyTeam));
  1451.             }
  1452.         }
  1453.         else
  1454.         {
  1455.             // Find a team for us.
  1456.             // What team has less active players?
  1457.             new String:steamID[24];
  1458.             GetClientAuthString(client, steamID, 24);
  1459.             new APTeamA = TeamSizeActive(TEAM_A);
  1460.             new APTeamB = TeamSizeActive(TEAM_B);
  1461.             if(APTeamA<APTeamB)
  1462.             {
  1463.                 // Team A
  1464.                 AddSteamToTeam(steamID, TEAM_A);
  1465.             }
  1466.             else if(APTeamB<APTeamA)
  1467.             {
  1468.                 // Team B
  1469.                 AddSteamToTeam(steamID, TEAM_B);
  1470.             }
  1471.             else
  1472.             {
  1473.                 // Random
  1474.                 new RandTeam = GetRandomInt(TEAM_A, TEAM_B);
  1475.                 AddSteamToTeam(steamID, RandTeam);
  1476.             }
  1477.             MyTeam = CSLTeam(client);
  1478.             if(MyTeam!=-1)
  1479.             {
  1480.                 // Join the team we are on.
  1481.                 if(GetClientTeam(client)!=CSLToCSTeam(MyTeam))
  1482.                 {
  1483.                     CS_SwitchTeam(client, CSLToCSTeam(MyTeam));
  1484.                 }
  1485.             }
  1486.         }
  1487.     }
  1488. }
  1489.  
  1490. TryGoT(client)
  1491. {
  1492.     if(TeamsSetup())
  1493.     {
  1494.         new MyTeam = CSLTeam(client);
  1495.         if(MyTeam!=-1)
  1496.         {
  1497.             // Join the team we are on.
  1498.             if(CSLToCSTeam(MyTeam)!=CS_TEAM_T)
  1499.             {
  1500.                 PrintCenterText(client, "\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 You are on Team %s, they are currently Counter-Terrorist.", ((MyTeam==TEAM_A)?"A":"B"));
  1501.             }
  1502.             if(GetClientTeam(client)!=CSLToCSTeam(MyTeam))
  1503.             {
  1504.                 CS_SwitchTeam(client, CSLToCSTeam(MyTeam));
  1505.             }
  1506.         }
  1507.         else
  1508.         {
  1509.             // They clearly want to be a Terrorist, which team is T?
  1510.             new TCSL = CSTeamToCSL(CS_TEAM_T);
  1511.             new CTCSL = CSTeamToCSL(CS_TEAM_CT);
  1512.             new ATCount = TeamSizeActive(TCSL);
  1513.             new ACTCount = TeamSizeActive(CTCSL);
  1514.             new String:steamID[24];
  1515.             GetClientAuthString(client, steamID, 24);
  1516.             if(ATCount <= ACTCount)
  1517.             {
  1518.                 // Let them, and add them to the team.
  1519.                 AddSteamToTeam(steamID, TCSL);
  1520.                 if(GetClientTeam(client)!=CS_TEAM_T)
  1521.                 {
  1522.                     CS_SwitchTeam(client, CS_TEAM_T);
  1523.                 }
  1524.             }
  1525.             else
  1526.             {
  1527.                 // They gotta go CT, add em and tell em the bad news :(
  1528.                 PrintCenterText(client, "CSL: Sorry, you have been forced to Team %s, the Counter-Terrorists.", ((CTCSL==TEAM_A)?"A":"B"));
  1529.                 AddSteamToTeam(steamID, CTCSL);
  1530.                 if(GetClientTeam(client)!=CS_TEAM_CT)
  1531.                 {
  1532.                     CS_SwitchTeam(client, CS_TEAM_CT);
  1533.                 }
  1534.             }
  1535.         }
  1536.     }
  1537. }
  1538.  
  1539. CSLToCSTeam(cslTeam)
  1540. {
  1541.     /*
  1542.     MS_Before_First_Half, // This is only used if the map changes.
  1543.     MS_Live_First_Half,
  1544.     MS_Before_Second_Half, // Always used. Team A is CT B is T
  1545.     MS_Live_Second_Half,    // Team A is CT team B is T
  1546.     MS_Before_Overtime_First_Half, // Team A is T, Team B is CT
  1547.     MS_Live_Overtime_First_Half, // Team A is T, Team B is CT
  1548.     MS_Before_Overtime_Second_Half, // Team A is CT, Team B is T
  1549.     MS_Live_Overtime_Second_Half, // Team A is CT, Team B is T
  1550.     */
  1551.     // This might need an edit when captains come along?
  1552.     if(gMatchState==MS_Live_First_Half)
  1553.     {
  1554.         if(cslTeam==TEAM_A)
  1555.         {
  1556.             return CS_TEAM_T;
  1557.         }
  1558.         else
  1559.         {
  1560.             return CS_TEAM_CT;
  1561.         }
  1562.     }
  1563.     else if(gMatchState==MS_Before_Second_Half || gMatchState==MS_Live_Second_Half)
  1564.     {
  1565.         if(cslTeam==TEAM_A)
  1566.         {
  1567.             return CS_TEAM_CT;
  1568.         }
  1569.         else
  1570.         {
  1571.             return CS_TEAM_T;
  1572.         }
  1573.     }
  1574.     else if(gMatchState==MS_Before_Overtime_First_Half || gMatchState==MS_Live_Overtime_First_Half)
  1575.     {
  1576.         if(cslTeam==TEAM_A)
  1577.         {
  1578.             return CS_TEAM_T;
  1579.         }
  1580.         else
  1581.         {
  1582.             return CS_TEAM_CT;
  1583.         }
  1584.     }
  1585.     else if(gMatchState==MS_Before_Overtime_Second_Half || gMatchState==MS_Live_Overtime_Second_Half)
  1586.     {
  1587.         if(cslTeam==TEAM_A)
  1588.         {
  1589.             return CS_TEAM_CT;
  1590.         }
  1591.         else
  1592.         {
  1593.             return CS_TEAM_T;
  1594.         }
  1595.     }
  1596.     else
  1597.     {
  1598.         return -1;
  1599.     }
  1600. }
  1601.  
  1602. CSTeamToCSL(csTeam)
  1603. {
  1604.     if(CSLToCSTeam(TEAM_A) == csTeam)
  1605.     {
  1606.         return TEAM_A;
  1607.     }
  1608.     else
  1609.     {
  1610.         return TEAM_B;
  1611.     }
  1612. }
  1613.  
  1614. TryGoCT(client)
  1615. {
  1616.     if(TeamsSetup())
  1617.     {
  1618.         new MyTeam = CSLTeam(client);
  1619.         if(MyTeam!=-1)
  1620.         {
  1621.             // Join the team we are on.
  1622.             if(CSLToCSTeam(MyTeam)!=CS_TEAM_CT)
  1623.             {
  1624.                 PrintCenterText(client, "\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 You are on Team %s, they are currently Terrorist.", ((MyTeam==TEAM_A)?"A":"B"));
  1625.             }
  1626.             if(GetClientTeam(client)!=CSLToCSTeam(MyTeam))
  1627.             {
  1628.                 CS_SwitchTeam(client, CSLToCSTeam(MyTeam));
  1629.             }
  1630.         }
  1631.         else
  1632.         {
  1633.             // They clearly want to be a Counter-Terrorist, which team is CT?
  1634.             new TCSL = CSTeamToCSL(CS_TEAM_T);
  1635.             new CTCSL = CSTeamToCSL(CS_TEAM_CT);
  1636.             new ATCount = TeamSizeActive(TCSL);
  1637.             new ACTCount = TeamSizeActive(CTCSL);
  1638.             new String:steamID[24];
  1639.             GetClientAuthString(client, steamID, 24);
  1640.             if(ACTCount <= ATCount)
  1641.             {
  1642.                 // Let them, and add them to the team.
  1643.                 AddSteamToTeam(steamID, CTCSL);
  1644.                 if(GetClientTeam(client)!=CS_TEAM_CT)
  1645.                 {
  1646.                     CS_SwitchTeam(client, CS_TEAM_CT);
  1647.                 }
  1648.             }
  1649.             else
  1650.             {
  1651.                 // They gotta go CT, add em and tell em the bad news :(
  1652.                 PrintCenterText(client, "CSL: Sorry, you have been forced to Team %s, the Terrorists.", ((TCSL==TEAM_A)?"A":"B"));
  1653.                 AddSteamToTeam(steamID, TCSL);
  1654.                 if(GetClientTeam(client)!=CS_TEAM_T)
  1655.                 {
  1656.                     CS_SwitchTeam(client, CS_TEAM_T);
  1657.                 }
  1658.             }
  1659.         }
  1660.     }
  1661. }
  1662.  
  1663. public Action:HookJoinTeam(client, const String:command[], argc)
  1664. {
  1665.     // Destined team
  1666.     new String:firstParam[16];
  1667.     GetCmdArg(1, firstParam, 16);
  1668.     StripQuotes(firstParam);
  1669.     new firstParamNumber = StringToInt(firstParam);
  1670.     if(!ValidClient(client) || IsFakeClient(client) || IsSourceTV(client))
  1671.     {
  1672.         return Plugin_Continue;        
  1673.     }
  1674.    
  1675.     if(firstParamNumber == CS_TEAM_SPEC)
  1676.     {
  1677.         // No.
  1678.         PrintCenterText(client, "CSL: You can't join spectator.");
  1679.         return Plugin_Handled;
  1680.     }
  1681.     else if(firstParamNumber == CS_TEAM_T)
  1682.     {
  1683.         if(TeamsSetup())
  1684.             TryGoT(client);
  1685.         else
  1686.         return Plugin_Continue;
  1687.     }
  1688.     else if(firstParamNumber == CS_TEAM_CT)
  1689.     {
  1690.         if(TeamsSetup())
  1691.             TryGoCT(client);
  1692.         else
  1693.         return Plugin_Continue;
  1694.     }
  1695.     else // Autojoin, our own version.
  1696.     {
  1697.         if(TeamsSetup())
  1698.             OurAutojoin(client);
  1699.         else
  1700.         return Plugin_Continue;
  1701.     }
  1702.     return Plugin_Handled;
  1703. }
  1704.  
  1705. public Action:HookBuy(client, const String:command[], argc)
  1706. {
  1707.     // Destined team
  1708.     new String:firstParam[16];
  1709.     GetCmdArg(1, firstParam, 16);
  1710.     StripQuotes(firstParam);
  1711.     if(ReadyUpState())
  1712.     {
  1713.         if(StrEqual(firstParam,"flashbang") || StrEqual(firstParam,"hegrenade") || StrEqual(firstParam,"smokegrenade"))
  1714.         {
  1715.             PrintCenterText(client, "CSL: No grenades during warm up.");
  1716.             return Plugin_Handled;
  1717.         }
  1718.     }
  1719.     return Plugin_Continue;
  1720. }
  1721.  
  1722. ClearMatch()
  1723. {
  1724.     ServerCommand("tv_stoprecord\n"); // Leet, MIRITE?!
  1725.     if(RestartTimers!=INVALID_HANDLE)
  1726.     {
  1727.         CloseHandle(RestartTimers);
  1728.     }
  1729.     RoundCounterOn = false;
  1730.     ChangeMatchState(MS_Pre_Setup);
  1731.     TeamAScore = 0;
  1732.     TeamBScore = 0;
  1733.     CurrentRound = 0;
  1734.     Format(MatchMap, 32, "");
  1735.     for(new x=0;x<MAX_ROUNDS;x++)
  1736.     {
  1737.         if(hMatchDamage[x]!=INVALID_HANDLE)
  1738.         {
  1739.             // How big is the array?
  1740.             new s = GetArraySize(hMatchDamage[x]);
  1741.             for(new y=0;y<s;y++)
  1742.             {
  1743.                 new Handle:aAt = GetArrayCell(hMatchDamage[x], y);
  1744.                 CloseHandle(aAt);
  1745.             }
  1746.             CloseHandle(hMatchDamage[x]);
  1747.             hMatchDamage[x] = INVALID_HANDLE;
  1748.         }
  1749.         if(hMatchKills[x]!=INVALID_HANDLE)
  1750.         {
  1751.             new s = GetArraySize(hMatchKills[x]);
  1752.             for(new y=0;y<s;y++)
  1753.             {
  1754.                 new Handle:aAt = GetArrayCell(hMatchKills[x], y);
  1755.                 CloseHandle(aAt);
  1756.             }
  1757.             CloseHandle(hMatchKills[x]);
  1758.             hMatchKills[x] = INVALID_HANDLE;
  1759.         }
  1760.     }
  1761.     Ruleset = Rules_PUG;
  1762.     CaptainMode = false;
  1763.     BunnyHopMode = false;
  1764.     for(new x=0;x<TEAM_COUNT;x++)
  1765.     {
  1766.         Format(TeamPlayers[x][0], 24, "");
  1767.         Format(TeamPlayers[x][1], 24, "");
  1768.         Format(TeamPlayers[x][2], 24, "");
  1769.         Format(TeamPlayers[x][3], 24, "");
  1770.         Format(TeamPlayers[x][4], 24, "");
  1771.     }
  1772. }
  1773.  
  1774. GetMapCount()
  1775. {
  1776.     new mapCount = 0;
  1777.     for(new x=0;x<MAX_MAPS;x++)
  1778.     {
  1779.         if(!StrEqual(MapNames[x],""))
  1780.         {
  1781.             mapCount++;
  1782.         }
  1783.     }
  1784.     return mapCount;
  1785. }
  1786.  
  1787. AddToOurMaps(const String:mapName[])
  1788. {
  1789.     for(new x=0;x<MAX_MAPS;x++)
  1790.     {
  1791.         if(StrEqual(MapNames[x],""))
  1792.         {
  1793.             Format(MapNames[x], 32, mapName);
  1794.             break;
  1795.         }
  1796.     }
  1797. }
  1798.  
  1799. LoadMapsDir()
  1800. {
  1801.     // Build path and look for .bsp files.
  1802.     new String:mapsDir[1024];
  1803.     BuildPath(Path_SM, mapsDir, 1024, "../../maps/");
  1804.     new String:path[1024];
  1805.     new Handle:dir = OpenDirectory(mapsDir);
  1806.     new FileType:type;
  1807.     while(ReadDirEntry(dir, path, sizeof(path), type))
  1808.     {
  1809.         if(type == FileType_File && StrContains(path, ".bsp") != -1)
  1810.         {
  1811.             // How many dots in the path?
  1812.             new len = strlen(path);
  1813.             new periods = 0;
  1814.             for(new x=0;x<len;x++)
  1815.             {
  1816.                 if(path[x]=='.')
  1817.                 {
  1818.                     periods++;
  1819.                 }
  1820.             }
  1821.             if(periods==1)
  1822.             {
  1823.                 ReplaceString(path, 1024, ".bsp", "", false);
  1824.                 AddToOurMaps(path);
  1825.             }
  1826.         }
  1827.     }
  1828.     CloseHandle(dir);
  1829. }
  1830.  
  1831. GoPostgame(winning_team, bool:forfeit = false)
  1832. {
  1833.     RoundCounterOn = false;
  1834.     // Send stats?
  1835.     ChangeMatchState(MS_Post_Match);
  1836.    
  1837.     // TODO
  1838.     new bool:tie=(winning_team==-1)?true:false;
  1839.     if(tie)
  1840.     {
  1841.         forfeit = false; // Just incase?
  1842.     }
  1843.    
  1844.     // Show everyone their stats page.
  1845.    
  1846.     ClearMatch();
  1847. }
  1848.  
  1849. MatchWinForfeit(winning_team)
  1850. {
  1851.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 %s wins due to forfeit", (winning_team==TEAM_A)?"Team A":"Team B");
  1852.     GoPostgame(winning_team, true);
  1853. }
  1854.  
  1855. MatchWin(winning_team)
  1856. {
  1857.     // Was the winning_team T or CT?
  1858.     new WinningScore = (winning_team==TEAM_A)?TeamAScore:TeamBScore;
  1859.     new LosingScore = (winning_team==TEAM_A)?TeamBScore:TeamAScore;
  1860.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Match is over, %s wins the match %d - %d",(winning_team==TEAM_A)?"Team A":"Team B", WinningScore, LosingScore);
  1861.    
  1862.     GoPostgame(winning_team);
  1863. }
  1864.  
  1865. MatchWinOT(winning_team)
  1866. {
  1867.     // Was the winning_team T or CT?
  1868.     new WinningScore = (winning_team==TEAM_A)?TeamAScore:TeamBScore;
  1869.     new LosingScore = (winning_team==TEAM_A)?TeamBScore:TeamAScore;
  1870.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Overtime is over, %s wins the match %d - %d",(winning_team==TEAM_A)?"Team A":"Team B", WinningScore, LosingScore);
  1871.    
  1872.     GoPostgame(winning_team);
  1873. }
  1874.  
  1875. MatchTieOT()
  1876. {
  1877.     PrintToChatAll("\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Match ends in a tie, %d - %d", TeamAScore, TeamBScore);
  1878.     GoPostgame(-1);
  1879. }
  1880.  
  1881. DeleteBomb()
  1882. {
  1883.     for (new i = 1; i <= MaxClients; i++)
  1884.     {
  1885.         if (IsClientInGame(i) && IsPlayerAlive(i))
  1886.         {
  1887.             new iWeapon = GetPlayerWeaponSlot(i, 4);
  1888.            
  1889.             if (iWeapon != -1 && IsValidEdict(iWeapon))
  1890.             {
  1891.                 decl String:szClassName[64];
  1892.                 GetEdictClassname(iWeapon, szClassName, sizeof(szClassName));
  1893.                
  1894.                 if (StrEqual(szClassName, "weapon_c4"))
  1895.                 {
  1896.                     RemovePlayerItem(i, iWeapon);
  1897.                     RemoveEdict(iWeapon);
  1898.                 }
  1899.             }
  1900.         }
  1901.     }
  1902.    
  1903. }
  1904.  
  1905. enum ConnAction
  1906. {
  1907.     ConnAction_Connect_NonMember = 0,
  1908.     ConnAction_Connect_Member,
  1909.     ConnAction_Disconnect,
  1910. };
  1911.  
  1912. bool:MatchLive()
  1913. {
  1914.     if(gMatchState == MS_Live_First_Half || gMatchState == MS_Live_Second_Half || gMatchState == MS_Live_Overtime_First_Half || gMatchState == MS_Live_Overtime_Second_Half)
  1915.     {
  1916.         return true;
  1917.     }
  1918.     return false;
  1919. }
  1920.  
  1921. public T_NoCallback(Handle:owner,Handle:hndl,const String:error[],any:data)
  1922. {
  1923.     // pst... it's quiet... too quiet? maybe log errors?
  1924. }
  1925.  
  1926. public StatsCallback(Handle:owner,Handle:hndl,const String:error[],any:data)
  1927. {
  1928.     new client=GetClientOfUserId(data);
  1929.     if(!ValidClient(client))
  1930.     {
  1931.         return;
  1932.     }
  1933.     if(hndl!=INVALID_HANDLE)
  1934.     {
  1935.         SQL_Rewind(hndl);
  1936.         if(!SQL_FetchRow(hndl))
  1937.         {
  1938.             PrintToChat(client, "\x04[\x070000FFAuto \x07FF0000Mix\x04]\x01 Sorry, username doesn't exist.");
  1939.         }
  1940.         else
  1941.         {
  1942.             new steamid;
  1943.             SQL_FieldNameToNum(hndl, "steamid", steamid);
  1944.             new String:steam[24];
  1945.             SQL_FetchString(hndl, steamid, steam, 24);
  1946.             new String:fullURL[192];
  1947.             Format(fullURL, 192, "http://thecsleague.com/stats.php?steam=%s", steam);
  1948.             ShowMOTDPanel(client, "Stats", fullURL, MOTDPANEL_TYPE_URL);
  1949.         }
  1950.     }
  1951. }
  1952.  
  1953. StartAuth(client)
  1954. {
  1955.     if(!ValidClient(client) || IsSourceTV(client))
  1956.     {
  1957.         return;        
  1958.     }
  1959.     if(!AllowBots() && IsFakeClient(client))
  1960.     {
  1961.         Kick(client,"No bots!"); // No bots stupid.    
  1962.         return;
  1963.     }
  1964.     notReadyTime[client] = GetTime();
  1965.     // Make sure they are a customer.
  1966.     decl String:steamID[24];
  1967.     GetClientAuthString(client, steamID, 24);
  1968.     if(BadSteamId(steamID))
  1969.     {
  1970.         Kick(client,"Your STEAMID isn't valid.");
  1971.         return;
  1972.     }
  1973.    
  1974.     notReadyTime[client] = GetTime();
  1975.     // Is the match already live? If it is put this person on a team etc...
  1976.     // TODO: This will need to be changed once we have a captain mode.
  1977.     if(TeamsSetup())
  1978.     {
  1979.         OurAutojoin(client);
  1980.     }  
  1981. }
  1982.  
  1983. bool:IsSourceTV(client)
  1984. {
  1985.     if(!ValidClient(client))
  1986.         return false;
  1987.     decl String:plName[64];
  1988.     GetClientName(client, plName, 64);
  1989.     if(IsFakeClient(client) && ( StrEqual(plName,"SourceTV") || StrEqual(plName,"CSL SourceTV") ))
  1990.     {
  1991.         return true;
  1992.     }
  1993.     return false;
  1994. }
  1995.  
  1996. public OnClientPutInServer(client)
  1997. {
  1998.     ClientDefaults(client);
  1999.     if(IsSourceTV(client))
  2000.         return; // Don't auth the SourceTV dude! :P
  2001.     new cCount = GetClientCount();
  2002.     if(GetConVarInt(hTVEnabled)==1)
  2003.         cCount -= 1;
  2004.     if(cCount>GetConVarInt(hMaxPlayers))
  2005.     {
  2006.         Kick(client, "Sorry, this match is full");
  2007.         return;
  2008.     }
  2009.     StartAuth(client);
  2010. }
  2011.  
  2012. ClientOfSteamId(const String:steamID[])
  2013. {
  2014.     for(new x=1;x<=MAXPLAYERS;x++)
  2015.     {
  2016.         if(ValidClient(x) && !IsSourceTV(x))
  2017.         {
  2018.             new String:mySteam[24];
  2019.             GetClientAuthString(x, mySteam, 24);
  2020.             if(StrEqual(steamID, mySteam))
  2021.             {
  2022.                 return x;
  2023.             }
  2024.         }
  2025.     }
  2026.     return 0;
  2027. }
  2028.  
  2029. TeamOfSteamId(const String:steamID[])
  2030. {
  2031.     // Return of -1 indicates none yet.
  2032.     for(new x=0;x<TEAM_COUNT;x++)
  2033.     {
  2034.         for(new y=0;y<5;y++)
  2035.         {
  2036.             if(StrEqual(steamID, TeamPlayers[x][y]))
  2037.             {
  2038.                 return x;
  2039.             }
  2040.         }
  2041.     }
  2042.     return -1;
  2043. }
  2044.  
  2045. public OnClientDisconnect(client)
  2046. {
  2047.     bDisconnecting[client] = true;
  2048.    
  2049.     new bool:specialCase = false;
  2050.    
  2051.     if(IsFakeClient(client) && !IsSourceTV(client)) {
  2052.         specialCase = true;
  2053.     }
  2054.    
  2055.     if(IsSourceTV(client))
  2056.         return;
  2057.    
  2058.     if(MatchLive())
  2059.     {
  2060.         new String:steamID[24];
  2061.         GetClientAuthString(client, steamID, 24);
  2062.         new TeamAB = TeamOfSteamId(steamID);
  2063.         if(TeamAB==-1)
  2064.         {
  2065.             return; // They we're on a team yet.
  2066.         }
  2067.         // Is anyone else on their team still there? If not, the match has been forfeited.
  2068.         new bool:AnyOnline = false;
  2069.         for(new x=0;x<5;x++)
  2070.         {
  2071.             new cOfSteam = ClientOfSteamId(TeamPlayers[TeamAB][x]);
  2072.             if(ValidClient(cOfSteam) && client!=cOfSteam)
  2073.             {
  2074.                 AnyOnline = true;
  2075.             }    
  2076.         }
  2077.         if(!AnyOnline && !specialCase)
  2078.         {
  2079.             MatchWinForfeit( (TeamAB==TEAM_A) ? TEAM_B : TEAM_A );
  2080.         }
  2081.     }
  2082.     /*else
  2083.     {
  2084.     // TODO: If we are picking teams?
  2085.     }*/
  2086. }
  2087.  
  2088. public OnMapStart()
  2089. {
  2090.     ServerCommand("mp_do_warmup_period 0");
  2091.     ServerCommand("mp_maxrounds 0");
  2092.     ServerCommand("bot_quota 0");
  2093.     ServerCommand("bot_kick");
  2094. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement