Making Maps Switch Randomly (alternate)

From Armagetron

This is a different way to go about Making Maps Switch Randomly, which requires no knowledge of Armagetron map-making. It cycles through a number of random maps every minute, and can even change settings accordingly or announce the map's name and creator.

This tutorial worked on an i686 Dell Dimension L933r running Fedora Core 5. Let me know if you have successes on different hardware/distros.

Requirements

  • A Linux system with Armagetron Advanced Server installed (possibly works on Mac OS X from a Terminal)
  • The cron utility
  • PHP (possibly requires HTTPD)

Tutorial

  • Make sure you are root.
$ su
Password: _
#
  • Make sure cron is started.
# /etc/init.d/crond start
  • Make a directory for cron to check every minute.
# mkdir /etc/cron.minutely
  • Let cron know to check for that directory.
# echo "*  * * * root run-parts /etc/cron.minutely" >> /etc/crontab
  • Now comes the fun part. (If you are more comfortable with another editor or have not used Vi before, go ahead and use it.)
# vi rand.php
  • Here is the sample PHP file that I use for my server.
!/usr/bin/php
<?php
echo "INCLUDE settings_custom.cfg\n";
$rand = rand(1,5);
if ( $rand == "1" ) {
        echo "MAP_FILE Blind/Beta/clanfun-1.1.aamap.xml\n";
        echo "SAY Next Map: Clan Fun by Blind";
} elseif ( $rand == "2" ) {
        echo "MAP_FILE Your_mom/cockpit/classic_m-0.0.3.aacockpit.xml\n";
        echo "SAY Next Map: Cockpit by Your mom";
} elseif ( $rand == "3" ) {
        echo "MAP_FILE manta/misc/nano_slingers-0.0.2.aamap.xml\n";
        echo "SAY Next Map: Nano Slingers by Manta";
} elseif ( $rand == "4" ) {
        echo "MAP_FILE HIM/race/race_map-0.1.0.aamap.xml\n";
        echo "SAY Next Map: Race Map by HIM";
} elseif ( $rand == "5" ) {
        echo "MAP_FILE Durka/nano/nano_sumo-0.0.2.aamap.xml\n";
        echo "SAY Next Map: Nano Sumo by Durka";
}
?>

This PHP file generates a random number and chooses a map accordingly. (The "\n"s at the end are PHP newlines; they are essential. If you modify this sample, remember to keep them!) If you want more maps, change the line

$rand = rand(1,5);

to

$rand = rand(1,x);

where x is the number of maps you want. Then add another block of these:

} elseif ( $rand == "5" ) {
        echo "MAP_FILE /path/to/map/file/in/repository\n";
        echo "SAY Next Map: Map Name by Creator";
}

for each extra map you have.

  • Make the PHP file executable.
# chmod a+x rand.php
  • The PHP file will output the map configuration onto the screen, but we need something to put it into a file. That is a shell script. Open another file for writing.
# vi rand.sh
  • Here is the shell script. You should not need to modify this, except to specify your user config directory.
#!/bin/bash
/etc/cron.minutely/rand.php > /your/userconfig/directory/everytime.cfg
  • Copy both files to the /etc/cron.minutely directory.
# cp rand.php /etc/cron.minutely/rand.php
# cp rand.sh /etc/cron.minutely/rand.sh
  • Give cron a good 3 minutes to recognize the new file.
  • Start the server. You're done!

The best part about this is that you can edit /etc/cron.minutely/rand.php to include more maps without shutting down the server; cron will pick it up automatically in the next minute.

Please tell me if this tutorial did not work for you.

Warning

If the match lasts less than 1 minute, the map may not be updated.