Advertisement
SoulOfSet

Multimode Vote

Jun 18th, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.08 KB | None | 0 0
  1. #!/usr/bin/php
  2.     <?php
  3.         //Vote Control
  4.         $playersVotedYes;
  5.         $playersVotedNo;
  6.         $numPlayersVoteYes;
  7.         $numPlayersVoteNo;
  8.         $voteInSession = false;
  9.         $voteSessionTime = 20; //In Seconds
  10.         $command;
  11.         $willInclude = false;
  12.         //Time Tracker
  13.         //$gameTimeCurr = 0;
  14.         //$gameTimeVoteEnd = -1;
  15.         //File Includes
  16.         $teamsumo = "include teamsumo.cfg \n";
  17.         $fort = "include fort.cfg \n";
  18.         $hr = "include hr.cfg \n";
  19.         $df = "include df.cfg \n";
  20.         //Files Array
  21.         $filesToInclude = array($teamsumo, $fort, $hr, $df);
  22.         $filesToIncludeStrings = array("teamsumo", "fort", "hr", "df");
  23.        
  24.         //Function To Start The Voting Session And Determines The Length Of The Session
  25.             while(1)
  26.                 {
  27.                     $input = rtrim(fgets(STDIN, 1024));
  28.                     $param = explode(" ", $input);
  29.                    
  30.                     //Keep Track Of Time   
  31.                     if (preg_match("/^GAME_TIME/", $input))
  32.                         {
  33.                             $gameTimeCurr = $param[1];
  34.                         }
  35.                    
  36.                     //Ends The Voting Sessions And Determines Outcome
  37.                     if ($gameTimeVoteEnd == $gameTimeCurr && $voteInSession == true);
  38.                         {
  39.                             $voteInSession = false;
  40.                             $numPlayersVoteYes = count($playersVotedYes);
  41.                             $numPlayersVoteNo = count($playersVotedNo);
  42.                             //Do Or Not Do?
  43.                             if ($numPlayersVoteYes > $numPlayersVoteNo) //The Vote Has Been Accepted
  44.                                 {
  45.                                     $willInclude = true;
  46.                                     print("console_message Vote Accepted! Config will be included at
  47.                                         the end of the round! \n");
  48.                                 }
  49.                             elseif ($numPlayersVoteYes == $numPlayersVoteNo) //The Vote Tied
  50.                                 {
  51.                                     print("console_message The vote has tied. No action will be taken.\n");
  52.                                 }
  53.                             else //The Vote Was Denied
  54.                                 {
  55.                                     print("console_message The vote was denied. No action will be taken.\n");
  56.                                 }
  57.                             $gameTimeVoteEnd = -1;
  58.                             unset($numPlayersVoteYes);
  59.                             unset($numPlayersVoteNo);
  60.                         }
  61.                        
  62.                     //Include It When The Round Ends
  63.                     if (preg_match("/^ROUND_COMMENCING/", $input) && $willInclude == true)
  64.                         {
  65.                             print($command);
  66.                             $willInclude = false;
  67.                         }
  68.                        
  69.                     //Voting Control
  70.                     if (preg_match("/^INVALID_COMMAND/", $input))
  71.                         {
  72.                             if ($param[1] == "/chmode" && $voteInSession == false)
  73.                                 {
  74.                                     $voteOwner = $param[2];
  75.                                     $voteType = $param[5];
  76.                                     if (in_array($param[5], $filesToIncludeStrings))
  77.                                         {
  78.                                             $voteInSession = true;
  79.                                             if ($voteType == "teamsumo") {$command = $teamsumo;}
  80.                                             elseif ($voteType == "fort") {$command = $fort;}
  81.                                             elseif ($voteType == "hr") {$command = $hr;}
  82.                                             elseif ($voteType == "df") {$command = $df;}
  83.                                             array_push($playersVotedYes, $voteOwner); //The Person Who Called Vote Needs A Yes
  84.                                             $gameTimeVoteEnd = $gameTimeCurr + $voteSessionTime;
  85.                                             print("console_message A vote has been cast for {$voteType}. Please vote /yes or /no
  86.                                             in your chat! \n");
  87.                                         }
  88.                                     else
  89.                                         {
  90.                                             print("console_message Please enter a valid mode. Type /modes for
  91.                                                 a list! \n");
  92.                                         }
  93.                                 }
  94.                             elseif ($param[1] == "/chmode" && $voteInSession == true)
  95.                                 {
  96.                                    
  97.                                     print("console_message A vote is already in session. Type /yes or /no
  98.                                         to vote on it \n");
  99.                                 }
  100.                             elseif ($param[1] == "/yes" && $voteInSession == true)
  101.                                 {
  102.                                     if (!in_array($param[2], $playersVotedYes) &&
  103.                                         !in_array($param[2], $playersVotedNo))
  104.                                             {
  105.                                                 $playersVotedYes[] = $param[2];
  106.                                                 print("player_message {$param[2]} \"Your vote has been casted!\" \n");
  107.                                             }
  108.                                     else
  109.                                         {
  110.                                             print("player_message {$param[2]} \"You've already cast your vote\" \n");
  111.                                         }
  112.                                 }
  113.                             elseif ($param[1] == "/no" && $voteInSession == true)
  114.                                 {
  115.                                     if (!in_array($param[2], $playersVotedYes) &&
  116.                                         !in_array($param[2], $playersVotedNo))
  117.                                             {
  118.                                                 $playersVotedNo[] = $param[2];
  119.                                                 print("player_message {$param[2]} \"Your vote has been casted!\" \n");
  120.                                             }
  121.                                     else
  122.                                         {
  123.                                             print("player_message {$param[2]} \"You've already voted!\" \n");
  124.                                         }
  125.                                 }
  126.                             //No Vote In Progress
  127.                             elseif ($param[1] == "/yes" && $voteInSession == false)
  128.                                 {
  129.                                     print("player_message {$param[2]} \"There is no vote in progress.
  130.                                         Type /chmode modehere to start a vote! Type /list for the available modes!\" \n");
  131.                                 }
  132.                             elseif ($param[1] == "/no" && $voteInSession == false)
  133.                                 {
  134.                                     print("player_message {$param[2]} \"There is no vote in progress.
  135.                                         Type /chmode modehere to start a vote! Type /list for the available modes!\" \n");
  136.                                 }
  137.                             //List The Modes
  138.                             elseif ($param[1] == "/list")
  139.                                 {
  140.                                     foreach (filesToIncludeStrings as $value)
  141.                                         {
  142.                                             print("player_message {$param[2]} \"0xff0010{$value}\" \n");
  143.                                         }
  144.                                 }
  145.                             else
  146.                                 {
  147.                                     print("player_message {$param[2]} \"Command does not exist!\" \n");
  148.                                 }
  149.                         }
  150.  
  151.                 }
  152.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement