Advertisement
Guest User

tf2comp

a guest
Dec 17th, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 24.73 KB | None | 0 0
  1.     #pragma semicolon 1
  2.     #include <sourcemod>
  3.     #include <tf2>
  4.     #include <colors>
  5.    
  6.     #define RED 0
  7.     #define BLU 1
  8.     #define TEAM_OFFSET 2
  9.    
  10.     //Logging-related variables
  11.     new bool:isPaused;
  12.     new String:sLogFileDir[64];
  13.     new String:sLogFileName[64];
  14.  
  15.     //Demo-related variables
  16.     new bool:teamReadyState[2] = { false, false };
  17.     new bool:recordOnRestart = false;
  18.     new bool:recording = false;
  19.     new String:sDemoFileDir[64];
  20.     new String:sDemoFileName[64];
  21.    
  22.     //Non demo/log related variables
  23.     new redCapTotal = 0;
  24.     new blueCapTotal  = 0;
  25.     new Handle:g_hPassword = INVALID_HANDLE;
  26.  
  27.     public Plugin:myinfo =
  28.     {
  29.         name = "tf2comp",
  30.         author = "Krysk",
  31.         description = "Automates scrimming!",
  32.         version = "0.1",
  33.         url = "http://cohencraven.com/tf2comp"
  34.     };
  35.    
  36.     //Sourcemod stock commands
  37.     public OnPluginStart()
  38.     {
  39.         // Logging Game Events
  40.         HookEvent("item_pickup", Event_ItemPickup);
  41.         HookEvent("player_hurt", Event_PlayerHurt);
  42.         HookEvent("player_healed", Event_PlayerHealed);
  43.         HookEvent("player_spawn", Event_PlayerSpawned);
  44.         HookEvent("player_death", Event_PlayerDeath);
  45.         HookEvent("medic_death", Event_MedicDeath);
  46.         HookEvent("player_builtobject", Event_BuiltObject);
  47.         HookEvent("teamplay_point_captured", Event_PointCaptured);
  48.         HookEvent("player_chargedeployed", Event_ChargeDeployed);
  49.         HookEvent("teamplay_round_win", Event_RoundWon);
  50.         AddCommandListener(Listener_Pause, "pause");
  51.        
  52.         // Demo events
  53.         HookEvent("tournament_stateupdate", TeamStateEvent);
  54.         HookEvent("teamplay_restart_round", GameRestartEvent);
  55.         HookEvent("teamplay_game_over", GameOverEvent);
  56.         HookEvent("tf_game_over", GameOverEvent);
  57.         RegServerCmd("mp_tournament_restart", TournamentRestartHook);
  58.        
  59.         // Chat Listeners
  60.         AddCommandListener(Event_Player_Say, "say");
  61.         AddCommandListener(Event_Player_Say, "say2");
  62.         AddCommandListener(Event_Player_Say_Team, "say_team");
  63.        
  64.         //Admin Commands
  65.         RegAdminCmd("pass", Command_ChangePassword, ADMFLAG_GENERIC);
  66.        
  67.         //Console Commands
  68.         RegConsoleCmd("getpass", Command_GetPassword, "Returns the current server password");
  69.         RegConsoleCmd("getstring", Command_GetString, "Returns the connect string to the client");
  70.     }
  71.    
  72.     public OnMapStart()
  73.     {
  74.         // Demos
  75.         ResetVariables();
  76.         // Check every 30secs if there are still players on the server
  77.         CreateTimer(30.0, CheckPlayers, 0, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  78.        
  79.     }
  80.    
  81.     // LOGGING EVENTS  
  82.     /*
  83.      * Listener_Pause: Called whenever the game is paused
  84.      * client: the clientID that issued the command
  85.      * command: the command that was triggered
  86.      * argc: the arguments of the command
  87.      */
  88.     public Action:Listener_Pause(client, const String:command[], argc)
  89.     {
  90.         isPaused = !isPaused;
  91.         if (isPaused)
  92.             Log("World triggered \"Game_Paused\"");
  93.         else
  94.             Log("World triggered \"Game_Unpaused\"");
  95.         return Plugin_Continue;
  96.     }
  97.  
  98.     /*
  99.      * Event_ItemPickup: Called whenever an item is picked up
  100.      * event: item_pickup
  101.      * name: the name of the event
  102.      * dontBroadcast: broadcast ehe event to the server
  103.      */
  104.     public Event_ItemPickup(Handle:event, const String:name[], bool:dontBroadcast)
  105.     {
  106.         decl String:playerName[32];
  107.         decl String:playerSteamId[64];
  108.         decl String:playerTeam[64];
  109.         decl String:item[64];
  110.         decl String:message[256];
  111.  
  112.         new playerId = GetEventInt(event, "userid");
  113.         new player = GetClientOfUserId(playerId);
  114.         GetClientAuthString(player, playerSteamId, sizeof(playerSteamId));
  115.         GetClientName(player, playerName, sizeof(playerName));
  116.         playerTeam = GetPlayerTeam(GetClientTeam(player));
  117.         GetEventString(event, "item", item, sizeof(item));
  118.        
  119.         PrintToChatAll("\"%s<%d><%s><%s>\" picked up item \"%s\"", playerName, playerId, playerSteamId, playerTeam, item);
  120.         Format(message, sizeof(message), "\"%s<%d><%s><%s>\" picked up item \"%s\"", playerName, playerId, playerSteamId, playerTeam, item);
  121.         Log(message);
  122.     }
  123.  
  124.     /*
  125.      * Event_PlayerHealed: Called whenever a player is healed.
  126.      * event: player_healed
  127.      * name: the name of the event
  128.      * dontBroadcast: broadcast the event to the server
  129.      */
  130.     public Event_PlayerHealed(Handle:event, const String:name[], bool:dontBroadcast)
  131.     {
  132.         decl String:patientName[32];
  133.         decl String:healerName[32];
  134.         decl String:patientSteamId[64];
  135.         decl String:healerSteamId[64];
  136.         decl String:patientTeam[64];
  137.         decl String:healerTeam[64];
  138.         decl String:message[256];
  139.        
  140.         new patientId = GetEventInt(event, "patient");
  141.         new healerId = GetEventInt(event, "healer");
  142.         new patient = GetClientOfUserId(patientId);
  143.         new healer = GetClientOfUserId(healerId);
  144.         new amount = GetEventInt(event, "amount");
  145.  
  146.         GetClientAuthString(patient, patientSteamId, sizeof(patientSteamId));
  147.         GetClientName(patient, patientName, sizeof(patientName));
  148.         GetClientAuthString(healer, healerSteamId, sizeof(healerSteamId));
  149.         GetClientName(healer, healerName, sizeof(healerName));
  150.  
  151.         patientTeam = GetPlayerTeam(GetClientTeam(patient));
  152.         healerTeam = GetPlayerTeam(GetClientTeam(healer));
  153.         PrintToChatAll("\"%s<%d><%s><%s>\" triggered \"healed\" against \"%s<%d><%s><%s>\" (healing \"%d\")", healerName, healerId, healerSteamId, healerTeam, patientName, patientId, patientSteamId, patientTeam, amount);
  154.         Format(message, sizeof(message), "\"%s<%d><%s><%s>\" triggered \"healed\" against \"%s<%d><%s><%s>\" (healing \"%d\")", healerName, healerId, healerSteamId, healerTeam, patientName, patientId, patientSteamId, patientTeam, amount);
  155.         Log(message);
  156.     }
  157.    
  158.     /*
  159.      * Event_PlayerHurt: Called whenever a player is hurt
  160.      * event: player_hurt
  161.      * name: the name of the event
  162.      * dontBroadcast: broadcast the event to the server
  163.      */
  164.     public Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
  165.     {
  166.         decl String:clientname[32];
  167.         decl String:steamid[64];
  168.         decl String:team[64];
  169.         decl String:message[256];
  170.        
  171.         new userid = GetClientOfUserId(GetEventInt(event, "userid"));
  172.         new attackerid = GetEventInt(event, "attacker");
  173.         new attacker = GetClientOfUserId(attackerid);
  174.         new damage = GetEventInt(event, "damageamount");
  175.         if(userid != attacker && attacker != 0)
  176.         {
  177.             GetClientAuthString(attacker, steamid, sizeof(steamid));
  178.             GetClientName(attacker, clientname, sizeof(clientname));
  179.             team = GetPlayerTeam(GetClientTeam(attacker));
  180.             PrintToChatAll("\"%s<%d><%s><%s>\" triggered \"damage\" (damage \"%d\")", clientname, attackerid, steamid, team, damage);
  181.             Format(message, sizeof(message), "\"%s<%d><%s><%s>\" triggered \"damage\" (damage \"%d\")", clientname, attackerid, steamid, team, damage);
  182.         }
  183.     }
  184.  
  185.     /*
  186.      * Event_PlayerSpawned: Called whenever a player spawns
  187.      * event: player_spawn
  188.      * name: the name of the event
  189.      * dontBroadcast: broadcast the event to the server
  190.      */
  191.     public Event_PlayerSpawned(Handle:event, const String:name[], bool:dontBroadcast)
  192.     {
  193.         decl String:clientname[32];
  194.         decl String:steamid[64];
  195.         decl String:team[64];
  196.         decl String:message[256];
  197.         new String:classes[10][64] = {"undefined", "scout", "sniper", "soldier", "demoman", "medic", "heavyweapons", "pyro", "spy", "engineer" };
  198.         new user = GetClientOfUserId(GetEventInt(event, "userid"));
  199.         new clss = GetEventInt(event, "class");
  200.         GetClientAuthString(user, steamid, sizeof(steamid));
  201.         GetClientName(user, clientname, sizeof(clientname));
  202.         team = GetPlayerTeam(GetClientTeam(user));
  203.         PrintToChatAll("\"%s<%d><%s><%s>\" spawned as \"%s\"", clientname, user, steamid, team, classes[clss]);
  204.         Format(message, sizeof(message), "\"%s<%d><%s><%s>\" spawned as \"%s\"", clientname, user, steamid, team, classes[clss]);
  205.     }
  206.    
  207.     /*
  208.      * Event_PlayerDeath: Called whenever a player dies
  209.      * event: player_death
  210.      * name: the name of the event
  211.      * dontBroadcast: broadcast the event to the server
  212.      */
  213.     public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
  214.     {
  215.         decl String:attackername[32];
  216.         decl String:victimname[32];
  217.         decl String:weapon[32];
  218.         decl String:attackerid[64];
  219.         decl String:victimid[64];
  220.         decl String:attackerteam[64];
  221.         decl String:victimteam[64];
  222.         decl String:message[256];
  223.        
  224.         new victim = GetClientOfUserId(GetEventInt(event, "userid"));
  225.         new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
  226.         GetEventString(event, "weapon", weapon, sizeof(weapon));
  227.         GetClientAuthString(attacker, attackerid, sizeof(attackerid));
  228.         GetClientAuthString(victim, victimid, sizeof(victimid));
  229.         GetClientName(attacker, attackername, sizeof(attackername));
  230.         GetClientName(victim, victimname, sizeof(victimname));
  231.         attackerteam = GetPlayerTeam(GetClientTeam(attacker));
  232.         victimteam = GetPlayerTeam(GetClientTeam(victim));
  233.        
  234.         PrintToChatAll("\"%s<%d><%s><%s>\"  \"killed\" \"%s<%d><%s><%s>\" with weapon (\"%s\")", attackername, attacker, attackerid, attackerteam, victimname, victim, victimid, victimteam, weapon);
  235.         Format(message, sizeof(message), "\"%s<%d><%s><%s>\"  \"killed\" \"%s<%d><%s><%s>\" with weapon (\"%s\")", attackername, attacker, attackerid, attackerteam, victimname, victim, victimid, victimteam, weapon);
  236.         Log(message);
  237.        
  238.         new assister = GetEventInt(event, "assister");
  239.         PrintToChatAll("assister id: %s", assister);
  240.        
  241.         if (assister != -1)
  242.         {
  243.             decl String:assistername[32];
  244.             decl String:assisterid[64];
  245.             decl String:assisterteam[64];
  246.             decl String:assMessage[256];
  247.            
  248.             GetClientAuthString(assister, assisterid, sizeof(assisterid));
  249.             GetClientName(assister, assistername, sizeof(assistername));
  250.             assisterteam = GetPlayerTeam(GetClientTeam(assister));
  251.             Format(assMessage, sizeof(assMessage), "\"%s<%d><%s><%s>\" triggered \"kill_assist\" against \"%s<%d><%s><%s>\"", assistername, assister, assisterid, assisterteam, victimname, victim, victimid, victimteam);
  252.         }
  253.     }
  254.    
  255.     /*
  256.      * Event_ChargeDeployed: Called whenever a medic uber charges
  257.      * event: player_chargedeployed
  258.      * name: name of thet event
  259.      * dontBroadcast: broadcast the event to the server
  260.      */
  261.     public Event_ChargeDeployed(Handle:event, const String:name[], bool:dontBroadcast)
  262.     {
  263.         decl String:medicname[32];
  264.         decl String:medicid[64];
  265.         decl String:medicteam[64];
  266.         decl String:message[256];
  267.         decl String:targetname[32];
  268.         decl String:targetid[64];
  269.         decl String:targetteam[64];
  270.  
  271.         new medic = GetEventInt(event, "userid");
  272.         new target = GetEventInt(event, "targetid");
  273.        
  274.         GetClientAuthString(medic, medicid, sizeof(medicid));
  275.         GetClientName(medic, medicname, sizeof(medicname));
  276.         medicteam = GetPlayerTeam(GetClientTeam(medic));
  277.         GetClientAuthString(target, targetid, sizeof(targetid));
  278.         GetClientName(target, targetname, sizeof(targetname));
  279.         targetteam = GetPlayerTeam(GetClientTeam(target));
  280.        
  281.         Format(message, sizeof(message), "\"%s<%d><%s><%s>\"  triggered \"charge_deployed\" against \"%s<%d><%s><%s>\"", medicname, medic, medicid, medicteam, targetname, target, targetid, targetteam);
  282.     }
  283.    
  284.     /*
  285.      * Event_PointCaptured: Called whenever a point is captured
  286.      * event: teamplay_point_captured
  287.      * name: the name of the event
  288.      * dontBroadcast: broadcast the event to the server
  289.      */
  290.     public Event_PointCaptured(Handle:event, const String:name[], bool:dontBroadcast)
  291.     {
  292.         decl String:pointname[32];
  293.         decl String:cappers[32];
  294.         decl String:capteam[64];
  295.         decl String:message[256];
  296.        
  297.         GetEventString(event, "cpname", pointname, sizeof(pointname));
  298.         GetEventString(event, "cappers", cappers, sizeof(cappers));
  299.         new team = GetEventInt(event, "team");
  300.         capteam = GetPlayerTeam(team);
  301.        
  302.         Format(message, sizeof(message), "%s captured point: %s", capteam, pointname);
  303.         PrintToChatAll(message);
  304.         PrintToChatAll(cappers);
  305.     }
  306.    
  307.     /*
  308.      * Event_MedicDeath: Called whenever a medic dies
  309.      * event: medic_death
  310.      * name: the name of the event
  311.      * dontBroadcast: broadcast the event to the server
  312.      */
  313.     public Event_MedicDeath(Handle:event, const String:name[], bool:dontBroadcast)
  314.     {
  315.         decl String:attackername[32];
  316.         decl String:victimname[32];
  317.         decl String:attackerid[64];
  318.         decl String:victimid[64];
  319.         decl String:attackerteam[64];
  320.         decl String:victimteam[64];
  321.         decl String:haduber[4];
  322.         decl String:message[256];
  323.        
  324.         new bool:uber = GetEventBool(event, "charged");    
  325.         new victim = GetClientOfUserId(GetEventInt(event, "userid"));
  326.         new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
  327.         new healingtotal = GetEventInt(event, "healing");
  328.         GetClientAuthString(attacker, attackerid, sizeof(attackerid));
  329.         GetClientAuthString(victim, victimid, sizeof(victimid));
  330.         GetClientName(attacker, attackername, sizeof(attackername));
  331.         GetClientName(victim, victimname, sizeof(victimname));
  332.         attackerteam = GetPlayerTeam(GetClientTeam(attacker));
  333.         victimteam = GetPlayerTeam(GetClientTeam(victim));
  334.         haduber = (uber == true) ? "1" : "0";
  335.        
  336.         Format(message, sizeof(message), "\"%s<%d><%s><%s>\"  triggered \"medic_death\" against \"%s<%d><%s><%s>\" (healing \"%d\") (ubercharge \"%s\")", attackername, attacker, attackerid,  attackerteam, victimname, victim, victimid, victimteam, healingtotal, haduber);
  337.         Log(message);
  338.     }
  339.    
  340.     /*
  341.      * Log: Logs the message to the current log file
  342.      * message: the message to log
  343.      */
  344.     public Log(String:message[])
  345.     {
  346.         // Logging
  347.         new String:date[16];
  348.         FormatTime(date, sizeof(date), "%Y-%m-%d");
  349.         Format(sLogFileDir, sizeof(sLogFileDir), "logs/%s/", date);
  350.         Format(sDemoFileDir, sizeof(sDemoFileDir), "demos/%s/", date);
  351.         if (!DirExists(sLogFileDir))
  352.         {
  353.             CreateDirectory(sLogFileDir, 511);
  354.         }
  355.         if (!DirExists(sDemoFileDir))
  356.         {
  357.             CreateDirectory(sDemoFileDir, 511);
  358.         }
  359.         if (recording)
  360.         {
  361.             LogToGame(message);
  362.         }
  363.         PrintToChatAll(message);
  364.     }
  365.    
  366.     /*
  367.      * Event_Player_Say: Called whenever a player writes a message to team
  368.      * client: the client id of who trigered the command
  369.      * command: the command that was triggered
  370.      * argc: the argument length
  371.      */
  372.     public Action:Event_Player_Say(client, const String:command[], argc)
  373.     {
  374.         decl String:logmessage[256];
  375.         decl String:message[256];
  376.         decl String:clientname[64];
  377.         decl String:clientid[32];
  378.         decl string:clientteam[64];
  379.        
  380.         GetCmdArg(1, message, sizeof(message));
  381.         GetClientAuthString(client, clientid, sizeof(clientid));
  382.         GetClientName(client, clientname, sizeof(clientname));
  383.         clientteam = GetPlayerTeam(GetClientTeam(client));
  384.        
  385.         Format(logmessage, sizeof(logmessage), "\"%s<%d><%s><%s>\"  triggered \"say\" (message \"%s\")", clientname, client, clientid, clientteam, message);
  386.         Log(logmessage);
  387.     }
  388.    
  389.     /*
  390.      * Event_Player_Say_Team: Called whenever a player writes a message to team
  391.      * client: the client id of who trigered the command
  392.      * command: the command that was triggered
  393.      * argc: the argument length
  394.      */
  395.     public Action:Event_Player_Say_Team(client, const String:command[], argc)
  396.     {
  397.         decl String:logmessage[256];
  398.         decl String:message[256];
  399.         decl String:clientname[64];
  400.         decl String:clientid[32];
  401.         decl string:clientteam[64];
  402.        
  403.         GetCmdArg(1, message, sizeof(message));
  404.         GetClientAuthString(client, clientid, sizeof(clientid));
  405.         GetClientName(client, clientname, sizeof(clientname));
  406.         clientteam = GetPlayerTeam(GetClientTeam(client));
  407.        
  408.         Format(logmessage, sizeof(logmessage), "\"%s<%d><%s><%s>\"  triggered \"say_team\" (message \"%s\")", clientname, client, clientid, clientteam, message);
  409.         Log(logmessage);
  410.     }
  411.    
  412.     /*
  413.      * Event_BuiltObject: Called whenever an object is built
  414.      * event: player_builtobject
  415.      * name: the name of the event
  416.      * dontBroadcast: broadcast the event to the server
  417.      */
  418.     public Event_BuiltObject(Handle:event, const String:name[], bool:dontBroadcast)
  419.     {
  420.         decl String:buildername[64];
  421.         decl String:builderid[32];
  422.         decl String:builderteam[64];
  423.         decl String:objectname[64];
  424.         decl String:message[256];
  425.    
  426.         new userid = GetEventInt(event, "userid");
  427.         new objectid = GetEventInt(event, "object");
  428.         GetClientAuthString(userid, builderid, sizeof(builderid));
  429.         GetClientName(userid, buildername, sizeof(buildername));
  430.         builderteam = GetPlayerTeam(GetClientTeam(userid));
  431.        
  432.         switch(objectid)
  433.         {
  434.             case 0:
  435.             {
  436.                 objectname = "obj_dispenser";
  437.             }
  438.             case 1:
  439.             {
  440.                 objectname = "obj_teleporter";
  441.             }
  442.             case 2:
  443.             {
  444.                 objectname = "obj_sentry";
  445.             }
  446.             default:
  447.             {          
  448.                 objectname = "obj_null";
  449.             }
  450.         }
  451.         PrintToChatAll("\"%s<%d><%s><%s>\"  triggered \"built_object\" (object \" %s \")", buildername, userid, builderid, builderteam, objectname);
  452.         Format(message, sizeof(message), "\"%s<%d><%s><%s>\"  triggered \"built_object\" (object \" %s \")", buildername, userid, builderid, builderteam, objectname);
  453.         Log(message);
  454.     }
  455.  
  456.     String:GetPlayerTeam(teamIndex)
  457.     {
  458.         decl String:team[64];
  459.        
  460.         switch (teamIndex)
  461.         {
  462.             case 2:
  463.                 team = "Red";
  464.             case 3:
  465.                 team = "Blue";
  466.             default:
  467.                 team = "undefined";
  468.         }
  469.         return team;
  470.     }
  471.  
  472.     //DEMO EVENTS (re: MatchRecorder)
  473.     /*
  474.      * TeamStateEvent: called whenever a change is made to the team (name/ready)
  475.      * event: tournament_stateupdate
  476.      * name: name of the event
  477.      * dontBroadcast: whether or not to broadcast to the server
  478.      */
  479.     public TeamStateEvent(Handle:event, const String:name[], bool:dontBroadcast)
  480.     {
  481.         new team = GetClientTeam(GetEventInt(event, "userid")) - TEAM_OFFSET;
  482.         new bool:nameChange = GetEventBool(event, "namechange");
  483.         new bool:readyState = GetEventBool(event, "readystate");
  484.  
  485.         if (!nameChange)
  486.         {
  487.             teamReadyState[team] = readyState;
  488.    
  489.             // If both teams are ready wait for round restart to start recording
  490.             if (teamReadyState[RED] && teamReadyState[BLU])
  491.             {
  492.                 recordOnRestart = true;
  493.             }
  494.             else
  495.             {
  496.                 recordOnRestart = false;
  497.             }
  498.         }
  499.     }
  500.  
  501.     /*
  502.      * GameRestartEvent: Called whenever the tournament is being reset
  503.      * event: teamplay_restart_round
  504.      * name: name of the event
  505.      * dontBroadcast: broadcast to the server
  506.      */
  507.     public GameRestartEvent(Handle:event, const String:name[], bool:dontBroadcast)
  508.     {
  509.         // Start recording only if both team are in ready state
  510.         if (recordOnRestart)
  511.         {
  512.             StartRecording();
  513.             recordOnRestart = false;
  514.             teamReadyState[RED] = false;
  515.             teamReadyState[BLU] = false;
  516.         }
  517.     }  
  518.  
  519.     /*
  520.      * GameOverEvent: called when a match has been won
  521.      * event: teamplay_game_over and tf_game_over
  522.      * name: name of the event
  523.      * dontBroadcast: broadcast to the server
  524.      */
  525.     public GameOverEvent(Handle:event, const String:name[], bool:dontBroadcast)
  526.     {
  527.         StopRecording();
  528.        
  529.         new String:sRedMessage[32];
  530.         new String:sMapMessage[64];
  531.         new String:sBlueMessage[32];
  532.         new String:sRedCaps[32];
  533.         new String:sBlueCaps[32];
  534.         new String:sRedTeamName[8];
  535.         new String:sBlueTeamName[8];
  536.         new String:sCurrentMap[64];
  537.        
  538.         GetConVarString(FindConVar("mp_tournament_redteamname"), sRedTeamName, sizeof(sRedTeamName));
  539.         GetConVarString(FindConVar("mp_tournament_blueteamname"), sBlueTeamName, sizeof(sBlueTeamName));
  540.         GetCurrentMap(sCurrentMap, sizeof(sCurrentMap));
  541.        
  542.         Format(sRedMessage, sizeof(sRedMessage), "Red team name: %s", sRedTeamName);
  543.         Format(sBlueMessage, sizeof(sBlueMessage), "Blue team name: %s", sBlueTeamName);
  544.         Format(sRedCaps, sizeof(sRedCaps), "Red caps: %i", redCapTotal);
  545.         Format(sBlueCaps, sizeof(sBlueCaps), "Blue caps: %i", blueCapTotal);
  546.         Format(sMapMessage, sizeof(sMapMessage), "Current map: %s", sCurrentMap);
  547.        
  548.         Log(sRedMessage);
  549.         Log(sBlueMessage);
  550.         Log(sMapMessage);
  551.         Log(sRedCaps);
  552.         Log(sBlueCaps);
  553.        
  554.         redCapTotal = 0;
  555.         blueCapTotal = 0;
  556.     }
  557.  
  558.     public Action:TournamentRestartHook(args)
  559.     {
  560.         if (recording)
  561.         {
  562.             StopRecording();
  563.         }
  564.         return Plugin_Continue;
  565.     }
  566.    
  567.     ResetVariables()
  568.     {
  569.         teamReadyState[RED] = false;
  570.         teamReadyState[BLU] = false;
  571.         recordOnRestart = false;
  572.         recording = false;
  573.     }
  574.  
  575.     StartRecording()
  576.     {
  577.         if (recording)
  578.         {
  579.             PrintToChatAll("Already recording");
  580.             return;
  581.         }
  582.  
  583.         // Format the demo filename
  584.         decl String:timestamp[16];
  585.         decl String:map[32];
  586.         decl String:command[128];
  587.         decl String:blueTeamName[32];
  588.         decl String:redTeamName[32];
  589.         decl String:recordname[256];
  590.         decl String:logname[256];
  591.        
  592.        
  593.         GetConVarString(FindConVar("mp_tournament_redteamname"), redTeamName, sizeof(redTeamName));
  594.         GetConVarString(FindConVar("mp_tournament_blueteamname"), blueTeamName, sizeof(blueTeamName));
  595.        
  596.         FormatTime(timestamp, sizeof(timestamp), "%Y%m%d-%H%M");
  597.         GetCurrentMap(map, sizeof(map));
  598.         Format(sDemoFileName, sizeof(sDemoFileName), "%s vs %%s-%s.dem", redTeamName, blueTeamName, timestamp, map);
  599.         Format(sLogFileName, sizeof(sLogFileName), "%s vs %s: %s-%s.log", redTeamName, blueTeamName, timestamp, map);
  600.         Format(recordname, sizeof(recordname), "%s%s", sDemoFileDir, sDemoFileName);
  601.         Format(logname, sizeof(logname), "%s%s", sLogFileDir, sLogFileName);
  602.         PrintToChatAll(sDemoFileName);
  603.         PrintToChatAll(recordname);
  604.         PrintToChatAll(sLogFileName);
  605.         PrintToChatAll(logname);
  606.         Format(command, sizeof(command), "tv_record \"%s\"", sDemoFileName);
  607.         // Start recording
  608.         ServerCommand(command);
  609.         PrintToChatAll("Recording started");
  610.         recording = true;
  611.     }  
  612.  
  613.     StopRecording()
  614.     {
  615.         if (recording)
  616.         {
  617.             // Stop recording
  618.             ServerCommand("tv_stoprecord");
  619.             PrintToChatAll("Recording stopped");
  620.             recording = false;
  621.         }
  622.     }
  623.    
  624.     // Stop recording if there are no players on the server - thanks jasonfrog!
  625.     public Action:CheckPlayers(Handle:timer)
  626.     {
  627.         if (recording)
  628.         {
  629.             for (new i = 1; i <= MaxClients; i++)
  630.             {
  631.                 if (IsClientConnected(i) && !IsFakeClient(i))
  632.                 {  
  633.                     return;
  634.                 }
  635.             }
  636.             StopRecording();
  637.         }
  638.     }
  639.    
  640.     // My custom private functions :3
  641.     /*
  642.      * Event_RoundWon: called when a round is won
  643.      * event: teamplay_round_win
  644.      * name: name of the event
  645.      * dontBroadcast: broadcast to the server
  646.      */
  647.     public Event_RoundWon(Handle:event, const String:name[], bool:dontBroadcast)
  648.     {
  649.         new String:sBlueTeamName[32];
  650.         new String:sRedTeamName[32];
  651.        
  652.         new winningTeam = GetEventInt(event, "team");
  653.         new Float:roundTimeFloat = GetEventFloat(event, "round_time");
  654.         GetConVarString(FindConVar("mp_tournament_redteamname"), sRedTeamName, sizeof(sRedTeamName));
  655.         GetConVarString(FindConVar("mp_tournament_blueteamname"), sBlueTeamName, sizeof(sBlueTeamName));
  656.        
  657.        
  658.         new roundTime = RoundToNearest(roundTimeFloat);
  659.         new mapTime = (roundTime) / 60;
  660.         new mapSecs = (roundTime) % 60;
  661.         switch(winningTeam)
  662.         {
  663.             case 2:
  664.             {
  665.                 redCapTotal++;
  666.                 new String:logMessage[64];
  667.                 Format(logMessage, sizeof(logMessage), " won in %i.%i", mapTime, mapSecs);
  668.                 CPrintToChatAll("{red} %s def %s in %i:%i {%i : %i)", sRedTeamName, sBlueTeamName,  mapTime, mapSecs, redCapTotal, blueCapTotal);
  669.                 Log(logMessage);
  670.             }
  671.             case 3:
  672.             {
  673.                 blueCapTotal++;
  674.                 new String:logMessage[64];
  675.                 Format(logMessage, sizeof(logMessage), "<red> won in %i.%i", mapTime, mapSecs);
  676.                 CPrintToChatAll("{blue} %s def %s in %i:%i {%i : %i)", sBlueTeamName, sRedTeamName, mapTime, mapSecs, redCapTotal, blueCapTotal);
  677.                 Log(logMessage);
  678.             }
  679.         }
  680.     }
  681.    
  682.     /*
  683.      * GetString: Returns the connect string to anyone who requests it
  684.      * client: the client index
  685.      * args: the argument indicies
  686.      */
  687.     public Action:Command_GetString(client, args)
  688.     {
  689.         new pieces[4];
  690.         new String:passstr[64];
  691.         new String:NetIP[32];
  692.         new String:hostport[6];
  693.         GetConVarString(FindConVar("hostport"), hostport, sizeof(hostport));
  694.         new longip = GetConVarInt(FindConVar("hostip"));
  695.         pieces[0] = (longip >> 24) & 0x000000FF;
  696.         pieces[1] = (longip >> 16) & 0x000000FF;
  697.         pieces[2] = (longip >> 8) & 0x000000FF;
  698.         pieces[3] = longip & 0x000000FF;
  699.         Format(NetIP, sizeof(NetIP), "%d.%d.%d.%d", pieces[0], pieces[1], pieces[2], pieces[3]);
  700.         GetConVarString(g_hPassword, passstr, sizeof(passstr));
  701.         CPrintToChat(client, "connect %s:%s; password %s", NetIP, hostport, passstr);
  702.     }
  703.    
  704.     /*
  705.      * GetPassword: Returns the password to anyone who requests it
  706.      * client: the client index
  707.      * args: the argument indicies
  708.      */
  709.     public Action:Command_GetPassword(client, args)
  710.     {
  711.         new String:passstr[64];
  712.         GetConVarString(g_hPassword, passstr, sizeof(passstr));
  713.         CPrintToChat(client, "{red} The password is %s", passstr);     
  714.     }
  715.    
  716.      /*
  717.      * Command_ChangePassword: The action will change the password of the server
  718.      * client: The client that wishes to execute this command
  719.      * args: The argument indicies
  720.      */
  721.     public Action:Command_ChangePassword(client, args)
  722.     {
  723.         if (args == 0)
  724.         {
  725.             new randomNumber = GetRandomInt(1000, 5000);
  726.             new String:newPassword[8];
  727.             Format(newPassword, sizeof(newPassword), "%d", randomNumber);
  728.             SetConVarString(g_hPassword, newPassword);
  729.             CPrintToChatAll("{red}Changed password to %d", randomNumber);
  730.         }
  731.         else if (args == 1)
  732.         {
  733.             new String:newPassword[64];
  734.             GetCmdArg(1, newPassword, sizeof(newPassword));
  735.             SetConVarString(g_hPassword, newPassword);
  736.             CPrintToChatAll("{red}Changed password to: %s", newPassword);
  737.         }
  738.         else
  739.         {
  740.             PrintToConsole(client, "Enter in the format !password \"password\" or with no arguments");
  741.         }
  742.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement