Raised This Month: $32 Target: $400
 8% 

Invalid cellvector in ArrayGetString


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 11-10-2012 , 06:49   Invalid cellvector in ArrayGetString
Reply With Quote #1

The highlighted line throws this error:
Code:
L 11/10/2012 - 12:41:30: Invalid cellvector handle provided (6:5:4)
L 11/10/2012 - 12:41:30: [AMXX] Run time error 10: native error (native "ArrayGetString")
L 11/10/2012 - 12:41:30: [AMXX]    [0] test.sma::_tShowAdv (line 87)
Code:
#include < amxmodx > #include < amxmisc > const MAX_SIZE = 256 const MAXPLAYERS = 32 new const FILENAME[ ] = "adv.ini" const Float: SHOW_PER = 60.0 new Array: g_Messages new g_ArrId[ MAXPLAYERS + 1 ] const TASK_CLIENTAD = 151114 new g_TotalMessages new g_Round, g_MaxPlayers new g_CvarHideSlots new g_msgSayText public plugin_init( ) {     register_plugin( "adv", "1.0", "IdiotStrike" )         g_Messages = ArrayCreate( MAX_SIZE )     g_MaxPlayers = get_maxplayers( )         UTIL_ReadFile( )         register_dictionary( "adv.txt" )         register_logevent( "_eRoundStart", 2, "1=Round_Start" )     register_event( "TextMsg", "Event_RoundRestart", "a", "2&#Game_w")         g_CvarHideSlots = get_cvar_pointer( "amx_hideslots" )         g_msgSayText = get_user_msgid( "SayText" ) } public Event_RoundRestart(  ) {     g_Round = 0 } public _eRoundStart( ) {         g_Round ++         new szMapName[ 32 ]     get_mapname( szMapName, charsmax( szMapName ) )         new aPlayers[ 32 ], iNum     get_players( aPlayers, iNum )         for ( new i; i < iNum; i++ )     {         ShowPrint ( aPlayers[i], "%L", LANG_SERVER, "ADV_ROUNDSTART", g_Round, szMapName, get_playersnum( ), g_MaxPlayers - get_pcvar_num( g_CvarHideSlots ) )     } }         public client_putinserver( id ) {     g_ArrId[ id ] = 0         set_task( SHOW_PER, "_tShowAdv", id + TASK_CLIENTAD, _, _, "b" ) } public client_disconnect( id ) {     remove_task( id + TASK_CLIENTAD ) } public _tShowAdv( __TASKID ) {        new id = __TASKID - TASK_CLIENTAD         if( !is_user_connected( id ) )         return remove_task( __TASKID )         if( g_ArrId[ id ] ++ >= g_TotalMessages )         g_ArrId[ id ] = 0         new szTemp[ MAX_SIZE ]
    ArrayGetString( g_Messages, g_ArrId[ id ], szTemp, charsmax( szTemp ) )
        ShowPrint( id, "%s", szTemp )         return PLUGIN_CONTINUE }     public UTIL_ReadFile( ) {         new szCfgDir[ 256 ]     get_configsdir( szCfgDir, charsmax( szCfgDir ) )         format( szCfgDir, charsmax( szCfgDir ), "%s/%s", szCfgDir, FILENAME )         if( !file_exists( szCfgDir ) )         set_fail_state( "File was not found." )         new iFile = fopen( szCfgDir, "rt" )         if( !iFile )         return         new szBuffer[ MAX_SIZE ]         while( !feof( iFile ) )     {                 fgets( iFile, szBuffer, charsmax( szBuffer ) )                 replace( szBuffer, charsmax( szBuffer ), "^n", "" )                 if( szBuffer[ 0 ] == ';' || !szBuffer[ 0 ] )             continue                 ArrayPushString( g_Messages, szBuffer )                 g_TotalMessages ++     }         fclose( iFile )         if( g_TotalMessages == 0 )         set_fail_state( "The file is empty." ) } ShowPrint( id, const sMsg[], { Float, Sql, Result, _ }:... ) {     if ( is_user_connected(id) ) {         static newMsg[191], message[191], tNewMsg;         tNewMsg = charsmax( newMsg );         vformat( newMsg, tNewMsg, sMsg, 3 );         replace_all( newMsg, tNewMsg, "!t", "^3" );         replace_all( newMsg, tNewMsg, "!g", "^4" );         replace_all( newMsg, tNewMsg, "!n", "^1" );         formatex( message, charsmax( message ), "^1%s", newMsg );         emessage_begin( MSG_ONE, g_msgSayText, _, id );         ewrite_byte( id );         ewrite_string( message );         emessage_end();     } }

I know the error means an invalid integer is passed as the array's item index, however I cannot see how could that go.

What the plugin does:
1) Read every line from a specified file and copy it's content into the global array
2) Whenever a client connects, set their array index to zero and set a task based on their ID every 60 seconds
3) Show them an ad based on their current Array index - first message shown should logically have index 1 and last should have index 0
__________________
Currently busy working on a very large scale anime database project.

Last edited by Backstabnoob; 11-10-2012 at 06:53.
Backstabnoob is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 11-10-2012 , 09:58   Re: Invalid cellvector in ArrayGetString
Reply With Quote #2

PHP Code:
if( g_ArrIdid ] ++ >= g_TotalMessages 


PHP Code:
if( ++g_ArrIdid ] >= g_TotalMessages 
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please

Last edited by nikhilgupta345; 11-10-2012 at 09:58.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 11-10-2012 , 10:08   Re: Invalid cellvector in ArrayGetString
Reply With Quote #3

How does ++ before the variable work? Will it still increment the value? Thanks for the reply
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 11-10-2012 , 11:40   Re: Invalid cellvector in ArrayGetString
Reply With Quote #4

If you do the ++ after the variable, then it would do the < check BEFORE adding 1 to the variable. Putting ++ before the variable first adds 1 to the variable, AND THEN does the check.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 11-10-2012 , 13:54   Re: Invalid cellvector in ArrayGetString
Reply With Quote #5

Also, once the file is parsed, better to do g_TotalMessages = ArraySize( ArrayName ).


Following code won't help for your problem but you may find interesting stuff in it : http://forums.alliedmods.net/showthread.php?p=781045
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 11-12-2012 , 11:19   Re: Invalid cellvector in ArrayGetString
Reply With Quote #6

Now that I look at it again, there are more mistakes I made such as making the function UTIL_ReadFile public or not caching the mapname in a global variable. Thanks for the replies and help.
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob 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 20:03.


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