AI Tutorial
Adding Night Mode

 

      This will be a short, easy, and fun lesson. I will show you how to add a night mode for fighting monsters or bots in the dark.
      You can use the QuakeC source if you want to battle creatures at night. But if you like bots, just download the code for the BGBots. It will work for them, too.
      First step: open up the MISC.QC file. Okay, first I will give you the code which you will be adding:


	if (cvar("temp1") == 1)
		{
		lightstyle(self.style, "a");
		return;
		}

      This code says if the console variable "temp1" is set to one, then the light style will be "a", which means none.
      Alright, copy that code. You will be adding that to eight subroutines. I don't want to list the entire routine here. Just look for these lines and paste the above code after each bracket:


void() light =
{

void() light_fluoro =
{

void() light_fluorospark =
{

void() light_globe =
{

void() light_torch_small_walltorch =
{

void() light_flame_large_yellow =
{

void() light_flame_small_yellow =
{

void() light_flame_small_white =
{

      Remember, we want our new code to come after the braket and before any of id's code. We want to turn off each light when the map loads.
      Now the second step. Open up CLIENT.QC and scroll down to the PutClientInServer() routine, which begins like this:


/*
===========
PutClientInServer

called each time a player is spawned
============
*/
void() DecodeLevelParms;
void() PlayerDie;


void() PutClientInServer =
{
	local	entity spot;

	spot = SelectSpawnPoint ();

      At the *end* of that routine, before the bracket and semi-colon, add the following code:


	if (cvar("temp1") == 1)
		self.effects = EF_DIMLIGHT;

      PutClientInServer() is where the player is "born." So, this code will make him glow in the dark. Now, open up MONSTERS.QC and slide down to this stuff:


//============================================================================

void() walkmonster_start_go =
{
local string	stemp;
local entity	etemp;


      After this, paste in the same code. You also want to paste it into the subroutines flymonster_start_go() and swimmonster_start_go(). Now the monsters will glow in the dark.
      Last step. If you are starting with the BgBot code, open the file called BOT.QC and scroll down to this:


//=============================================================
// BotActivate - Activates the bot
//=============================================================
void (string name) BotCreate =
{
// sounds and models precached in the world.qc file

      Paste your glow-in-the-dark code at the end of this subroutine. Also, you must add it to the end of the next routine, called botrespawn().
      You're done. With our change, the player, monsters, and bots will emit light, but the rest of the level will be pitch black. Even though we did a lot of pasting, all we really did was turn off the lights and add special effects to the contestants.
      When you start Quake, bring down the console and type "temp1 1" without the quotes. Then load your favorite map.
      Shooting rockets in the dark can be very cool.
 


Author: Coffee
Questions: coffee@planetquake.com
AI chat on ICQ: 2716002