Tutorial *47*
Is it hard remember some impulses, or you simply need a menu for choosing team? This is a nice menu that works very fine. In this menu we will only add two different menu item's "team 1" and "team 2".


First, make a new file, and name it "menu.qc". Open it and place this into it:



void() Menu_Select;



void() Toggle_Menu =

{

	if (self.menu == 0)

		self.menu = 1;

	else

	{

		Menu_Select();

		self.menu = 0;

	}

};



void() Draw_Menu =

{

	if (self.menu == 1)

	{

		centerprint(self,"Choose your team\n> Team 1\n  Team 2");

	}

	if (self.menu == 2)

	{

		centerprint(self,"Choose your team\n  Team 1\n> Team 2");

	}

}



void() Menu_Down =

{

	if (self.menu == 1)

	{

		self.menu = 2;

		Draw_Men();    // Updates the menu imegetly when you want to move cursor.

	}

	if (self.menu == 2)

	{

		self.menu = 1;

		Draw_Men();    // Updates the menu imegetly when you want to move cursor.

	}

}



// A Menu_Up is not nessesary here, cause we only have two items.



void() Menu_Select =

{

	if (self.menu == 1)

	{

		self.team = 1;

		self.menu = 0;	       // Don't draw the menu anymore

		centerprint(self,"");  // Take away the menu

		PutClientInServer ();  // This respawns the player

	}

	if (self.menu == 2)

	{

		self.team = 1;

		self.menu = 0;	       // Don't draw the menu anymore

		centerprint(self,"");  // Take away the menu

		PutClientInServer ();  // This respawns the player

	}

}

Now we're done with this file, close it and open the defs.qc file. Add at the very bottom of that file:


.float	menuupdate;

Open up the client.qc file, and brows down to the "PlayerPreThink" function. Above the if (intermission_running) add this:


if ((self.menu != 0) && (self.menuupdate < time)

{

	self.menuupdate = time + 1.5;

	Draw_Menu();

}

I think this need some explonation. If you're on a LAN, or just use the menu in Singelplayer, then you can take off the "self.menuupdate" stuff. But if you're supposed to play on internet, we don't want the menu to update each frame (cause this will owerflow the player). The Centerprint function draws the text in 2 seconds, but we're refreshing this menu each 1.5 second. Why's that? Well, Simply because if someone have a ping of 300ms, then if we have 2 seconds, the menu will dissapear for 0.3 seconds before it's redrawn. That's why ;). Anyway, close the client.qc file, and load up the weapons.qc file, and scroll down to the "Impulsecommands" function. After the:


	if (self.impulse == 12)

		CycleWeaponReverseCommand ();

add this:


	if (self.impulse == 20)

		Toggle_Menu();

	if (self.impulse == 21)

		Menu_Down();

Now compile, and type "impulse 20" to enable the menu, then type "impulse 21" to change the menu item, and impulse 20 again to select.


 
Not logged in
Sign up
Login:
Passwd: