Anyway, I think Inside3D should serve as the central repository of all QuakeC information:
Foreword
Most of the popular mods have some form of map voting, but the burden upon a QuakeC coder to implement a map voting system is high and usually a foreign and rather technical and painful process for someone who typically is writing a mod for fun and doesn't want to be bogged down with figuring out "administrative code".
Instructions:
1. Add bindings.qc and vote.qc to your QuakeC source folder.
Just keep in mind that you will need to change line 241 to expand/contract the impulse range if the number of voteable maps change:You will need to edit vote.qc if the mod or the server you intend to use this on is running something other than the standard Quake maps. The changes necessary are pretty obvious.
2. In progs.src, you need to add vote.qc and bindings.qcLine 241 of vote.qc will need changed if voteable maps are customized
if (self.impulse >= 1 && self.impulse <= 38 )
3. Add this to the end of defs.qcAdd highlighted lines to your progs.src
../progs.dat
defs.qc
settings.qc // Add if this does not exist
func.qc
subs.qc
fight.qc
ai.qc
combat.qc
items.qc
vote.qc // Must be before weapons.qc
weapons.qc
world.qc
bindings.qc // Must be before client.qc
client.qc
player.qc
monsters.qc
doors.qc
buttons.qc
triggers.qc
plats.qc
misc.qc
These are new variables and constants to support the vote-map functionality.
4. Create or add this to settings.qcAdd to end of defs.qc
//BAM ADD
.float pflag, vflag;
.float vdelay, vcount;
.float primary_impulse_hack;
string request_mapname;
//==============
// client.pflag
//==============
// client.pflag is used for random things to remember
// about a player, and its value is saved across levels
float POQ_NEW_CLIENT = 1;
float POQ_BINDINGS_SENT = 2;
float POQ_VOTE_IDENTIFY = 4;
//==============
// client.vflag
//==============
// client.vflag is used for voting
float POQ_VOTE_YES = 1;
float POQ_VOTE_NO = 2;
Adjust the impulses as appropriate for your mod. Your mod might already use these impulses or may prefer to change them. Impulses can be from 1 to 255, but generally the lower impulses are for weapons and such.
5. Add this to the end of func.qcAdd to end of settings.qc, if settings.qc does not exist then create it.
float VOTE_PRIMARY_IMPULSE = 97;
float VOTE_YES_IMPULSE = 98;
float VOTE_NO_IMPULSE = 99;
float VOTE_PRINT_DELAY = 10;
float VOTE_PRINT_COUNT = 5;
To support the new functions.
6. Open Weapons.qc and modify as followsAdd to end of func.qc
//BAM ADD
void () vote_init_consider;
void () vote_aliases;
void (string s, void () func) vote_init;
void (float print) vote_print;
void (string mode_name, void () func) vote_spawn;
a. Find void() ImpulseCommands and highlighted text to an appropriate place in the if statements block.
b. Find void() W_WeaponFrame and insert highlighted text.Add highlighted lines to ImpulseCommands in weapons.qc
void() ImpulseCommands =
{
if (self.impulse >= 1 && self.impulse <= 8 )
W_ChangeWeapon ();
if (self.impulse == 9)
CheatCommand ();
if (self.impulse == 10)
CycleWeaponCommand ();
if (self.impulse == 11)
ServerflagsCommand ();
if (self.impulse == 12)
CycleWeaponReverseCommand ();
if (self.impulse == VOTE_YES_IMPULSE || self.impulse == VOTE_NO_IMPULSE)
vote_impulse ();
if (self.impulse == VOTE_PRIMARY_IMPULSE)
{
self.pflag = self.pflag | POQ_VOTE_IDENTIFY;
self.primary_impulse_hack = time + 0.3;
return;
}
if (self.impulse == 255)
QuadCheat ();
self.impulse = 0;
};
This is where the impulses that control map voting are checked.
7. Finally open client.qc for the following adjustmentsAdd Highlighted code as follows to W_WeaponFrame in weapons.qc
void() W_WeaponFrame =
{
if (time < self.attack_finished)
return;
if (self.impulse)
{
//BAM: Primary/Secondary vote impulse handling
if (!self.pflag & POQ_VOTE_IDENTIFY)
ImpulseCommands ();
else
{
// BAM: If a player uses the primary impulse
// (impulse <VOTE_PRIMARY_IMPULSE>) it goes into an endless loop.
if (self.primary_impulse_hack < time)
{
self.pflag = self.pflag - (self.pflag & POQ_VOTE_IDENTIFY);
self.impulse = 0;
}
else
vote_init_consider ();
}
}
// check for attack
if (self.button0)
{
SuperDamageSound ();
W_Attack ();
}
};
You may need to adjust this for some mods. This is where is bindings are sent to the client.
The process works like this: a client connects and it will need the vote aliases sent to it and .pflag is keeps track of whether or not the aliases have been sent yet or not. This needs to preserve across map changes because clients only need the aliases sent once.
If a client connects, it automatically needs them. If a client disconnects, this must be reset and the voting state of the client needs reset as well (.vflag).
Near the top, preferably right before void() SetChangeParms add this function in client.qc
void ()
SetNewParms2 =
{
parm1 = IT_SHOTGUN | IT_AXE;
parm2 = 100;
parm3 = 0;
parm4 = 25;
parm5 = 0;
parm6 = 0;
parm7 = 0;
parm8 = 1;
parm9 = 0;
parm10 = self.pflag;
};
Now in SetChangeParms, add the highlighted code
void ()
SetChangeParms =
{
if (self.health <= 0)
{
SetNewParms2 ();
return;
}
//remove items
self.items = self.items - (self.items &
(IT_KEY1 | IT_KEY2 | IT_INVISIBILITY | IT_INVULNERABILITY | IT_SUIT | IT_QUAD) );
//cap super health
if (self.health > 100)
self.health = 100;
if (self.health < 50)
self.health = 50;
parm1 = self.items;
parm2 = self.health;
parm3 = self.armorvalue;
if (self.ammo_shells < 25)
parm4 = 25;
else
parm4 = self.ammo_shells;
parm5 = self.ammo_nails;
parm6 = self.ammo_rockets;
parm7 = self.ammo_cells;
parm8 = self.weapon;
parm9 = self.armortype * 100;
parm10 = self.pflag;
};
Add this single highlighted line to SetNewParms in client.qc
void ()
SetNewParms =
{
parm1 = IT_SHOTGUN | IT_AXE;
parm2 = 100;
parm3 = 0;
parm4 = 25;
parm5 = 0;
parm6 = 0;
parm7 = 0;
parm8 = 1;
parm9 = 0;
parm10 = POQ_NEW_CLIENT; // New client! They will need aliases sent!
};
Add/change highlighted lines in DecodeLevelParms in client.qc
void ()
DecodeLevelParms =
{
if (serverflags)
{
if (world.model == "maps/start.bsp")
SetNewParms2 (); // This WAS SetNewParms(); but we are changing!
}
self.items = parm1;
self.health = parm2;
self.armorvalue = parm3;
self.ammo_shells = parm4;
self.ammo_nails = parm5;
self.ammo_rockets = parm6;
self.ammo_cells = parm7;
self.weapon = parm8;
self.armortype = parm9 * 0.01;
self.pflag = parm10; // Need to preserve state of whether aliases have been sent
};
Change highlighted line in respawn in client.qc
void ()
respawn =
{
if (coop)
{
// make a copy of the dead body for appearances sake
CopyToBodyQue (self);
// get the spawn parms as they were at level start
setspawnparms (self);
// respawn
PutClientInServer ();
}
else if (deathmatch)
{
// make a copy of the dead body for appearances sake
CopyToBodyQue (self);
// set default spawn parms
SetNewParms2 (); // Was SetNewParms();
// respawn
PutClientInServer ();
}
else
{ // restart the entire server
localcmd ("restart\n");
}
};
Finally ...Change code in ClientConnect in client.qc to mirror this
void ()
ClientConnect =
{
// a client connecting during an intermission can cause problems
if (intermission_running)
ExitIntermission ();
if (parm10 & POQ_NEW_CLIENT) // this is a new client
{
bprint (self.netname); // Note these 2 lines have been moved
bprint (" entered the game\n"); // to below the intermission check to ensure aliases are sent
player_bindings_begin (); // send aliases
parm10 = parm10 - POQ_NEW_CLIENT;
}
};
Add to end of ClientDisconnect in client.qc
void ()
ClientDisconnect =
{
if (gameover)
return;
// if the level end trigger has been activated, just return
// since they aren't *really* leaving
// let everyone else know
bprint (self.netname);
bprint (" left the game with ");
bprint (ftos(self.frags));
bprint (" frags\n");
sound (self, CHAN_BODY, "player/tornoff2.wav", 1, ATTN_NONE);
set_suicide_frame ();
self.pflag = 0; // Reset "alias sent" status
self.vflag = 0; // Reset voting state (yes/no) status
};