Tutorial *50*

Editors note: this one was received after the original quakeC menu tutorial was released. According to the author, this one is more flexible then the other. This is one big chunk of code, for instructions, read the comments in it.

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

// Inserting the menus

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

// Below are the voids we need so that each player can store what his menu is calling

// Put them in your defs qc

.void() mnuchoice1;

.void() mnuchoice2;

.void() mnuchoice3;

.void() mnuchoice4;

.void() mnuchoice5;

.void() mnuchoice6;

.void() mnuchoice7;

.void() mnuchoice8;

.void() mnuchoice9;

.float inmenu; // This tells you whether a player is in a menu (i.e., if other impulses are disabled)

// Put this in a qc that is before any in which you will call menus

void() ClearMenus =


self.inmenu = 0;

self.mnuchoice1 = SUB_Null;

self.mnuchoice2 = SUB_Null;

self.mnuchoice3 = SUB_Null;

self.mnuchoice4 = SUB_Null;

self.mnuchoice5 = SUB_Null;

self.mnuchoice6 = SUB_Null;

self.mnuchoice7 = SUB_Null;

self.mnuchoice8 = SUB_Null;

self.mnuchoice9 = SUB_Null;


// Put this in a qc that is before any in which you will call menus

void() CallMenu =


if (self.impulse == 1)

self.mnuchoice1 ();

else if (self.impulse == 2)

self.mnuchoice2 ();

else if (self.impulse == 3)

self.mnuchoice3 ();

else if (self.impulse == 4)

self.mnuchoice4 ();

else if (self.impulse == 5)

self.mnuchoice5 ();

else if (self.impulse == 6)

self.mnuchoice6 ();

else if (self.impulse == 7)

self.mnuchoice7 ();

else if (self.impulse == 8)

self.mnuchoice8 ();

else if (self.impulse == 9)

self.mnuchoice9 ();


// Add the following two lines at the top of your CheckImpulses function

// You may need to edit them to make them work with your mod

if ((self.impulse >= 1 && self.impulse <= 9) && (self.inmenu == 1))

CallMenu ();

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

// Using the menus

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

// Say you wanted to create a menu where each choice does exactly the same thing.

// Also say that you made a trigger that will set up this menu in whoever touched it.

// The code that follows is what the trigger's touch function would look like:

void() trigger_touch =


if (other.classname != "player")

return; //Not a player, so no menu

if (other.health <= 0)

return; //Make sure they are still alive...

other.mnuchoice1 = say_hi; // These next ten lines set up the menu

other.mnuchoice2 = say_hi;

other.mnuchoice3 = say_hi;

other.mnuchoice4 = say_hi;

other.mnuchoice5 = say_hi;

other.mnuchoice6 = say_hi;

other.mnuchoice7 = say_hi;

other.mnuchoice8 = say_hi;

other.mnuchoice9 = say_hi;

other.inmenu = 1;

centerprint (other, "1-9: Do exactly the same thing\n"); // Tell the player what the menu is


// Now when the player touches the trigger the menu will pop up, centerprinted. He then has to press one of the

// number keys (1-9) and the corresponding option (function) will 'open up'. Of course, all these ones do the same

// thing, so it doesnt matter which key he presses.

// Ok, you have the menu, but if you try to compile this, it will go blah blah... say_hi not found or something

// The code below is what you would put in that function. Obviously this would go before the trigger_touch code ;)

void() say_hi =


sprint (self, "Hi\n"); // Say hi to your self... how sad

ClearMenus (); // Clear the menus so they can be used again without conflicts and stuff


// That about sums it up. you can use these menus anywhere, and they can also be practically infinitely expanded.

// To do this, you need to set option 9 on the first menu to target a function that loads up a new menu (after clearing

// the old one). You then set the option 1 of the second one to target the first menu. This way you can scroll

// between multiple menus, all acting as one. Pretty neat, eh? :)

Not logged in
Sign up