Hi everyone,
This is my first time posting a plugin so bare with me, I know there is a similar plugin to the one that I'm releasing but I will explain the differences before you think I copied someone else.
Basically the main problem with MW3 at the moment is its hard for custom playlists to be used with custom game types there for anyone using the God Plugin and permissions plugin it isn't trivial as to how you switch the map with the correct game type assigned in the playlist.
What I have done is created a simple chat command that accepts the map name and DSR file name, of course its the same as another plugin but bare with me, the key difference is I have ensured only the maps defined in the plugin can ever be loaded and only if they do exist will they be loaded. If a map is found along with the specified game type two server commands will be issued; one that sets the map rotation playlist and another that rotates the map using the custom playlist that was just set.
In a nutshell it works like this:
Now the main problem with setting a custom DSPL file is that you lose the custom playlist previously assigned, to fix this issue on the map pre change I have set a check that looks for this custom DSPL file and switches the map rotation back to the DSPL file you had set previously.
There are some limitations/downsides to doing this and they are:
Now of course I'm still new to this so there may be a way to fix this but from my investigating there isn't but if you know a fix please let me know. So without further ado add the following into your sv_config.ini file.
Usage:
Changelog:
Credits:
@Nukem - For such a great code base to work with
@Pozzuh - For the permissions plugin
Source:
Thanks for reading and hope you enjoy it!
GameTypeChanger-v1.3.zip (Size: 4.5 KB / Downloads: 182)
GameTypeChanger-v1.2.zip (Size: 4.16 KB / Downloads: 67)
GameTypeChanger-v1.1.zip (Size: 4.16 KB / Downloads: 27)
GameTypeChanger-v0.1.zip (Size: 3.19 KB / Downloads: 20)
This is my first time posting a plugin so bare with me, I know there is a similar plugin to the one that I'm releasing but I will explain the differences before you think I copied someone else.
Basically the main problem with MW3 at the moment is its hard for custom playlists to be used with custom game types there for anyone using the God Plugin and permissions plugin it isn't trivial as to how you switch the map with the correct game type assigned in the playlist.
What I have done is created a simple chat command that accepts the map name and DSR file name, of course its the same as another plugin but bare with me, the key difference is I have ensured only the maps defined in the plugin can ever be loaded and only if they do exist will they be loaded. If a map is found along with the specified game type two server commands will be issued; one that sets the map rotation playlist and another that rotates the map using the custom playlist that was just set.
In a nutshell it works like this:
- The plugin creates a new DSPL file in the admin folder
- Once created it adds a new playlist line for the map and game type
- Next it assigns the map rotation to the custom playlist
- Finally it rotates the map
Now the main problem with setting a custom DSPL file is that you lose the custom playlist previously assigned, to fix this issue on the map pre change I have set a check that looks for this custom DSPL file and switches the map rotation back to the DSPL file you had set previously.
There are some limitations/downsides to doing this and they are:
- The map rotation counter goes up so once the map rotates it sits at 2
- The !nextmap command reports the same map as been next because of the custom playlist
- You need to write the full name of maps and game types as its not smart enough to guess them for you
- When the map changes the !mr command will rotate to the to the first map in your playlist file
Now of course I'm still new to this so there may be a way to fix this but from my investigating there isn't but if you know a fix please let me know. So without further ado add the following into your sv_config.ini file.
Code:
[GameTypeChange]
dsplfile=default
// The name of the DSPL file you have set for your map playlist
Usage:
Code:
!gametype <map name> <dsr file name>
or
!gt <map name> <dsr file name>
Example: !gt dome INF_default
Changelog:
Spoiler (Click to View)
Credits:
@Nukem - For such a great code base to work with
@Pozzuh - For the permissions plugin
Source:
CSHARP Code
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using Addon;
-
- namespace GameTypeChanger
- {
- public class GameTypeChanger : CPlugin
- {
- // The array that aliases can be stored in
-
- // General variables
- public bool isDLC = false;
- public string mapName;
- public string gameType;
-
- /// <summary>
- /// Executes when a client connects to the MW3 server.
- ///
- /// When a client does connect a list of map aliases will be constructed that will be used to
- /// determine if a chosen map is part of the DLC packs or a standard map that comes packaged
- /// with the game on a clean install.
- /// </summary>
- public override void OnServerLoad()
- {
- ServerPrint("\n Game type changer plugin loaded. Author: SgtLegend. Version 1.3\n");
-
- // Create the map alias array
- // Standard maps
-
- // DLC maps
- });
-
- // Get and set all the directories in the zone folder
- string[] zoneDirectories = Directory.GetDirectories("zone");
-
- foreach (string directory in zoneDirectories)
- {
- if (!directory.Contains("dlc"))
- directories.Add(directory);
- }
-
- aliases.Add("zones", directories);
- }
-
- /// <summary>
- /// Listens for when a client types in the chat, currently it listens for "!gametype" and "!gt"
- /// which are two pre-defined chat commands that can be assigned using the permissions plugin
- /// otherwise everyone will be able to use them.
- /// </summary>
- /// <param name="Message"></param>
- /// <param name="Client"></param>
- /// <returns></returns>
- public override ChatType OnSay(string Message, ServerClient Client)
- {
- if (Message.StartsWith("!gametype") || Message.StartsWith("!gt"))
- {
- string[] split = Message.Split(' ');
-
- // Do we have enough arguments?
- if (split.Length < 3)
- {
- TellClient(Client.ClientNum, "^1Usage: ^7!" + split[0] + " <map name> <dsr name>", true);
- return ChatType.ChatNone;
- }
-
- // Set the map name and game type
- mapName = split[1].ToLower();
- gameType = split[2];
-
- // Are the required arguments empty?
- if (string.IsNullOrEmpty(mapName) || string.IsNullOrEmpty(gameType))
- {
- TellClient(Client.ClientNum, (string.IsNullOrEmpty(mapName) ? "^1Enter a map name" : "^1Enter a game type DSR name"), true);
- return ChatType.ChatNone;
- }
-
- // Sort through all the maps specified in the alias list and determine if the map name
- // the user has entered matches something in that list
- setMapNameAndIsDLC();
-
- // Check if the specified map exists on the server and also check if the game type given
- // is on that exists within the admin folder
- bool isMapValid = checkIfTheMapExists();
- bool isGameTypeValid = File.Exists(@"admin\" + gameType + ".dsr");
-
- if (!isMapValid || !isGameTypeValid)
- {
- TellClient(Client.ClientNum, string.Format("^1Invalid ^7{0} ^1given!", (!isMapValid ? "map name" : "game type")), true);
- return ChatType.ChatNone;
- }
-
- // Check if the custom playlist file we created still exists, if it does we need to
- // delete it off the server so the normal playlist can continue to work after the map
- // has been changed
- if (File.Exists(@"admin\gametypechanger.dspl"))
- {
- File.Delete(@"admin\gametypechanger.dspl");
- }
-
- // Create the new playlist file that we can use to force the game type
- createDSPLFileAndMessageTheAdmins();
-
- return ChatType.ChatNone;
- }
-
- return ChatType.ChatContinue;
- }
-
- /// <summary>
- /// When the map changes the custom DSPL file we set will take control of the map rotation so we
- /// need to switch it back to the original DSPL file.
- ///
- /// There is a downside to this which is that we have to incur another map rotation call which now
- /// increments the total to "2" rotations.
- ///
- /// Resets the variables that may still have values from the last change.
- /// </summary>
- public override void OnMapChange()
- {
- isDLC = false;
- mapName = string.Empty;
- gameType = string.Empty;
-
- if (File.Exists(@"admin\gametypechanger.dspl"))
- {
- ServerCommand("sv_maprotation " + GetServerCFG("GameTypeChange", "dsplfile", "default"));
- }
- }
-
- /// <summary>
- /// Loops through all the pre-defined maps that were constructed while the server was connecting to
- /// the server and tries to determine which map the user has chosen using the switch game type commands
- /// </summary>
- private void setMapNameAndIsDLC()
- {
- foreach (AliasListing map in aliases["maps"])
- {
- string[] mapDetails = map.value.Split(':');
-
- // Check if the given map name matches the current map name
- if (mapName == map.name || mapName == mapDetails[1])
- {
- mapName = mapDetails[1];
- isDLC = (mapDetails[0] == "dlc");
- break;
- }
- }
- }
-
- /// <summary>
- /// Checks if the given map exists on the server using the list of directories that we discovered
- /// in the zone folder earlier.
- /// </summary>
- /// <returns></returns>
- private bool checkIfTheMapExists()
- {
- if ((isDLC && File.Exists(@"zone\dlc\" + mapName + ".ff")) || !isDLC)
- {
- if (!isDLC)
- {
- foreach (string directory in aliases["zones"])
- {
- if (File.Exists(directory + @"\" + mapName + ".ff"))
- return true;
- }
- }
- else
- {
- return true;
- }
- }
-
- return false;
- }
-
- /// <summary>
- /// It also create the custom DSPL file needed to set the user selected map and game type set via
- /// the commands.
- ///
- /// Lets all the admins on the server know the map was just changed using "!gametype" or "!gt" and
- /// what game type was loaded during the change.
- /// </summary>
- private void createDSPLFileAndMessageTheAdmins()
- {
- {
- file.WriteLine(string.Format("{0},{1},1", mapName, gameType));
-
- // Issue the server command to change the map
- ServerCommand("sv_maprotation gametypechanger");
- ServerCommand("start_map_rotate");
-
- // Display a server message to let the user know the map and game type has changed. Admins ONLY!
- string adminXUIDs = GetServerCFG("Permission", "Admin_xuids", "");
- List<ServerClient> clients = GetClients();
-
- if (!string.IsNullOrEmpty(adminXUIDs))
- {
- foreach (ServerClient client in clients)
- {
- if (adminXUIDs.Contains(client.XUID))
- TellClient(client.ClientNum, string.Format("^5Map changed to ^7{0} ^5using ^7{1} as the game type", mapName, gameType), true);
- }
- }
- }
- }
- }
-
- /// <summary>
- /// A re-usable structure array that can be used for map aliases etc...
- /// </summary>
- public struct AliasListing
- {
- public string name, value;
- }
- }
Thanks for reading and hope you enjoy it!




I now host all my MW3 projects on my private GIT repo