Raised This Month: $ Target: $400
 0% 

Very weird 'index out of bounds' error.


Post New Thread Reply   
 
Thread Tools Display Modes
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 01-03-2009 , 15:56   Re: Very weird 'index out of bounds' error.
Reply With Quote #11

Thanks all - Exolent, Emp' and danielkza.
I just got confused and thought that info is the number of the item(that appears near the item in the menu).
Thanks!

EDIT:
I've debugged the plugin, and it always prints: "Why is it always 0?!", which means that the map variable is always 0 no matter what I chose from the menu:
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, p_VoteTime; new mapsFile[ 62 ], Maps[ 50 ][ 25 ]; new g_iDeaths, g_iVotes[ 50 ], g_iMaxPlayers, g_iMapCount = 0; new bool:g_bVoted[ 33 ], bool:g_bVoting; 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_VoteTime = register_cvar( "mvak_vote_time", "60" );     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 )     {         if( !g_bVoting )         {             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 );         if( !g_bVoting )         {             show_hudmessage( 0, "%s deaths left before map voting: %d", Teams[ team - 1 ], pcvar - g_iDeaths );         }                 else         {             show_hudmessage( 0, "Still choosing a map!" );         }     }         return PLUGIN_CONTINUE; } public startMapVote() {     new menu = menu_create( "Map Vote", "mapVoteMenu_Handler" );         new i, szValue[ 3 ];     for( i = 0 ; i < g_iMapCount ; i++ )     {         num_to_str( i, szValue, charsmax( szValue ) );         menu_additem( menu, Maps[ i ], szValue );     }         menu_setprop( menu, MPROP_EXIT, MEXIT_ALL );         for( i = 1 ; i <= g_iMaxPlayers ; i++ )     {         if( is_user_connected( i ) )         {             menu_display( i, menu );         }     }         g_bVoting = true;     set_task( float( get_pcvar_num( p_VoteTime ) ), "endVote", 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, callback;     new pressed[ 3 ];     menu_item_getinfo( menu, item, _access, pressed, charsmax( pressed ), _, _, callback );     new map = str_to_num( pressed );     if( map == 0 )     {         client_print( 1, print_chat, "Why is it always 0?!" );     }     g_iVotes[ map ]++;     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 )     {         voteEnd();     }         menu_destroy( menu );     return PLUGIN_HANDLED; } public endVote( menu ) {     if( !g_bVoting )         return;         voteEnd(); } 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; } voteEnd() {     new best = 0, bool:bFound = false;     for( new i = 0 ; i < g_iMapCount ; i++ )     {         if( g_iVotes[ i ] > g_iVotes[ best ] )         {             best = i;             if( !bFound )                 bFound = true;         }     }         if( !bFound )         best = random( g_iMapCount );         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 );     g_bVoting = false; }
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ

Last edited by Dores; 01-03-2009 at 21:06.
Dores is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode