Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- VoteSystem
- Developed by: Lucas
- Credits: Matheus/Takanaue (I did nothing but I'm here)
- */
- VoteStarted <- false;
- VoteText <- null;
- VoteY <- 0;
- VoteN <- 0;
- VoteTime <- 0;
- VoteList <- {};
- function onScriptLoad()
- {
- N <- BindKey( true, 0x4E, 0, 0 );
- Y <- BindKey( true, 0x59, 0, 0 );
- }
- function onPlayerJoin( player )
- {
- VoteList.rawset( player.ID, "none" );
- }
- function onPlayerPart( player, reason )
- {
- VoteList.rawdelete( player.ID );
- }
- function onKeyDown( player, key )
- {
- if ( key == N )
- {
- if ( VoteStarted )
- {
- switch ( VoteList[ player.ID ] )
- {
- case "yes":
- VoteY > 0 ? VoteY -- : false;
- VoteN ++;
- VoteList.rawset( player.ID, "no" );
- PrivMessage( player, "Okay, you've changed your vote." );
- break;
- case "none":
- VoteN ++;
- VoteList.rawset( player.ID, "no" );
- PrivMessage( player, "Feedback computed." );
- break;
- default: break;
- }
- }
- }
- else if ( key == Y )
- {
- if ( VoteStarted )
- {
- switch ( VoteList[ player.ID ] )
- {
- case "no":
- VoteY ++;
- VoteN > 0 ? VoteN -- : false;
- VoteList.rawset( player.ID, "yes" );
- PrivMessage( player, "Okay, you've changed your vote." );
- break;
- case "none":
- VoteY ++;
- VoteList.rawset( player.ID, "yes" );
- PrivMessage( player, "Feedback computed." );
- break;
- default: break;
- }
- }
- }
- }
- function Result()
- {
- local y_calc, n_calc;
- AnnounceAll( "The time is over!" ,1 );
- Message( "[#DCDCDC]Result of the votes:" );
- if ( VoteY == VoteN && VoteY > 0 ) y_calc = "50", n_calc = "50";
- else if ( VoteY > VoteN ) y_calc = ( !VoteY ? "0" : ( 100 - ( ( VoteN.tofloat() / VoteY ) * 100 ) ) ), n_calc = ( !VoteN ? "0" : ( ( VoteN.tofloat() / VoteY ) * 100 ) );
- else y_calc = ( !VoteY ? "0" : ( ( VoteY.tofloat() / VoteN ) * 100 ) ), n_calc = ( !VoteN ? "0" : ( 100 - ( VoteY.tofloat() / VoteN ) * 100 ) );
- Message( "[#DCDCDC]- Number of votes yes: [#FF0000]" + VoteY + "[#DCDCDC](" + y_calc + "%)" );
- Message( "[#DCDCDC]- Number of votes no: [#FF0000]" + VoteN + "[#DCDCDC](" + n_calc + "%)" );
- // Resetting the results
- VoteStarted = false;
- VoteText = null;
- VoteY = 0;
- VoteN = 0;
- foreach ( idx, val in VoteList ) VoteList.rawset( idx, "none" );
- }
- function VoteClock()
- {
- AnnounceAll( format( "Ends in " + VoteTime + " second%s...", VoteTime == 1 ? "" : "s" ), 1 );
- VoteTime --;
- }
- function onPlayerCommand( player, cmd, text )
- {
- if ( cmd == "vote" )
- {
- if ( PlayerInfo( player, cmd ) ) return 0;
- else if ( !text ) MessagePlayer( "/" + cmd + " <text/off>.", player );
- else
- {
- if ( text == "off" )
- {
- if ( !VoteStarted ) MessagePlayer( "No vote in progress." player );
- else
- {
- VoteStarted = false;
- VoteText = null;
- VoteY != 0 ? VoteY = 0 : false;
- VoteN != 0 ? VoteN = 0 : false;
- VoteTime = 0;
- _Timer.Destroy( _Result );
- _Timer.Destroy( _VoteClock );
- Message( "[#9B30FF]* Admin. [#B5B5B5]" + player.Name + " [#9B30FF]closed the poll." );
- }
- }
- else
- {
- if ( VoteStarted ) MessagePlayer( "There is a vote in progress.", player );
- else
- {
- VoteStarted = true;
- VoteText = text;
- VoteTime = 29;
- Message( "[#9B30FF]* Admin. [#B5B5B5]" + player.Name + " [#9B30FF]started a poll." );
- Message( "[#DCDCDC]~ " + text + " ~\nPress [#00FF00]\"Y\" [#DCDCDC]to vote yes or [#FF0000]\"N\" [#DCDCDC]to vote no." );
- AnnounceAll( "Ends in " + VoteTime + " seconds...", 1 );
- _Result <- _Timer.Create( this, Result, 30000, 1 );
- _VoteClock <- _Timer.Create( this, VoteClock, 1000, VoteTime );
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement