Map Changing Vote system


 

Posted by Fear (195.92.194.*) on June 30, 1999 at 07:23:48:

Here are some instructions on how to implement an easy voting system to quake 2. With some small modifications it can be used to do all sort of things
like kick people, turn weapons on and off etc

First We need to create some variables

Add these lines to level_locals_t in g_local.h

     int vote_active;

     int vote_number;

     float vote_time;

     char vote_nextmap[MAX_QPATH];


And this one too client_respawn_t
This variable is here because We dont want people to vote more than once by killing theirselves


     qboolean vote_taken; // True if the client has voted


Add This line to G_Runframe in g_main.c


     vote_think();


Add these lines to ClientCommand in g_cmds.c in the usual way


     else if (Q_stricmp(cmd, "warp") == 0)

     Cmd_warp_f(ent);

     else if (Q_stricmp(cmd, "vote") == 0)

     Cmd_vote_f(ent);


If your fussy add these lines to the top of that file


     void Cmd_warp_f(edict_t *ent);

     void Cmd_vote_f(edict_t *ent);


Create a new file called p_vote.c and paste the remainder of this text into it


     #include "g_local.h"

     // david.hillier2@virgin.net

     // Fears remote system

     // -------------------

     extern cvar_t *sv_maplist;

     extern cvar_t *sv_votepercent;

     qboolean ValidMap (char *mymap, char *maplist)

     {

     char *p;

     cvar_t *sv_maplist;

     sv_maplist = gi.cvar ("sv_maplist", "", 0);

     p = strstr( maplist, mymap );

     if( p != NULL )

     return true;

     else

     return false;

     }

     void Cmd_vote_f (edict_t *ent)

     {

     char *s;

     s = gi.args();

     if (!level.vote_active)

     {

     gi.cprintf (ent, PRINT_HIGH, "No active votes.\n");

     return;

     }

     if(ent->client->resp.vote_taken)

      {

     gi.cprintf (ent, PRINT_HIGH, "You've already voted.\n");

     return;

     }

     if (!s)

     {

     gi.cprintf (ent, PRINT_HIGH, "Type Vote .\n");

     return;

     }

     if (Q_stricmp(s, "yes") == 0)

     {

     gi.cprintf (ent, PRINT_HIGH, "Voted Yes.\n");

     level.vote_number++;

     ent->client->resp.vote_taken = true;

     }

     if (Q_stricmp(s, "no") == 0)

     {

     gi.cprintf (ent, PRINT_HIGH, "Voted No.\n");

     ent->client->resp.vote_taken = true;

     }

     gi.bprintf (PRINT_HIGH, "There are currently %i 'Yes' votes.\n", level.vote_number);

     }

     void Cmd_warp_f (edict_t *ent)

     {

     char *s;

     cvar_t *sv_votepercent;

     sv_votepercent;= gi.cvar ("sv_votepercent;", "50", 0);

     s = gi.args();

     if (sv_votepercent->value> 100)

     {

     gi.cprintf (ent, PRINT_HIGH, "Voting Disabled.\n");

     return;

     }

     if (level.vote_active)

     {

     gi.cprintf (ent, PRINT_HIGH, "Vote already in progress.\n");

     return;

     }

     if(!ValidMap(s,sv_maplist->string))

     {

     gi.cprintf (ent, PRINT_HIGH, "Type warp *map name* to change level.\n");

     return;

     }

     //Activate Vote

     level.vote_active = true;

     level.vote_time = level.time + 30;

     level.vote_number = 0;

     // Vote for yourself

     level.vote_number = 1;

     ent->client->resp.vote_taken = true;

     //Set the nextmap

     strcpy (level.vote_nextmap, s);

     gi.bprintf (PRINT_HIGH, "Type vote yes to change the map to %s.\n", level.vote_nextmap);

     }

     void vote_think ()

     {

     int i,numplayers=0;

     edict_t *player;

     float remaining;

     cvar_t *sv_votepercent;

     sv_votepercent;= gi.cvar ("sv_votepercent;", "50", 0);

     if (!level.vote_active)

     {

     for(i=1;i<=maxclients->value;i++)

     {

     if ((player= &g_edicts[i]) &&player->inuse)

     player->client->resp.vote_taken = false;

     }

     return;

     }

     if (level.vote_time < level.time)

     {

     gi.bprintf (PRINT_HIGH, "The vote is over.\n");

     level.vote_active = false;

     return;

     }

     for(i=1;i<=maxclients->value;i++)

     {

     if ((player= &g_edicts[i]) &&player->inuse)

     numplayers++;

     }

     if ((sv_votepercent) && (level.vote_number >numplayers*(sv_votepercent->value/100)))

     {

     level.vote_active = false;

     // Vote Achieved

     gi.bprintf (PRINT_HIGH, "Vote Achieved. Warping %s.\n", level.vote_nextmap);

     strcpy (level.nextmap,level.vote_nextmap);

     EndDMLevel ();

     }

     remaining = level.vote_time - level.time;

     if (remaining == 5)

     gi.bprintf (PRINT_HIGH, "5 seconds left on vote. %i votes, %i needed\n",
     level.vote_number,(int)numplayers*(sv_votepercent->value/100));

     if (remaining == 10)

     gi.bprintf (PRINT_HIGH, "10 seconds left on vote. %i votes, %i needed\n",
     level.vote_number,(int)numplayers*(sv_votepercent->value/100));

     if (remaining == 20)

     gi.bprintf (PRINT_HIGH, "20 seconds left on vote. %i votes, %i needed\n",
     level.vote_number,(int)numplayers*(sv_votepercent->value/100));

     }