Code:
#include < amxmodx >
#define task 1264
enum _:g_mCvars
{
g_mEnable,
g_mType,
g_mValue
};
new g_szCvars[ g_mCvars ][ ] =
{
{ "amx_vote_rs_enable", "1" },
{ "amx_vote_rs_type", "1" },
{ "amx_vote_rs_number", "30" }
};
new g_iVotes[ 2 ], g_iVoted[ 33 ], g_iMenu[ 33 ];
new g_iCvars[ g_mCvars ];
new g_iRounds = 0, g_iVoteRunning = 0, g_iRestartRound = 0;
public plugin_init( )
{
register_plugin( "Restart Round Vote", "v1.0", "XControlX" );
register_clcmd( "say /voters", "startRestartVote" );
register_clcmd( "amx_vote_rs", "startRestartVote" );
register_logevent( "EventRoundStart", 2, "1=Round_Start" );
for ( new i = 0; i < g_mCvars; i++ )
g_iCvars[ i ] = register_cvar( g_szCvars[ i ][ 0 ], g_szCvars[ i ][ 1 ] );
set_task( float( get_pcvar_num( g_iCvars[ g_mValue ] ) ), "checkVote", _, _, _, "b" );
}
public startRestartVote( client )
{
if ( ! ( get_user_flags( client ) & ADMIN_KICK ) )
{
client_print( client, print_chat, "You have no access to this command." );
return 1;
}
if ( g_iVoteRunning )
{
client_print( client, print_chat, "A vote is already running !" );
return 1;
}
startVote( );
client_print( 0, print_chat, "%s has started a restart round vote.", GetUserName( client ) );
return 1;
}
public EventRoundStart( )
{
if ( g_iRestartRound )
{
g_iRestartRound = 0;
set_cvar_num( "sv_restart", 1 );
return 1;
}
if ( get_pcvar_num( g_iCvars[ g_mType ] ) != 2 || g_iVoteRunning )
return 1;
g_iRounds += 1;
if ( g_iRounds >= get_pcvar_num( g_iCvars[ g_mValue ] ) )
{
startVote( );
return 1;
}
return 1;
}
public startVote( )
{
g_iRestartRound = 0;
g_iVoteRunning = 1;
new i, j = get_maxplayers( );
for ( i = 0; i < j; i++ )
g_iVoted[ i ] = 0;
for ( i = 0; i < 2; i++ )
g_iVotes[ i ] = 0;
set_task( 1.0, "voteMenu", task, _, _, "b" );
set_task( 10.0, "stopVote" );
}
public voteMenu( )
{
if ( ! g_iVoteRunning )
{
remove_task( task );
return 1;
}
new i, j = get_maxplayers( );
for ( i = 0; i < j; i++ )
{
if ( ! is_user_connected( i ) )
continue;
g_iMenu[ i ] = menu_create( "\rDo you want to restart the round ?", "voteHandler" );
menu_additem( g_iMenu[ i ], "Yes" );
menu_additem( g_iMenu[ i ], "No" );
menu_setprop( g_iMenu[ i ], MPROP_EXIT, MEXIT_NEVER );
menu_display( i, g_iMenu[ i ], 0 );
}
return 1;
}
public voteHandler( client, menu, item )
{
if ( g_iVoted[ client ] ) return 1;
g_iVotes[ item ] += 1;
g_iVoted[ client ] = 1;
client_print( 0, print_chat, "%s has just voted ^"%s^"", ! item ? "yes" : "no" );
return 1;
}
public stopVote( )
{
for ( new i = 0; i < get_maxplayers( ); i++ )
{
if ( ! is_user_connected( i ) )
continue;
menu_destroy( g_iMenu[ i ] );
}
g_iVoteRunning = 0;
g_iRounds = 0;
if ( g_iVotes[ 1 ] > g_iVotes[ 0 ] || g_iVotes[ 1 ] == g_iVotes[ 0 ] )
{
client_print( 0, print_chat, "The most votes are to yes! next round the round will restart." );
g_iRestartRound = 1;
return 1;
}
client_print( 0, print_chat, "The vote has failed." );
return 1;
}
public checkVote( )
{
if ( get_pcvar_num( g_iCvars[ g_mType ] ) != 1 || g_iVoteRunning )
return 1;
startVote( );
return 1;
}
stock GetUserName( const index )
{
new name[ 32 ];
get_user_name( index, name, charsmax( name ) );
return name;
}