You told me once that that parameter is not needed, but whatever.
Code:
#include <amxmodx>
#include <amxmisc>
#define VERSION "1.0"
new const Teams[ 2 ][] =
{
"Terrorists",
"Counter-Terrorists"
}
new p_Deaths, p_Team, p_HUD, p_MaxMaps;
new mapsFile[ 62 ], Maps[ 50 ][ 25 ];
new g_iDeaths, g_iVotes[ 50 ], g_iMaxPlayers, g_iMapCount = 0;
new bool:g_bVoted[ 33 ];
public plugin_precache()
{
get_configsdir( mapsFile, charsmax( mapsFile ) );
format( mapsFile, charsmax( mapsFile ), "%s/maps.ini", mapsFile );
/* Taken from Map Menu */
if( !file_exists( mapsFile ) )
get_cvar_string( "mapcyclefile", mapsFile, charsmax( mapsFile ) );
if( !file_exists( mapsFile ) )
format( mapsFile, charsmax( mapsFile ), "mapcycle.txt" );
}
public plugin_init()
{
register_plugin( "Map Vote After X Kills", VERSION, "Dores" );
p_Deaths = register_cvar( "mvak_deaths", "20" );
p_HUD = register_cvar( "mvak_hud", "1" );
p_MaxMaps = register_cvar( "mvak_max_maps", "5" );
p_Team = register_cvar( "mvak_team", "1" ); // 1 = Terrorist, 2 = CT, 0 = plugin off.
g_iMaxPlayers = get_maxplayers();
register_event( "DeathMsg", "ev_Death", "a" );
if( !loadMaps() )
{
server_print( "[AMXX]: Can't retrieve maps from file! Turning ^"Map Vote After X Kills^" plugin OFF!" );
return;
}
}
public ev_Death()
{
static iVic ; iVic = read_data( 2 );
static team ; team = get_user_team( iVic );
if( team != get_pcvar_num( p_Team ) )
return PLUGIN_CONTINUE;
new pcvar = get_pcvar_num( p_Deaths );
if( pcvar - ++g_iDeaths <= 0 )
{
g_iDeaths = 0;
startMapVote();
return PLUGIN_CONTINUE;
}
if( get_pcvar_num( p_HUD ) && team == get_pcvar_num( p_Team ) )
{
set_hudmessage( 255, 0, 0, 0.8, 0.28, 0, 6.0, 12.0 );
show_hudmessage( 0, "%s deaths left before map voting: %d", Teams[ team - 1 ], pcvar - g_iDeaths );
}
return PLUGIN_CONTINUE;
}
public startMapVote()
{
new menu = menu_create( "Map Vote", "mapVoteMenu_Handler" );
new i, iValue[ 3 ];
for( i = 0 ; i < g_iMapCount ; i++ )
{
format( iValue, charsmax( iValue ), "%d", ( i + 1 ) );
// Also tried: num_to_str( ( i + 1 ), iValue, charsmax( iValue ) ).
menu_additem( menu, Maps[ i ], iValue );
}
menu_setprop( menu, MPROP_EXIT, MEXIT_ALL );
for( i = 1 ; i <= g_iMaxPlayers ; i++ )
{
if( is_user_connected( i ) )
{
menu_display( i, menu );
}
}
return 1;
}
public mapVoteMenu_Handler( menu, id, item )
{
if( item == MENU_EXIT )
{
g_bVoted[ id ] = true;
menu_destroy( menu );
return PLUGIN_HANDLED;
}
new _access, name[ 32 ], callback;
new pressed[ 5 ], map = 0;
menu_item_getinfo( menu, item, _access, pressed, charsmax( pressed ), name, charsmax( name ), callback );
map = str_to_num( pressed ); // First map starts at Maps[0] and not 1, so we need to substract 1 from the pressed key.
g_iVotes[ map - 1 ]++;
g_bVoted[ id ] = true;
new bool:bAllVoted = true;
for( new i = 1 ; i <= g_iMaxPlayers ; i++ )
{
if( !is_user_connected( i ) )
{
g_bVoted[ i ] = true;
continue;
}
if( !g_bVoted[ i ] )
bAllVoted = false;
}
if( bAllVoted )
{
new best;
for( new i = 0 ; i < g_iMapCount ; i++ )
{
if( g_iVotes[ i ] > g_iVotes[ best ] )
{
best = i;
}
}
client_print( 0, print_chat, "[AMXX]: Map Voting has ended!" );
client_print( 0, print_chat, "Map chosen: %s Votes for it: %d", Maps[ best ], g_iVotes[ best ] );
client_print( 0, print_chat, "Changing map!" );
set_task( 2.0, "mapChange", best );
}
menu_destroy( menu );
return PLUGIN_HANDLED;
}
public mapChange( map )
{
server_cmd( "changelevel %s", Maps[ map ] );
}
public server_changelevel( map[] )
{
for( new i = 1 ; i <= g_iMaxPlayers ; i++ )
{
if( g_bVoted[ i ] )
{
g_bVoted[ i ] = false;
}
}
for( new i = 0 ; i < g_iMapCount ; i++ )
{
if( g_iVotes[ i ] )
{
g_iVotes[ i ] = 0;
}
}
}
loadMaps()
{
new Map[ 25 ], line = 0, txtlen, size;
size = file_size( mapsFile, 1 );
new bool:bUsedLine[ 50 ], bool:bUsedAll = true;
while( line < size )
{
for( new i = 0 ; i < size ; i++ )
{
if( !bUsedLine[ i ] )
bUsedAll = false;
}
if( bUsedAll )
break;
do
{
line = random( size );
}
while( bUsedLine[ line ] );
bUsedLine[ line ] = true;
read_file( mapsFile, line, Map, charsmax( Map ), txtlen );
if( !txtlen || Map[ 0 ] == ';' )
continue;
format( Maps[ g_iMapCount++ ], charsmax( Maps[] ), "%s", Map );
if( g_iMapCount == get_pcvar_num( p_MaxMaps ) )
break;
}
if( !g_iMapCount )
return 0;
return 1;
}