Creating a New Game Mode

So you think you have a interesting idea for a new game mode?  Wish to have the ability to toggle it by the console?  Here is how.

The whole thing relies on a alias in which you set in your KEYCONF lump.   This alias should set a variable of your choice, but should not be named the same as the said variable.  (Well technically it can be but I would recommend against it.)  Your alias will need to back reference an argument and use the set command.  Here is an example:

alias mynewgamemode "set mynewgamemodevar %1"

The end user will now be able to call "mynewgamemode 1" in the console to turn it on.  But we will need an ACS script to control it.  I would highly recommend storing the code in a library so you can fix bugs without recompiling every map.  Vary useful particularly in complex modes.  Just be sure you are not using the same script numbers as the maps.  To create a library start your script with #library "LIBNAME".  ("LIBNAME" can not be more than 8 characters.)  This name will be the lump name.  (Remember #import and not #include!)

#library "MYMODE"
#include "zcommon.acs"

script 1 OPEN
{
	while(1)
	{
		int myvar = getcvar("mynewgamemodevar");
		if(myvar)
			log(s: "The game mode is on!");
		else
			log(s: "The game mode is off!");
		delay(5);
	}
}

Lets add a global variable in the mix so we can store the value between maps.  Additionally you will need a variable to hold what state it is in for the current maps (usually we can't change the mode mid level).  So with this we will also be able to inform the server that the game mode will be changed next game.  If you are unfamiliar with global variables the "1:" is the global variable index number.  This is required to tell Skulltag what variable to restore between maps.  Like everything else this should be an unused number.

As stated before we will need to use while(true) to keep the script looping instead of restart because we need to transfer the global variable's value to the map variable's.  After that is done we will set the global variable to myvar and tell the server if the global is not the same as myvar.  Again refer to the example.

#library "MYMODE"
#include "zcommon.acs"

global bool 1:mygamemode_state;
bool mygamemode_enabled;

script 1 OPEN
{
	mygamemode_enabled = mygamemode_state;
	while(true)
	{
		int myvar = gcvar("mynewgamemodevar");
		if(myvar != mygamemode_state)
		{
			log(s: "My game mode will be changed next game.");
			mygamemode_state = myvar;
		}
		delay(5);
	}
}

Now you have a fully functional game mode toggle!  But it still doesn't do anything.  You must then code your game mode into other scripts and wrap the code with an if statement like so:

//Take all weapons and give them a shotgun.
script 2 ENTER
{
	if(mygamemode_enabled)
	{
		clearinventory();
		giveinventory("shotgun", 1);
		setweapon("shotgun");
	}
}

Of course for that you would also need a RESPAWN script, but I'm not here to do the work for you.

Back to TOC