msgbartop
by Brian Neal
msgbarbottom

24 Jul 09 Call of Duty Random Map Rotation Generator Script

Here is a Python script I wrote to randomly generate a map rotation for our Call of Duty: World at War server. It outputs the “set sv_mapRotation” line that you should copy & paste into your server’s config file. Our gaming clan mainly plays TDM, but we got a second server to try out the other objective-based game types. Not knowing which map combinations were the best, I simply wrote a script to generate a random rotation of the non-TDM and non-DM gametypes. Unfortunately, I found out later that there is a 1024 character line length limit in the config file (boo!). So I later modified the script to observe this unfortunate limit. This means you can’t have very large map rotations.

Here are some notes about the script.

  • The script should work with any Call of Duty game from 1 to W@W. You just have to edit the list of maps and use the appropriate game types. Just be advised that the game type names aren’t consistent across titles. For example, COD:MW uses “WAR” for team deathmatch, while the older games, and COD:W@W use the more familiar “TDM”. Not all game types are supported in all titles in the series, and some titles have game types that don’t exist in other games. E.g. Only COD1 has retrieval (“RE”) and behind enemy lines (“BEL”).
  • Put the desired maps you want between the triple quoted lines 9 and 14, and separate them by spaces.
  • The gametypes  tuple on line 16 contains the game types supported. Edit this to contain the game types you want.
"""
map_rotate.py 

Generate map rotation for COD:W@W.
25 June 2009 - Brian Neal
"""
import random

maps = """\
mp_airfield mp_asylum mp_castle mp_shrine mp_courtyard mp_dome mp_downfall
mp_hangar mp_kneedeep mp_makin mp_nachtfeuer mp_outskirts mp_roundhouse
mp_seelow mp_subway mp_suburban mp_makin_day
mp_docks mp_kwai mp_stalingrad
""".split()

gametypes = ('dom', 'koth', 'sab', 'sd', 'ctf', 'twar')

combos = []
for gametype in gametypes:
   for map in maps:
      combos.append((gametype, map))

random.shuffle(combos)

# There is a 1024 character limit for lines from the config file...damn.

s = 'set sv_mapRotation "'
for game in combos:
   ss = 'gametype %s map %s ' % (game[0], game[1])
   if len(s) + len(ss) > 1024:
      break
   s += ss

s = s.rstrip()
s += '"'

print s

Remember that the script is random, so you may get the same map back-to-back, and/or some maps may be missing due to the stupid 1024 character limit. I run it a few times, saving the result into a file, until I get one that looks good. If you are ambitious, you could modify it a bit to prevent these issues, although the code for doing something like that starts to get very complicated.

I hope some people find this useful!

Tags: , , ,