<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3AMM_MapAutoSizer</id>
	<title>Scripts:MM MapAutoSizer - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3AMM_MapAutoSizer"/>
	<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:MM_MapAutoSizer&amp;action=history"/>
	<updated>2026-08-06T01:09:17Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://bf2tech.uturista.pt/index.php?title=Scripts:MM_MapAutoSizer&amp;diff=116&amp;oldid=prev</id>
		<title>Pireax: Created page with &quot;__TOC__ == Introduction  ==  After trying out Scripts:AutoMap and finding that it didn&#039;t do exactly what I wanted (and didn&#039;t seem to work with BF2 1.12),...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:MM_MapAutoSizer&amp;diff=116&amp;oldid=prev"/>
		<updated>2018-06-22T15:32:09Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__TOC__ == Introduction  ==  After trying out &lt;a href=&quot;/index.php/Scripts:AutoMap&quot; title=&quot;Scripts:AutoMap&quot;&gt;Scripts:AutoMap&lt;/a&gt; and finding that it didn&amp;#039;t do exactly what I wanted (and didn&amp;#039;t seem to work with BF2 1.12),...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__TOC__&lt;br /&gt;
== Introduction  ==&lt;br /&gt;
&lt;br /&gt;
After trying out [[Scripts:AutoMap|Scripts:AutoMap]] and finding that it didn&amp;#039;t do exactly what I wanted (and didn&amp;#039;t seem to work with BF2 1.12), I decided to write a plugin for the popular [[ModManager|ModManager]] package that comes with [http://www.bf2cc.com/ BF2CC]. The idea is based on [[Scripts:AutoMap|Scripts:AutoMap]], but there are some important differences:&lt;br /&gt;
&lt;br /&gt;
* no randomizer&lt;br /&gt;
* the map rotation is read directly out of the BF2 server and not from maplist.con. This allows you to use this script even when you&amp;#039;re changing your map rotation on the fly, without messing things up. It also allows map voting to work properly.&lt;br /&gt;
* map size thresholds are configurable through the modmanager configuration file&lt;br /&gt;
&lt;br /&gt;
== Downloading  ==&lt;br /&gt;
&lt;br /&gt;
You can always find the most current version at the [http://www.gloryhoundz.com/code/ GloryHoundz Code Repository]. As of this writing, the latest version is 1.0 to be found here: [http://www.gloryhoundz.com/code/mm_mapautosizer/1.0/mm_mapautosizer.py mm_mapautosizer.py].&lt;br /&gt;
&lt;br /&gt;
== Prerequisites  ==&lt;br /&gt;
&lt;br /&gt;
[[ModManager|ModManager]] or [http://www.bf2cc.com/ BF2CC] &lt;br /&gt;
&lt;br /&gt;
== Install  ==&lt;br /&gt;
&lt;br /&gt;
* copy the file to &amp;#039;&amp;#039;admin/modules&amp;#039;&amp;#039; in your Battlefield 2 server install.&lt;br /&gt;
* change your &amp;#039;&amp;#039;modmanager.con&amp;#039;&amp;#039; and include the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;modmanager.loadModule &amp;quot;mm_mapautosizer&amp;quot;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The default threshold for 32-size maps is 16 players and for 64-size maps it&amp;#039;s 32 players. You can set your own thresholds by adding two configuration lines to &amp;#039;&amp;#039;modmanager.con&amp;#039;&amp;#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;mm_mapautosizer.threshold_64 40&amp;#039;&amp;#039;&lt;br /&gt;
&amp;#039;&amp;#039;mm_mapautosizer.threshold_32 20&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Bugs/Comments  ==&lt;br /&gt;
&lt;br /&gt;
If you encounter any problems, stop by the [http://www.gloryhoundz.com/forums/ GloryHoundz Forums] and post about it. &lt;br /&gt;
&lt;br /&gt;
== The Code ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# vim: ts=4 sw=4 noexpandtab&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;MapAutoSizer module&lt;br /&gt;
&lt;br /&gt;
===== About =====&lt;br /&gt;
 This ModManager script was created by GloryHoundz.com to allow for auto&lt;br /&gt;
 sizing of maps in rotation based on the number of people on a server.&lt;br /&gt;
&lt;br /&gt;
 Inspired and partially based on the DontCamp.com dc_automap.py script from&lt;br /&gt;
 http://bf2.fun-o-matic.org/index.php/Scripts:AutoMap&lt;br /&gt;
&lt;br /&gt;
===== Config =====&lt;br /&gt;
 # 64 Player map threshold. End of map number of players to trigger 64-size map&lt;br /&gt;
 mm_mapautosizer.threshold_64 32&lt;br /&gt;
&lt;br /&gt;
 # 32 Player map threshold. End of map number of players to trigger 32-size map&lt;br /&gt;
 mm_mapautosizer.threshold_32 16&lt;br /&gt;
&lt;br /&gt;
===== History =====&lt;br /&gt;
 v1.0 - 1/15/2006:&lt;br /&gt;
 Initial public release: fixed map voting support&lt;br /&gt;
&lt;br /&gt;
 v0.9 - 1/08/2006:&lt;br /&gt;
 Internal GloryHoundz.com release&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
import bf2&lt;br /&gt;
import host&lt;br /&gt;
import mm_utils&lt;br /&gt;
import re&lt;br /&gt;
&lt;br /&gt;
# Set the version of your module here&lt;br /&gt;
__version__ = 1.0&lt;br /&gt;
&lt;br /&gt;
# Set the required module versions here&lt;br /&gt;
__required_modules__ = {&lt;br /&gt;
    &amp;#039;modmanager&amp;#039;: 1.0&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Does this module support reload ( are all its reference closed on shutdown? )&lt;br /&gt;
__supports_reload__ = True&lt;br /&gt;
&lt;br /&gt;
# Set the description of your module here&lt;br /&gt;
__description__ = &amp;quot;MapAutoSizer v%s&amp;quot; % __version__&lt;br /&gt;
&lt;br /&gt;
# Add all your configuration options here&lt;br /&gt;
configDefaults = {&lt;br /&gt;
    &amp;#039;threshold_64&amp;#039;: 32,&lt;br /&gt;
    &amp;#039;threshold_32&amp;#039;: 16&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class MapAutoSizer( object ):&lt;br /&gt;
&lt;br /&gt;
    def __init__( self, modManager ):&lt;br /&gt;
        # ModManager reference&lt;br /&gt;
        self.mm = modManager&lt;br /&gt;
&lt;br /&gt;
        # Internal shutdown state&lt;br /&gt;
        self.__state = 0&lt;br /&gt;
&lt;br /&gt;
        # Add any static initialisation here.&lt;br /&gt;
        # Note: Handler registration should not be done here&lt;br /&gt;
        # but instead in the init() method&lt;br /&gt;
&lt;br /&gt;
    def onGameStatusChanged(self, status):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Control Map rotation.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        threshold64 = self.__config[&amp;#039;threshold_64&amp;#039;]&lt;br /&gt;
        threshold32 = self.__config[&amp;#039;threshold_32&amp;#039;]&lt;br /&gt;
        if 1 != self.__state:&lt;br /&gt;
            return 0&lt;br /&gt;
&lt;br /&gt;
        if status == bf2.GameStatus.EndGame:&lt;br /&gt;
            host.rcon_invoke(&amp;#039;echo &amp;quot;MapAutoSizer Initializing&amp;quot;&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
            rawMapRotation = host.rcon_invoke(&amp;#039;maplist.list&amp;#039;).split(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
            mapRotation = []&lt;br /&gt;
            for mapLine in rawMapRotation:&lt;br /&gt;
                if mapLine:&lt;br /&gt;
                    mapParts = mapLine.split(&amp;quot; &amp;quot;)&lt;br /&gt;
                    if mapParts[1]:&lt;br /&gt;
                        mapRotation.append(mapParts[1])&lt;br /&gt;
&lt;br /&gt;
            nextMapIndex = int(host.rcon_invoke(&amp;#039;admin.nextLevel&amp;#039;))&lt;br /&gt;
            if nextMapIndex &amp;gt;= len(mapRotation):&lt;br /&gt;
                nextMapIndex = 0&lt;br /&gt;
            host.rcon_invoke(&amp;#039;echo &amp;quot;MapAutoSizer next map index: %s&amp;quot;&amp;#039; % (nextMapIndex))&lt;br /&gt;
&lt;br /&gt;
            nextMap = mapRotation[nextMapIndex]&lt;br /&gt;
            host.rcon_invoke(&amp;#039;echo &amp;quot;MapAutoSizer next map: %s&amp;quot;&amp;#039; % (nextMap))&lt;br /&gt;
&lt;br /&gt;
            numPlayers = 0&lt;br /&gt;
&lt;br /&gt;
            for p in bf2.playerManager.getPlayers():&lt;br /&gt;
                numPlayers += 1&lt;br /&gt;
&lt;br /&gt;
            host.rcon_invoke(&amp;#039;echo &amp;quot;MapAutoSizer number of players: %s&amp;quot;&amp;#039; % (numPlayers))&lt;br /&gt;
&lt;br /&gt;
            if numPlayers &amp;gt;= threshold64:&lt;br /&gt;
                mapSize = 64&lt;br /&gt;
            if numPlayers &amp;lt; threshold64:&lt;br /&gt;
                mapSize = 32&lt;br /&gt;
            if numPlayers &amp;lt; threshold32:&lt;br /&gt;
                mapSize = 16&lt;br /&gt;
&lt;br /&gt;
            host.rcon_invoke(&amp;#039;echo &amp;quot;Changing map entry (index,name,size): (%s,%s,%s)&amp;quot;&amp;#039; % (nextMapIndex, nextMap, mapSize))&lt;br /&gt;
            host.rcon_invoke(&amp;#039;maplist.insert %s %s gpm_cq %d&amp;#039; % (nextMapIndex, nextMap, mapSize))&lt;br /&gt;
            host.rcon_invoke(&amp;#039;maplist.remove %s&amp;#039; % (nextMapIndex+1))&lt;br /&gt;
            host.rcon_invoke(&amp;#039;admin.setnextlevel %s&amp;#039; % (nextMapIndex))&lt;br /&gt;
            host.rcon_invoke(&amp;#039;echo &amp;quot;MapAutoSizer finished&amp;quot;&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
    def init( self ):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Provides default initialisation.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # Load the configuration&lt;br /&gt;
        self.__config = self.mm.getModuleConfig( configDefaults )&lt;br /&gt;
&lt;br /&gt;
        if 0 == self.__state:&lt;br /&gt;
            # Register GameStatus event handler&lt;br /&gt;
            host.registerGameStatusHandler(self.onGameStatusChanged)&lt;br /&gt;
&lt;br /&gt;
        # Update to the running state&lt;br /&gt;
        self.__state = 1&lt;br /&gt;
&lt;br /&gt;
    def shutdown( self ):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Shutdown and stop processing.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # Flag as shutdown as there is currently way to:&lt;br /&gt;
        # host.unregisterHandler&lt;br /&gt;
        self.__state = 2&lt;br /&gt;
&lt;br /&gt;
        # Unregister GameStatus event handler&lt;br /&gt;
        host.unregisterGameStatusHandler(self.onGameStatusChanged)&lt;br /&gt;
&lt;br /&gt;
    def update( self ):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Process and update.&lt;br /&gt;
        Note: This is called VERY often processing in here should&lt;br /&gt;
        be kept to an absolute minimum.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
def mm_load( modManager ):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Creates and returns the MapAutoSizer object.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    return MapAutoSizer( modManager )&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Changelog  ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
v1.0 - 1/15/2006:&lt;br /&gt;
Initial public release: fixed map voting support&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
v0.9 - 1/08/2006:&lt;br /&gt;
Internal GloryHoundz.com release&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pireax</name></author>
	</entry>
</feed>