home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / qvote27 / vote.qc < prev    next >
Encoding:
Text File  |  1996-08-20  |  5.5 KB  |  182 lines

  1. // I don't like prototyping.
  2.  
  3. float noexitdefault = 1;
  4. float teamsdefault = 0;
  5.  
  6. float numplayers;
  7. float exitTotal;    // don't laugh, there are no arrays or lists in QuakeC
  8. float noexitTotal;
  9. float teamtotal;
  10. float noteamtotal;
  11. float noexitvotetotal;
  12. float noteamvotetotal;
  13.  
  14. /*************************************************************************/
  15. // CountVotes - Self Explanatory
  16. void() countvotes =                          
  17. {
  18. local string temps;
  19. local entity ent;
  20.  
  21.  exitTotal=0;
  22.  noexitTotal=0;
  23.  teamtotal=0;
  24.  noteamtotal=0;
  25.  noexitvotetotal=0;
  26.  noteamvotetotal=0;
  27.  
  28.  ent = find(world,classname,"player");
  29.  
  30.  while (ent != world)
  31.   {
  32.    if (ent.noexitvote == 1)
  33.     noexitTotal=noexitTotal + 1;
  34.    else if (ent.noexitvote == 0)
  35.     exitTotal=exitTotal + 1;
  36.    else
  37.     noexitvotetotal=noexitvotetotal + 1;
  38.  
  39.    if (ent.teamplayvote == 1)
  40.     teamtotal=teamtotal + 1;
  41.    else if (ent.teamplayvote == 0)
  42.     noteamtotal=noteamtotal + 1;
  43.    else
  44.     noteamvotetotal=noteamvotetotal + 1;
  45.  
  46.   ent = find(ent,classname,"player");
  47.   }
  48.  
  49.  
  50.  if ( teamtotal > (noteamtotal + noteamvotetotal))    //check for majority
  51.   cvar_set("teamplay","1");                           //if none (tie), do
  52.  else if ( noteamtotal > (teamtotal + noteamvotetotal))  //nothing.
  53.   cvar_set("teamplay","0");
  54.  
  55.  if (exitTotal > (noexitTotal + noexitvotetotal))
  56.   cvar_set("noexit","0");
  57.  else if (noexitTotal > (exitTotal + noexitvotetotal))
  58.   cvar_set("noexit","1");
  59.  
  60.  temps = ftos(noexitdefault);
  61.  if ((exitTotal + noexitTotal) == 0)  //until someone votes, set to defaults.
  62.   cvar_set("noexit",temps);
  63.  temps = ftos(teamsdefault);
  64.  if ((teamtotal + noteamtotal) == 0)
  65.   cvar_set("teamplay",temps);
  66.  
  67.  numplayers=exitTotal+noexitTotal+noexitvotetotal; // not implemented
  68.  
  69. }; //countvotes
  70.  
  71.  
  72. /*************************************************************************/
  73. //VoteStats - Show vote stats
  74. void(entity self) votestats =
  75.         {
  76.  local string tempstr;
  77.  
  78.          countvotes();
  79.  
  80.          sprint(self, "Allow level exit : ");
  81.          tempstr = ftos(exitTotal);    // sprint(self,ftos(exitTotal)) doesnt 
  82.          sprint(self, tempstr);        // seem to work.
  83.          sprint(self, "\n");
  84.          sprint(self, "Disallow level exit : ");
  85.          tempstr = ftos(noexitTotal);
  86.          sprint(self, tempstr);
  87.          sprint(self, "\n");
  88.  
  89.          sprint(self, "Allow Friendly Fire : ");
  90.          tempstr = ftos(noteamtotal);  
  91.          sprint(self, tempstr);       
  92.          sprint(self, "\n");
  93.          sprint(self, "Disallow Friendly Fire : ");
  94.          tempstr = ftos(teamtotal);
  95.          sprint(self, tempstr);
  96.          sprint(self, "\n");
  97.  
  98.         };
  99.  
  100. /************************************************************************/
  101. // VoteExitYes - Vote for noexit = 0
  102. void(entity self) voteexityes =
  103.       {
  104.        self.noexitvote = 0;
  105.        countvotes();
  106.       };
  107.  
  108. /************************************************************************/
  109. //VoteExitNo - Vote for noexit = 1
  110. void(entity self) voteexitno =
  111.       {
  112.        self.noexitvote = 1;
  113.        countvotes();
  114.       };
  115. /********************************************************************/
  116. // VoteTeamsNo - Vote for teamplay = 0
  117. void(entity self) voteteamsno =
  118.       {
  119.        self.teamplayvote = 0;
  120.        countvotes();
  121.       };
  122.  
  123. /************************************************************************/
  124. // VoteTeamsYes - Vote for teamplay = 1
  125. void(entity self) voteteamsyes =
  126.       {
  127.        self.teamplayvote = 1;
  128.        countvotes();
  129.       };
  130.  
  131. /************************************************************************/
  132.  
  133. // RegVoter - Add new player to the voting booth.
  134. void(entity self) regvoter =
  135. {
  136.  
  137. self.noexitvote = 666;
  138. self.teamplayvote = 666;
  139. countvotes();
  140.  
  141. };  // regvoter
  142.  
  143. /***********************************************************************/
  144. //VoteHelp - display command help
  145. void() votehelp =
  146. {
  147.  sprint(self,"VoteStats : See voting status\nVoteExit : Vote for noexit = 0\nVoteNoExit : Vote for noexit = 1\nVoteTeams : Vote for teamplay = 1\nVoteNoTeams : Vote for teamplay = 0\n");
  148. };
  149. /***********************************************************************/
  150. //VoteAliases - alias the impulse commands for user friendliness.
  151. //FIXME:find a better place to call this.
  152. //Note to QuakeC coders : this function doesn't seem to work when I do
  153. // it as votealiases(entity self), which I like to do, even though it's
  154. // unnecessary, just because it's logical. All the others seem to work
  155. // whichever way I do them, but this one, when written and called as
  156. // votealias(self), compiles, but on runtime gives some error "unknown
  157. // command 'ishedalias'" (finishedalias?), which makes no sense.  If
  158. // you can enlighten me, please do. (flame@pacbell.net)
  159. void() votealiases =
  160. {
  161.  stuffcmd(self,"alias votestats \"impulse 12\"\n");
  162.  stuffcmd(self,"alias votenoexit \"impulse 14\"\n");
  163.  stuffcmd(self,"alias voteexit \"impulse 13\"\n");
  164.  stuffcmd(self,"alias voteteams \"impulse 16\"\n");
  165.  stuffcmd(self,"alias votenoteams \"impulse 17\"\n");
  166.  stuffcmd(self,"alias votehelp \"impulse 18\"\n");
  167.  stuffcmd(self,"alias vote \"impulse 18\"\n");
  168.  
  169. // votehelp();
  170.  
  171. };
  172. /***************************************************************************/
  173. //ConnectMessage - display a message on connect.
  174. void() connectmessage =
  175. {
  176.  
  177.  sprint(self,"This server is running Qvote v2.7, by Lunatik (flame@pacbell.net)\nServer settings Noexit and Teamplay can now be set democratically, via the following commands : \n");
  178.  votealiases();
  179.  votehelp();
  180.  
  181. };
  182.