Advertisement
Syky

Vote System

Feb 13th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. //////////////////////////////////////////////////////////////////////////////// VOTE SYSTEM
  2. local Vote = 0;
  3. local VoteTime = 10000; // (10 seconds currently)
  4. local IfVote = array(MAX_PLAYERS, 0);
  5. local YES = 0; //not working
  6. local NO = 0; //not working
  7. //////////////////////////////////////////////////////////////////////////////// /vote
  8. addCommandHandler( "vote",
  9.      
  10.     function( playerid, ... )  
  11. {
  12.     if(vargv.len() > 1)
  13. {
  14.     local msg = "";
  15.     for (local i = 0; i < vargv.len(); i++)
  16. {
  17.     msg = msg + " " + vargv[i];
  18. }    
  19. {
  20.     if( Vote == 0 )
  21.     { //IF VOTE NOT RUNNING
  22.     sendPlayerMessageToAll( "[Server]: " + getPlayerName( playerid ) + " started a Vote!", 255, 255, 0 );
  23.     sendPlayerMessageToAll( "[Server]: Question: " + msg, 51,204,153 );  
  24.     sendPlayerMessageToAll( "[Server]: Answer /y for YES or /n for NO.", 255, 255, 0 );
  25.     Vote = 1;
  26.      
  27.     timer( function() {
  28.     Vote = 0;
  29.     sendPlayerMessageToAll( "[Server]: Voting is closed", 255, 255, 0 );
  30.     sendPlayerMessageToAll( "[Server]: Results: " + "YES: " +YES + " NO: " +NO, 51,204,153 );
  31.     YES = 0;
  32.     NO = 0;
  33.     IfVote = 0;
  34. },  VoteTime, 1
  35. );
  36. }
  37. else
  38.     if( Vote == 1 ) {
  39.     sendPlayerMessage( playerid, "[Server]: Any Vote already running", 255, 0, 0 );
  40. }
  41. }
  42. }
  43. }
  44. );
  45. //////////////////////////////////////////////////////////////////////////////// YES
  46. addCommandHandler( "y",
  47.     function( playerid )
  48.     if( Vote == 1 ) {
  49.     sendPlayerMessage( playerid, "[Server]: Thanks for your vote", 255, 255, 0 );
  50.     YES = 1; // I changing only to 1. :/
  51.     IfVote[playerid] = 1;
  52. }
  53. else
  54.     if( Vote == 0 ) {
  55.     sendPlayerMessage( playerid, "[Server]: There's no Vote active!", 255, 0, 0 ); 
  56.     if( IfVote == 1 ) {
  57.     sendPlayerMessage( playerid, "[Server]: You already voted!", 255, 0, 0 ); //not working.... nah.. :(
  58. }
  59. }
  60. );
  61. //////////////////////////////////////////////////////////////////////////////// NO
  62. addCommandHandler( "n",
  63.     function( playerid )   
  64.     if( Vote == 1 ) {
  65.     sendPlayerMessage( playerid, "[Server]: Thanks for your vote", 255, 255, 0 );
  66.     NO = 1; //Same here :/
  67.     IfVote[playerid] = 1;
  68. }
  69. else
  70.     if( Vote == 0 ) {
  71.     sendPlayerMessage( playerid, "[Server]: There's no Vote active!", 255, 0, 0 ); 
  72.     if( IfVote == 1 ) {
  73.     sendPlayerMessage( playerid, "[Server]: You already voted!", 255, 0, 0 ); //same not working... grrr
  74.     }
  75.     }
  76. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement