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.