Installing Dr. Banzai's Voting Patch
------------------------------------

First, you need the source code of your server patch. If you want to start with
id's original code, you can download it from:

ftp://ftp.idsoftware.com/idstuff/unsup/progs106.zip


First thing to do is to install the Random Map Chooser. Here is how:

in Client.qc, change this line:


	if (cvar("samelevel"))	// if samelevel is set, stay on same level

to this:

	if (cvar("samelevel") > 0)  // if samelevel is set, stay on same level

Later on in the file, the context looks like this:

 {
 	local entity o;
 
 	if (mapname == "start")
 	{
 		if (!cvar("registered"))

You will need to add these four lines of code after "local entity o;" and
before "if (mapname ==":


	if (cvar("samelevel") < 0)
		o = RandomNextMap();
	else
	{

Next, do a search from that position for "nextmap = o.map;". Add a line
containing only this, after the nextmap line:

	}


In the file Progs.src, add these lines after world.qc and before client.qc:

	maplist.qc
	randmap.qc

Then, you need to move maplist.qc and randmap.qc into the same directory
as the rest of your .qc files.

That is all for the Random Map Chooser. Now to install the voting code:

Open Weapons.qc.
Add these lines before the line "void() ImpulseCommands =" like so:

	void() AddVote;			// Add this line
	void() StatVote;		// Add this line
				//
	void() ImpulseCommands =	// This line is already there

Add this code into the ImpulseCommands function before the line
"self.impulse = 0;" :

	// Voting Impulses
	if (self.impulse == 100)
		AddVote ();			// Register your vote

	if (self.impulse == 101)
		StatVote ();		// See how many people have voted

Next, add this code at the very end of weapons.qc:


// START NEW CODE START NEW CODE
// HKCSRV START
/*
====================
Voting
	Player voting for a new level
====================
*/
void() NextLevel;
void() CheckVote;

/*
========================
AddVote
	Registers a player's vote.
========================
*/

void() AddVote =
{
if (self.vote == 1) {
	sprint(self, "You've already voted!\n");
	StatVote();
	CheckVote();
	return;
	}

self.vote = 1;

sprint (self, "Thank you for your vote.\n");
bprint (self.netname);
bprint (" voted for a CHGLVL. Impulse 100 to vote\n");

StatVote();
CheckVote();

};

/*
========================
StatVote
	Tells player the percentage of players who have voted.
========================
*/

void() StatVote =
{
local	entity	ent;
local	float		numplayers;
local	float		vote_tally;
local string		temp;
local float			tempFloat;

ent = nextent (world);
while (ent != world)
{
  if (ent.classname == "player")
  {
    numplayers = numplayers + 1;
	if (ent.vote == 1)
		vote_tally = vote_tally + 1;
  }
	  ent = nextent (ent);
}

temp = ftos (vote_tally);
sprint (self, temp);
sprint (self, " votes, ");
temp = ftos (numplayers);
sprint (self, temp);
sprint (self, " total. Percent voted: ");
tempFloat = vote_tally / numplayers;
tempFloat = tempFloat * 100;
tempFloat = rint (tempFloat);
temp = ftos (tempFloat);
sprint (self, temp);
sprint (self, "\n"); 

};

/*
========================
CheckVote
	Checks whether more than 50% of players have voted.
	If so, it changes to a random level.
========================
*/

void() CheckVote =
{
local	entity	ent;
local	float		numplayers;
local	float		vote_tally;
local	float		temp;

ent = nextent (world);
while (ent != world)
{
  if (ent.classname == "player")
  {
    numplayers = numplayers + 1;
	if (ent.vote == 1)
		vote_tally = vote_tally + 1;
  }
	  ent = nextent (ent);
}

temp = vote_tally / numplayers;
temp = temp * 100;

if (temp > 50)
{
bprint ("The majority of the players voted to change the level\n");
NextLevel ();
}

};
// HKCSRV END
// END NEW CODE END NEW CODE






Now re-compile the code using QCC and put the progs on your server.
Note that one should use "noexit 1" and "samelevel -1" with this
patch. Also one should set a fraglimit and timelimit for full
enjoyment of the random-map chooser.

Be sure to read randmap.txt.

You are done!


Customization
--------------


The default impulses are Impulse 100 to register a vote,
and Impulse 101 to check the status of the votes. You may
want to change these impulses. Also it would be a good idea
to install an MOTD to tell players what the impulses are to
vote. Mail me for more information. phosk@tesla.uah.ualberta.ca




