Map game files

From King Arthur's Gold Wiki
Jump to: navigation, search

Map game files, with the .gm extension, can be used to run scripts prior to loading the map. They can be specified in the "mapcycle" variable in the MapCycle.cfg file.

You can use these files to run scripts during map load, customize the map, spawn bots, or add workshops.

Examples

Spawning Workshops

The following map.gm file, when loaded, will load the map at "Rules/MODE/Maps/map.png", and then spawn a Tunnel (tunnel config not supplied by default) at X of 212 and Y of 692, with the "neutral" (used by both players) team.

LoadMap("Rules/MODE/Maps/map.png");
addBlob(`room`,`Rules/MODE/Rooms/Tunnel.cfg`,212,692,3);

Spawning Bots

Spawning bots is a bit tricker, as you need to add some custom pausing variables to prevent the bots from being doubled on a map restart.

if ( LVL != -1 ) { // In case nextmap/restart is used more than once
  global LVL = -1;  // For restart map
  while ( WORKING == 1 ) {sleep( 0.5 );} // Waits until the previous lvl script ends
  LoadMap( "Rules/MODE/Maps/map.png" );

  global WORKING = 1;
  serverMessage(`Loading bots...`);
  sleep( 10 ); // pause for a second

  for (it = 0; it <= 10; it = it + 1) {
    addBotX(0,0,`Blue Knight`);
    addBotX(1,0,`Red Knight`);
  }
  global WORKING = 0;
} else {
  LoadMap("Rules/MODE/Maps/map.png");
}

Note how we set a global variable, called LVL, to -1, and then proceed onward. This prevents our bots from being loaded multiple times if a map restart happens; if LVL is still -1, just load the map, as the bots are already loaded.

We then set another global var, WORKING, to 1. This tells KAG that we're adding bots, so if a restart happens while we're adding them, don't add even more - wait until we're done.

We make sure to load the map prior to loading the bots, and then send a server message in-chat to the server saying we're loading the bots.

Next, we pause for a second to give the map time to generate. Finally, we run a "for" loop, which basically allows us to create 10 knight bots for both the red and blue teams (see addBotX).

Finally, we set WORKING to 0 to tell KAG we're done.

See Also