Map voting system

This will make 3 random maps that the players can vote for by typing "$VOTE 1", "$VOTE 2", or "$VOTE 3" into the chat.

First, lets set which modes are enabled and which maps can be selected.

using System;
using CustomGameOW;
using System.Collections.Generic;
using System.Linq;

namespace CustomgameBotLibrary_MapVoting
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            CustomGame cg = new CustomGame();

            // Modes that are enabled in our custom game.
            cg.ModesEnabled.TeamDeathmatch = true;

            // Maps that can be selected.
            string[] maps = new string[] 
            {
                "tdm_Dorado",
                "tdm_Eichenwalde",
                "tdm_Hanamura",
                "tdm_Hollywood",
                "tdm_Horizon",
                "tdm_KingsRow",
                "tdm_TempleOfAnubis",
                "tdm_Volskaya",
            };
        }
    }
}

Then, choose 3 random maps from the maps array and store it in a new array.

[STAThread]
static void Main(string[] args)
{
    CustomGame cg = new CustomGame();

    // Modes that are enabled in our custom game.
    cg.ModesEnabled.TeamDeathmatch = true;

    // Maps that can be selected.
    string[] maps = new string[] 
    {
        "tdm_Dorado",
        "tdm_Eichenwalde",
        "tdm_Hanamura",
        "tdm_Hollywood",
        "tdm_Horizon",
        "tdm_KingsRow",
        "tdm_TempleOfAnubis",
        "tdm_Volskaya",
    };

    // Get maps
    Random rnd = new Random();
    string[] votemap = new string[3]; // Array of maps that can be voted for.
    // Choose random maps to be added to the votemap variable.
    for (int i = 0; i < votemap.Length; i++)
    {
        string choose; // Map index that is chosen.
        while (true)
        {
            // Make sure there are no duplicates when choosing the next map to be added to the votemap array
            choose = maps[rnd.Next(maps.Length)];
            if (votemap.Contains(choose))
                continue;
            break;
        }
        votemap[i] = choose;
    }
    // We now have an array, votemap, with 3 random strings from the maps array.
}

Now send a chat message showing the maps that can be voted for.

[STAThread]
static void Main(string[] args)
{
    CustomGame cg = new CustomGame();

    // Modes that are enabled in our custom game.
    cg.ModesEnabled.TeamDeathmatch = true;

    // Maps that can be selected.
    string[] maps = new string[] 
    {
        "tdm_Dorado",
        "tdm_Eichenwalde",
        "tdm_Hanamura",
        "tdm_Hollywood",
        "tdm_Horizon",
        "tdm_KingsRow",
        "tdm_TempleOfAnubis",
        "tdm_Volskaya",
    };

    // Get maps
    Random rnd = new Random();
    string[] votemap = new string[3]; // Array of maps that can be voted for.
    // Choose random maps to be added to the votemap variable.
    for (int i = 0; i < votemap.Length; i++)
    {
        string choose; // Map index that is chosen.
        while (true)
        {
            // Make sure there are no duplicates when choosing the next map to be added to the votemap array
            choose = maps[rnd.Next(maps.Length)];
            if (votemap.Contains(choose))
                continue;
            break;
        }
        votemap[i] = choose;
    }
    // We now have an array, votemap, with 3 random strings from the maps array.
    
    // Send message to chat of what maps can be voted for.
    string type = "Vote for map! (15 seconds)                                     " + votemap[0] + " - $VOTE 1                              " + votemap[1] + " - $VOTE 2                              " + votemap[2] + " - $VOTE 3";
    cg.Chat(type);
}

This will send a chat message like this:

To start listening to the $VOTE command, add the string "$VOTE" to the CustomGame.Commands.ListenTo variable, and set CustomGame.Commands.Listen to true.

[STAThread]
static void Main(string[] args)
{
    CustomGame cg = new CustomGame();

    // Modes that are enabled in our custom game.
    cg.ModesEnabled.TeamDeathmatch = true;

    // Maps that can be selected.
    string[] maps = new string[] 
    {
        "tdm_Dorado",
        "tdm_Eichenwalde",
        "tdm_Hanamura",
        "tdm_Hollywood",
        "tdm_Horizon",
        "tdm_KingsRow",
        "tdm_TempleOfAnubis",
        "tdm_Volskaya",
    };

    // Get maps
    Random rnd = new Random();
    string[] votemap = new string[3]; // Array of maps that can be voted for.
    // Choose random maps to be added to the votemap variable.
    for (int i = 0; i < votemap.Length; i++)
    {
        string choose; // Map index that is chosen.
        while (true)
        {
            // Make sure there are no duplicates when choosing the next map to be added to the votemap array
            choose = maps[rnd.Next(maps.Length)];
            if (votemap.Contains(choose))
                continue;
            break;
        }
        votemap[i] = choose;
    }
    // We now have an array, votemap, with 3 random strings from the maps array.
    // Send message to chat of what maps can be voted for.
    string type = "Vote for map! (15 seconds)                                     " + votemap[0] + " - $VOTE 1                              " + votemap[1] + " - $VOTE 2                              " + votemap[2] + " - $VOTE 3";
    cg.Chat(type);

    // Now, start listening for the "$VOTE" command for 15 seconds.
    CustomGame.Commands.ListenTo.Add("$VOTE", true);
    CustomGame.Commands.Listen = true;
    System.Threading.Thread.Sleep(15000);
    CustomGame.Commands.Listen = false;
}

Sort through the commands to get the map highest voted for.

[STAThread]
static void Main(string[] args)
{
    CustomGame cg = new CustomGame();

    // Modes that are enabled in our custom game.
    cg.ModesEnabled.TeamDeathmatch = true;

    // Maps that can be selected.
    string[] maps = new string[] 
    {
        "tdm_Dorado",
        "tdm_Eichenwalde",
        "tdm_Hanamura",
        "tdm_Hollywood",
        "tdm_Horizon",
        "tdm_KingsRow",
        "tdm_TempleOfAnubis",
        "tdm_Volskaya",
    };

    // Get maps
    Random rnd = new Random();
    string[] votemap = new string[3]; // Array of maps that can be voted for.
    // Choose random maps to be added to the votemap variable.
    for (int i = 0; i < votemap.Length; i++)
    {
        string choose; // Map index that is chosen.
        while (true)
        {
            // Make sure there are no duplicates when choosing the next map to be added to the votemap array
            choose = maps[rnd.Next(maps.Length)];
            if (votemap.Contains(choose))
                continue;
            break;
        }
        votemap[i] = choose;
    }
    // We now have an array, votemap, with 3 random strings from the maps array.
    // Send message to chat of what maps can be voted for.
    string type = "Vote for map! (15 seconds)                                     " + votemap[0] + " - $VOTE 1                              " + votemap[1] + " - $VOTE 2                              " + votemap[2] + " - $VOTE 3";
    cg.Chat(type);

    // Now, start listening for the "$VOTE" command for 15 seconds.
    CustomGame.Commands.ListenTo.Add("$VOTE", true);
    CustomGame.Commands.Listen = true;
    System.Threading.Thread.Sleep(15000);
    CustomGame.Commands.Listen = false;

    // Get results
    int[] results = new int[3]; // Array to store results in.
    var commands = CustomGame.Commands.ExecutedCommands; // Commands that were executed by players.
    for (int i = 0; i < commands.Count; i++)
        if (commands[i].command == "$VOTE")
        {
            try
            {
                // Get map player voted for and index result of map.
                int votefor = Int32.Parse(commands[i].parameters[0]) - 1;
                results[votefor]++;
            }
            catch (Exception) { }
        }
    string winningmap = votemap[results.ToList().IndexOf(results.Max())]; // Gets the highest voted for map.
    CustomGame.Commands.ExecutedCommands = new List<CustomGame.Commands.CommandData>(); // Resets executed commands variable.
    cg.Chat(String.Format("{0}: {1} votes, {2}: {3} votes, {4}: {5} votes", votemap[0], results[0], votemap[1], results[1], votemap[2], results[2])); // Write results to chat.
    cg.Chat("Next map: " + winningmap); // Write name of next map to chat.
    Map mapid = cg.GetMapIDFromName(winningmap); // Get ID of next map.
    cg.ToggleMap(mapid, true); // Set next map in custom games.
}