Updated 2/25/08 -- Highly recommended to upgrade to new version as it fixes a memory leak!
Dependencies
Optional -- nextmap.smx (required for autochangemap_mode
1). Also optional -- modified mapchooser.smx (required if you use both autochangemap_mode
1 and
mapchooser.smx at the same time -- explanation below).
Description
This plugin causes the map to automatically change when there isn't a certain amount of players on the server for a set amount of time. For example, if you want to have the server change maps when the server is empty for ten minutes, this plugin can accomplish that.
An alternative function of this plugin would be to
always force automatic map changes, regardless of the player count, after a set amount of minutes. This would be useful in games where the last round has to be played out to completion past the map's time limit -- if you do not enjoy that feature. I did not make the plugin with this in mind, so it's implementation may not be ideal for that use.
This is based on Nicolous' AutoChangeLevel plugin (abandoned). Some code was also taken from SourceMod's nextmap.smx plugin.
CVars
autochangemap_client_limit "1"
// Number of clients that must be connected before automatic map changes are disabled. Zero disables automatic map changes.
// Default: "1"
// Minimum: "0.000000"
autochangemap_include_bots "0"
// Include bots in the client count (remember, SourceTV counts as a bot).
// Default: "0"
// Minimum: "0.000000"
// Maximum: "1.000000"
autochangemap_time_limit "10"
// Consecutive minutes which must pass while the client limit has not been reached for the automatic map change to occur. Zero disables automatic map changes.
// Default: "10"
// Minimum: "0.000000"
autochangemap_mode "0"
// Method of choosing the next map in automatic map changes: 0 = custom mapcycle (create new section in sourcemod/configs/maplists.cfg), 1 = sm_nextmap/mapcycle (requires nextmap.smx), 2 = load map in autochangemap_default_map cvar, 3 = reload current map.
// Default: "0"
// Minimum: "0.000000"
// Maximum: "3.000000"
autochangemap_default_map ""
// Map to load at automatic map changes when autochangemap_mode is set to '2.'
// Default: ""
autochangemap_config_to_exec ""
// Config to exec when an automatic map change occurs, if desired. Executes after the map loads and server.cfg and SourceMod plugin configs are exec'd.
// Default: ""
Installation
1. Delete old autochangemap.cfg in cfg\sourcemod\ (if applicable).
2. Configure and add autochangemap.cfg to cfg\sourcemod\.
3. Add autochangemap.smx to addons\sourcemod\plugins\.
4. (Optional) Add nextmap.smx to addons\sourcemod\plugins\.
5. (Optional) Add modified mapchooser.smx to addons\sourcemod\plugins\.
Nextmap.smx is required if you want to use autochangemap_mode 1. If you use autochangemap_mode 1 and you don't have nextmap.smx, you will get errors.
The modified mapchooser.smx is required if you want to use autochangemap_mode 1 and MapChooser at the same time. This simply removes the one line in MapChooser that sets sm_nextmap to "Pending Vote." Side effect is that typing "nextmap" in chat will still show the next map in the mapcycle, even if MapChooser is set to run a vote to select the next map. But it's the best I could do for now. The version of MapChooser it's based on is 1895 (2008-02-22). I'll continue to update it as new MapChoosers come out, until I get a better solution or the new map management SourceMod plugin comes out, at which point this plugin will become irrelevant (yay!).
Configuration
Autochangemap_mode explanation:
Automapchange_mode 0 will simply cycle through a custom mapcycle (specified in maplists.cfg -- see instructions below). It doesn't keep track of maps played -- it will just go to the next map in the file any time an automatic map change occurs. Very simple.
Mode 1 will cycle through your normal map cycle using sm_nextmap, which may be more or less desirable, depending on your needs.
Mode 2 will load whatever map is specified in autochangemap_default_map.
Mode 3 will reload the current map.
Instructions for setting up mapcycle file for autochangemap_mode 0:
1. Create a maplist file. One map per line, no special syntax. Txt, cfg, ini, whatever. Place it somewhere within the mod folder or subfolders.
2. Add a "autochangemap" sub-section to addons/sourcemod/configs/maplists.cfg within the "MapLists" section --
Code:
"autochangemap"
{
"file" "<relative path to mapcycle file from mod folder>"
}
Important additional notes:
You can specify a config file to run on automatic map changes with autochangemap_config_to_exec. It runs after loading the new map and after the server.cfg and plugin configs are exec'd. It will only run on map changes triggered by this plugin (automatic map changes).
IMPORTANT -- set up your autochangemap.cfg file! The config is re-executed on every map change, so if you want your settings to stick, you have to change them in the config file. This has special implications when using autochangemap_config_to_exec -- if you don't specify this in the config file, it will never run!
Use only integers for numerical type cvars. I didn't code for handling of floating point numbers. (Is there an easy way to force the type for cvars?)
Change Log
1.1
% Substantial rewrite.
% Added exec'ing a config on automatic map changes.
% Added cycling through a custom mapcycle file with autochangelevel_mode 0.
% Added a chat message and a five second delay before changing maps.
% Added optional custom mapchooser.smx for compatibility with autochangemap_mode 1.
% Changed autochangemap_type to autochangemap_mode and changed values correlating with modes.
% Changed default cvar values.
% Changed/removed some code for dealing with invalid map names. Now the plugin will simply reload the current map if it encounters an invalid map name on trying to change maps.
% Fixed a memory leak.
1.0
% Initial release.
Please inform me of any bugs/problems.
Here ya go.