// Suicide Barrels Map Manager module
// About this module:
// This module codes for when the server changes map
// It makes sure the next map is a SB map, and if it is not it changes to a random
// SB map. This module is loaded with SB, and to unload it you must type 'es_unload sb_map'
// in the server console, or via RCON

block load
{
  // Settings:
  // Override the next map or unload script
  // 1 = Override | 2 = Unload script
  es_set sb_nextoverride 1
  echo Suicide Barrels Map Manager has been loaded
}

event es_map_start
{
  if ("sb_" in event_var(nextmap)) do
  {
    // Ok, so its a SB map!
    es echo Nextmap: event_var(nextmap)
    // Leave time for the config to execute
    es_delayed 10 mp_playerid 1
  }
  else do
  {
    if (server_var(sb_nextoverride) equalto 1) do
    {
      // Ok, so override the map
      echo ----------------------------------------
      echo ERROR! The nextmap is not a SB map!
      echo All SB maps must be prefixed with a sb_!
      es echo The next map was event_var(nextmap)
      echo ----------------------------------------
      // Override the next map!
      map sb_killingrooms2.bsp
    }
    else do
    {
      // Ok, unload the script
      echo ----------------------------------------
      echo ERROR! The nextmap is not a SB map!
      echo All SB maps must be prefixed with a sb_!
      es echo The next map was event_var(nextmap)
      echo ----------------------------------------
      es_unload sb
    }
  }
}

block unload
{
  echo Suicide Barrels Map Manager has been unloaded!
}
