LucasRed

VoteSystem #brdms

Jan 25th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.40 KB | None | 0 0
  1. /*
  2.     VoteSystem Evolution Death-Match...
  3.     Feito pelo roludo do Lucas!
  4.     Esta porra deve ser ajustada de acordo com o server de quem quiser usar.
  5. */
  6. VoteStarted <- false;
  7. VoteText    <- null;
  8. VoteY       <- 0;
  9. VoteN       <- 0;
  10. VoteTime    <- 0;
  11. VoteList    <- {};
  12.  
  13. function onScriptLoad()
  14. {
  15.     N <- BindKey( true, 0x4E, 0, 0 );
  16.     Y <- BindKey( true, 0x59, 0, 0 );
  17. }
  18.  
  19. function onPlayerJoin( player )
  20. {
  21.     VoteList.rawset( player.ID, "none" );
  22. }
  23.  
  24. function onPlayerPart( player, reason )
  25. {
  26.     VoteList.rawdelete( player.ID );
  27. }
  28.  
  29. function onKeyDown( player, key )
  30. {
  31.     if ( key == N )
  32.     {
  33.         if ( VoteStarted )
  34.         {
  35.             switch ( VoteList[ player.ID ] )
  36.             {
  37.                 case "yes":
  38.                     VoteY > 0 ? VoteY -- : false;
  39.                     VoteN ++;
  40.                     VoteList.rawset( player.ID, "no" );
  41.                     _PrivMessage( player, "Certo, voce alterou seu voto.", "Okay, you've changed your vote." );
  42.                 break;
  43.  
  44.                 case "none":
  45.                     VoteN ++;
  46.                     VoteList.rawset( player.ID, "no" );
  47.                     _PrivMessage( player, "Feedback computado!", "Feedback computed." );
  48.                 break;
  49.                 default: break;
  50.             }
  51.         }
  52.     }
  53.  
  54.     else if ( key == Y )
  55.     {
  56.         if ( VoteStarted )
  57.         {
  58.             switch ( VoteList[ player.ID ] )
  59.             {
  60.                 case "no":
  61.                     VoteY ++;
  62.                     VoteN > 0 ? VoteN -- : false;
  63.                     VoteList.rawset( player.ID, "yes" );
  64.                     _PrivMessage( player, "Certo, voce alterou seu voto.", "Okay, you've changed your vote." );
  65.                 break;
  66.  
  67.                 case "none":
  68.                     VoteY ++;
  69.                     VoteList.rawset( player.ID, "yes" );
  70.                     _PrivMessage( player, "Feedback computado!", "Feedback computed." );
  71.                 break;
  72.                 default: break;
  73.             }
  74.         }
  75.     }
  76. }
  77.  
  78. function Result() // Parte do VoteSystem
  79. {
  80.     local y_calc, n_calc;
  81.     _AnnounceAll( "Tempo esgotado!", "Time is over!" ,1 );
  82.     _Message( "[#DCDCDC]Resultado da votacao:", "[#DCDCDC]Result of the vote:" );
  83.     pIRC_Message( "14Resultado da votação:" );
  84.     /*Message( "[#DCDCDC]- Positivos: [#FF0000]" + VoteY + "[#DCDCDC](" + ( !VoteY ? "0" : ( 100 - ( ( VoteN.tofloat() / VoteY ) * 100 ) ) ) + "%)" );
  85.     Message( "[#DCDCDC]- Negativos: [#FF0000]" + VoteN + "[#DCDCDC](" + ( !VoteN ? "0" : ( 100 - ( ( VoteY.tofloat() / VoteN ) * 100 ) ) ) + "%)" );
  86.     pIRC_Message( "14- Positivos:4 " + VoteY + "14(" + ( !VoteY ? "0" : ( 100 - ( ( VoteN.tofloat() / VoteY ) * 100 ) ) ) + "%)" );
  87.     pIRC_Message( "14- Negativos:4 " + VoteN + "14(" + ( !VoteN ? "0" : ( 100 - ( ( VoteY.tofloat() / VoteN ) * 100 ) ) ) + "%)" );*/
  88.  
  89.     if ( VoteY == VoteN && VoteY > 0 ) y_calc = "50", n_calc = "50";
  90.     else if ( VoteY > VoteN ) y_calc = ( !VoteY ? "0" : ( 100 - ( ( VoteN.tofloat() / VoteY ) * 100 ) ) ), n_calc = ( !VoteN ? "0" : ( ( VoteN.tofloat() / VoteY ) * 100 ) );
  91.     else y_calc = ( !VoteY ? "0" : ( ( VoteY.tofloat() / VoteN ) * 100 ) ), n_calc = ( !VoteN ? "0" : ( 100 - ( VoteY.tofloat() / VoteN ) * 100 ) );
  92.  
  93.     Message( "[#DCDCDC]- Positivos: [#FF0000]" + VoteY + "[#DCDCDC](" + y_calc + "%)" );
  94.     Message( "[#DCDCDC]- Negativos: [#FF0000]" + VoteN + "[#DCDCDC](" + n_calc + "%)" );
  95.     pIRC_Message( "14- Positivos:4 " + VoteY + "14(" + y_calc + "%)" );
  96.     pIRC_Message( "14- Negativos:4 " + VoteN + "14(" + n_calc + "%)" );
  97.     // Zerar tudo, assim que a votação for encerrada.
  98.     VoteStarted = false;
  99.     VoteText = null;
  100.     VoteY = 0;
  101.     VoteN = 0;
  102.     foreach ( idx, val in VoteList ) VoteList.rawset( idx, "none" );
  103. }
  104.  
  105. function VoteClock()
  106. {
  107.     _AnnounceAll( format( "Termina em " + VoteTime + " segundo%s...", VoteTime == 1 ? "" : "s" ), format( "Ends in " + VoteTime + " second%s...", VoteTime == 1 ? "" : "s" ), 1 );
  108.     VoteTime --;
  109. }
  110.  
  111. function onPlayerCommand( player, cmd, text )
  112. {
  113.     if ( cmd == "vote" )
  114.     {
  115.         if ( PlayerInfo( player, cmd ) ) return 0;
  116.         else if ( !text ) SMsg( "/" + cmd + " <texto/off>.", "/" + cmd + " <text/off>.", player );
  117.         else
  118.         {
  119.             if ( text == "off" )
  120.             {
  121.                 if ( !VoteStarted ) EMsg( "Nenhum voto em progresso.", "No vote in progress." player );
  122.                 else
  123.                 {
  124.                     VoteStarted = false;
  125.                     VoteText = null;
  126.                     VoteY != 0 ? VoteY = 0 : false;
  127.                     VoteN != 0 ? VoteN = 0 : false;
  128.                     VoteTime = 0;
  129.                     _Timer.Destroy( _Result );
  130.                     _Timer.Destroy( _VoteClock );
  131.                     _Message( "[#9B30FF]* Admin. [#B5B5B5]" + player.Name + " [#9B30FF]encerrou a votacao.", "[#9B30FF]* Admin. [#B5B5B5]" + player.Name + " [#9B30FF]closed the poll." );
  132.                     pIRC_Message( "6* Admin.14 " + player.Name + " 6encerrou a votação." );
  133.                    
  134.                 }
  135.             }
  136.             else
  137.             {
  138.                 if ( VoteStarted ) EMsg( "Uma votacao esta em andamento.", "There is a vote in progress.", player );
  139.                 else
  140.                 {
  141.                     VoteStarted = true;
  142.                     VoteText = text;
  143.                     VoteTime = 29;
  144.                     _Message( "[#9B30FF]* Admin. [#B5B5B5]" + player.Name + " [#9B30FF]iniciou uma votacao.", "[#9B30FF]* Admin. [#B5B5B5]" + player.Name + " [#9B30FF]started a poll." );
  145.                     _Message( "[#DCDCDC]~ " + text + " ~\nPressione [#00FF00]\"Y\" [#DCDCDC]para votar sim ou [#FF0000]\"N\" [#DCDCDC]para votar nao.", "[#DCDCDC]~ " + text + " ~\nPress [#00FF00]\"Y\" [#DCDCDC]to vote yes or [#FF0000]\"N\" [#DCDCDC]to vote no." );
  146.                     _AnnounceAll( "Termina em " + VoteTime + " segundos...", "Ends in " + VoteTime + " seconds...", 1 );
  147.                     pIRC_Message( "6* Admin.14 " + player.Name + " 6iniciou uma votação." );
  148.                     pIRC_Message( "14~ " + text + " ~" );
  149.                     pIRC_Message( "14Pressione 3\"Y\" 14para votar sim ou 4\"N\" 14para votar não." );
  150.                     _Result <- _Timer.Create( this, Result, 30000, 1 );
  151.                     _VoteClock <- _Timer.Create( this, VoteClock, 1000, VoteTime );
  152.                 }
  153.             }
  154.         }
  155.     }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment