Configuring custom weapon modes on a per map basis

We were recently asked how to go about configuring a multiplayer Half-Life 2: Deathmatch server to support different game modes depending on maps. 

The owner wants to offer varying environments for players to play in, and luckily our weapon manager plugin was designed with this specific goal in mind!

We elected to use the most excellent mapconfigs plugin by bcserv to handle the actual task of setting which set of weapons maps would use.  In this case, we set it up so that maps prefixed with “de_” would use sniper weapons only, with remaining maps using default weapons.  

First things first though:  Deciding which weapons players would spawn with and whether other weapons would be allowed.  

We setup defined two weapon modes:

default” gives shotgun, crowbar, pistol, smg1, slam, 357, crossbow, frag, physcannon.  For giggles, we set the 357 magnum to allow firing under water – we were curious to see who figured out they can snipe with the fishes!  

sniperxbow” – my personal favorite, the perfect combination for a neo-style fire and forget physics weapon, and a 357 magnum for those times when you’re sneaking in the bushes.  For this mode, we set the option to not allow weapon pickups from the map.  

"default"
{
  "options"
  {
    "pickupothers"  "1"     // 1 - Players can pick up any weapons they find on the map.  0 = deny pickups of other weapons
  }

  "weapon_shotgun"
  {
    "default"       "1"     // Make the Shotfun the default weapon
  }

  "weapon_crowbar"
  {

  }

  "weapon_pistol"
  {
    "p_underwater" "1"    
  }

  "weapon_smg1"
  {
  }

  "weapon_slam"
  {

  }

  "weapon_357"
  {
    "p_underwater"  "1"     // Primary attack fires under water

  }

  "weapon_crossbow"
  {

  }

  "weapon_frag"
  {
  }

  "weapon_physcannon"
  {

  }
}


"sniperxbow"
{
  "weapon_crossbow"
  {
  }

  "weapon_357"
  {
    "default" "1"
  }
  "options"
  {
    "pickupothers"  "0"     // 0 - can't pick up any other weapons than those listed here
  }
}

With these settings added to addons/sourcemod/configs/weaponmanager.cfg it was now time to setup the sniper maps to use the sniperxbow weapon mode.

bcserv’s mapconfig plugin is pretty simple to configure.  mapconfig looks for a configuration file for the current map in based on map prefix, so if we’re playing a map named “de_xyzzy” – mapconfig will first try to read “de_.cfg”, then “de_xyzzy.cfg”.  More technical information about the mapconfig configuration and plugin can be found on the AlliedModders forum.

In this case we set it up as follows:

From the hl2mp server folder, create:

cfg/sourcemod/map-cfg/de_.cfg

and add the line:

sm_weaponmanager_defaultmode sniperxbow

With this in place, every map that starts with de_ will run the sniperxbow weaponmode.  The best part is for specific maps (eg: de_xyzzy), if we wanted to add a slightly different configuration (lets call it “xyzzy” mode, we could create a new weaponmode that grants the crossbow, 357 and crowbar!

"xyzzy"
{
  "weapon_crossbow"
  {
  }

  "weapon_357"
  {
    "default" "1"
  }
  
  "crowbar"
  {
  
  }
  
  "options"
  {
    "pickupothers"  "0"     // 0 - can't pick up any other weapons than those listed here
  }
}

Then in we would create a new mapconfig file named cfg/sourcemod/map-cfg/de_xyzzy.cfg

and add the command:

sm_weaponmanager_defaultmode xyzzy

We can also add extra commands too, so that only de_xyzzy runs them.  For example:

sv_gravity 600
sm_playerspeed_infiniterun "1"

would adjust the gravity for this map only and also let players run infinitely without recharging.

Easy peasy!