Raised This Month: $7 Target: $400
 1% 

Dynamic Map Rotations (Nextmap Based on # of Players, Time, etc)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author
FLOOR_MASTER
Senior Member
Join Date: Mar 2008
Plugin ID:
320
Plugin Version:
0.7
Plugin Category:
Server Management
Plugin Game:
Any
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Dynamically alters the map rotation based on server conditions.
    Old 03-20-2008 , 21:41   Dynamic Map Rotations (Nextmap Based on # of Players, Time, etc)
    Reply With Quote #1

    Dynamic Map Rotations is a plugin I wrote to allow me to automatically alter the map rotation based on the current server conditions. With Dynamic Map Rotations, you can skip maps based on the number of players on the server or the time of day, and it's easy to add more conditions.

    Dynamic Map Rotations replaces nextmap.smx but reproduces the in-game "nextmap" functionality and the sm_setnextmap command.

    For brevity, I'll sometimes use "DMR" in place of dynamic map rotations.

    Configuration
    • dmr_file (default "dmr.txt")
      • Specifies the filename your DMR is stored in. The default filename resolves to orangebox/tf/dmr.txt in TF2, for example.
    • sm_nextmap
      • Specifies the current nextmap. This updates every minute and should be considered read-only.

    Commands
    • nextmap
      • This is an in-game chat trigger that displays the current nextmap, based on server conditions.
    • nextmaps
      • This is an in-game chat trigger that displays the next 5 maps, based on server conditions.
    • sm_setnextmap <mapname>
      • Force the specified mapname (e.g. "sm_setnextmap cp_dustbowl") to be the next map. After the forced nextmap is run, the rotation continues from where it left off (no maps are skipped).
    • sm_unsetnextmap
      • If you've used sm_setnextmap to force a nextmap, this command will undo that action and allow the DMR to proceed uninterrupted.
    • sm_reloaddmr
      • Reload your Dynamic Map Rotation if you've made any changes to it. Also display the current status of the plugin.
    Dynamic Map Rotations
    Dynamic map rotations are essentially keyvalues structures. I'll go through an illustrative example of how to create a simple DMR. Let's begin with a simple basic mapcycle.txt:
    Code:
    cp_gravelpit
    cp_well
    cp_dustbowl
    Here's an equivalent DMR:
    Code:
    "rotation"
    {
        "start"    "10"
        "10"
        {
            "map"            "cp_gravelpit"
            "default_nextmap"    "20"
        }
        "20"
        {
            "map"            "cp_well"
            "default_nextmap"    "30"
        }
        "30"
        {
            "map"            "cp_dustbowl"
            "default_nextmap"    "10"
        }
    }
    There are several things to note about the DMR:
    • The entire keyvalues structure is called "rotation"
    • Every map is its own section with an arbitrary section name. In this case, the names are "10", "20", and "30", but they could easily be the mapnames themselves or whatever you want.
    • There is a "start" keyvalue pair that indicates the first map in the rotation.
    • Within each section is a "map" keyvalue pair whose value is the actual name of the map.
    • Within each section is a "default_nextmap" keyvalue pair. The value points to the section of the nextmap. For example, notice how in section 30 (cp_dustbowl), the default_nextmap is section 10 (cp_gravelpit).
    The above DMR looks like:

    Now let's say we want to skip ctf_well when the number of players on the server is <= 12. The corresponding DMR looks like:
    Code:
    "rotation"
    {
        "start"    "10"
        "10"
        {
            "map"            "cp_gravelpit"
            "default_nextmap"    "20"
             "30"
            {
                "players_lte"    "12"
            }
        }
        "20"
        {
            "map"            "cp_well"
            "default_nextmap"    "30"
        }
        "30"
        {
            "map"            "cp_dustbowl"
            "default_nextmap"    "10"
        }
    }
    Notice the subsection added within section 10 (cp_dustbowl). This is called a conditional nextmap. Basically, the red highlighted section can be read as "if the number of players is lte (less than or equal to) 12, then the nextmap is section 30 (cp_dustbowl)". If the conditional nextmap isn't true, which in this case means there are more than 12 players on the server, then the default_nextmap is used as the next map. Visualized, this looks like:

    One more example. Let's add cp_badlands to the rotation and throw in a few more conditional nextmaps:
    Code:
    "rotation"
    {
        "start"    "10"
        "10"
        {
            "map"            "cp_gravelpit"
            "default_nextmap"    "20"
            "30"
            {
                "players_lte"    "12"
            }
    
        }
        "20"
        {
            "map"            "ctf_well"
            "default_nextmap"    "30"
            "bdlnds"
            {
                "players_lte"    "10"
                "time_lte"    "11:00"
            }
            "10"
            {
                "players_lte"    "10"
            }
        }
        "30"
        {
            "map"            "cp_dustbowl"
            "default_nextmap"    "10"
        }
    
        "bdlnds"
        {
            "map"            "cp_badlands"
            "default_nextmap"    "30"
        }
    }
    Before I discuss it, here is the visualization:

    First, notice how I used the section name "bdlnds". Remember that section names are arbitrary -- I could have just been consistent and chosen "40" or chosen anything at all.

    Let's look closely at section 20 (ctf_well). There are two conditional nextmaps and a default_nextmap. The first condition reads "IF the number of players <= 10 AND the current server time is <= 11AM, THEN the next map is section bdlnds (cp_badlands)". The second condition reads "IF the number of players <= 10 THEN the next map is section 10 (cp_gravelpit). If none of the conditional nextmaps are true, then the nextmap is the default_nextmap: section 30 (cp_dustbowl).

    Conditional nextmaps are evaluated in the order they're written, and the first one that is true is taken. So in the case of ctf_well, if the number of players were, for example 8, and it was 1AM, then the next map would be cp_badlands. If the number of players were 8 and it was 2PM, then the next map would be cp_gravelpit. It's really pretty straightforward!

    Automated DMR Generator
    Understandably, typing up a DMR is a pain. I've written a simple web tool to help get you started as well as visualize your DMR.
    Simply paste your mapcycle.txt into the top text box to generate the basic DMR. You can then modify it to add custom conditions. You can use the bottom text box to create a visualization of your DMR similar to the example images you've seen in this post.

    Custom Conditions
    • players_lte - the number of players on the server is less than or equal to the specified number
    • players_gte - ditto, but greater than or equal to
    • time_lte - the current server time is less than or equal to the specified time, in 24-hour "h:mm" format
    • time_gte - ditto, but greater than or equal to
    • day_eq - the day is currently a certain day of the week, where the day is specified with m, t, w, r, f, s, and u for Monday, Tuesday, etc. You can specify multiple days. For example, "day_eq" "mwf" will be true if the day is Monday, Wednesday, or Friday. "day_eq" "u" will be true if the day is Sunday.
    • day_neq - ditto, but if the day is NOT a certain day of the week
    Please send me your ideas for new custom conditions to add.

    Installation
    1. Move nextmap.smx from your SourceMod plugins directory to the "plugins/disabled" directory
    2. Create a dynamic map rotation and copy it to your game's root directory (the same directory as mapcycle.txt, most likely
    3. Copy dmr.smx to your SourceMod plugins directory
    4. Note: dmr.inc is for plugin authors. You do not need to download dmr.inc for a normal installation.
    Other Cvars
    These cvars are modified and used directly by the plugin and should be considered read only. Modify them at your own peril.
    • dmr_map_key - the current section key in the rotation. DMR will base its nextmap decisions on this section's conditional nextmaps/default_nextmap.
    • dmr_force_nextmap - if sm_setnextmap was used, this cvar stores the value of the nextmap that will be loaded in lieu of the DMR-based nextmap. Setting this value directly will not guarantee it will be used: use sm_setnextmap.
    Compatibility
    This plugin was developed for a TF2 server, but I don't have any reason to believe it would misbehave in other games. Please let me know if it works with other games.

    Version History
    • 2008-03-20 - v0.1
      • Initial release
    • 2008-03-25 - v0.2
      • Fixed bug with Insurgency mod
      • Added GetNextMaps() function for other plugins to retrieve a mapcycle-like list of next maps
    • 2008-04-06 - v0.3
      • Added custom conditions day_eq and day_neq
    • 2008-05-01 - v0.5
      • Added nextmaps command
      • Added sm_nextmap cvar for compatibility with plugins that need to know nextmap info via cvars (ads, etc)
    • 2008-05-06 - v0.6
      • Fixed conditional nextmap bug where times weren't properly calculated when both time_lte and time_gte are used in a single conditional nextmap
      • Added sm_unsetnextmap command
      • Added sm_reloaddmr command
    • 2008-05-14 - v0.7
      • Fixed bug involving time ranges (when both time_lte and time_gte are used in the same conditional nextmap)
    Todo
    • Complete comments
    • Add better support for specifying time ranges that straddle midnight
    • Global conditional nextmaps
    • Verify compatibility with other rotation-related plugins (rtv/votemaps/etc)
    How am I using it? This is my server's rotation as of this writing: http://tf2.2fort2furious.com/images/dmr.php

    I'd love to hear any feedback or suggestions about the plugin.
    Attached Files
    File Type: inc dmr.inc (1.4 KB, 1389 views)
    File Type: sp Get Plugin or Get Source (dmr.sp - 4025 views - 23.3 KB)

    Last edited by FLOOR_MASTER; 05-15-2008 at 01:44.
    FLOOR_MASTER is offline
     


    Thread Tools
    Display Modes

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump


    All times are GMT -4. The time now is 04:31.


    Powered by vBulletin®
    Copyright ©2000 - 2024, vBulletin Solutions, Inc.
    Theme made by Freecode