Because first you need to declare it locally before using it
new g_iItems[ PlayerData ];
Since all file data was parsed into array g_aDatabase, from this you will retrieve later any data you want.
Yes, it copies the name, but it will be the last name parsed from that file. Is that what you want?
Let me be more specific with some changes in your code, at the logic and structure, your OnTaskCheckStealAdmin function should be like this:
PHP Code:
public OnTaskCheckStealAdmin( )
{
ReadFile( );
new iArraySize = ArraySize( g_aDatabase );
new g_iItems[ PlayerData ];
new szPlayers[ 32 ], iNum, szName[ 32 ], szAuthID[ 32 ], szPassword[ 18 ], iTempID;
get_players( szPlayers, iNum );
for( new i; i < iNum; i++ )
{
iTempID = szPlayers[ i ];
for( new iIndex; iIndex < iArraySize; iIndex++ )
{
ArrayGetArray( g_aDatabase, iIndex, g_iItems );
get_user_info( iTempID, "name", szName, charsmax( szName ) );
get_user_authid( iTempID, szAuthID, charsmax( szAuthID ) );
get_user_info( iTempID, "_pw", szPassword, charsmax( szPassword ) );
trim(szName);
trim(szPassword);
if( equal( g_iItems[Player_Name], szName ) || equal( g_iItems[Player_Name], szAuthID ) )
{
if( equal( g_iItems[Player_Password], szPassword ) )
{
if( g_iItems[Player_Suspended] )
{
remove_user_flags( iTempID );
log_to_file( "DebugTest.txt", "#2 Called" );
}
else {
remove_user_flags( iTempID );
set_user_flags( iTempID, read_flags( g_iItems[Player_AccessFlags]) );
log_to_file( "DebugTest.txt", "#3 Called" );
}
}
else
{
server_cmd( "kick #%d ^"KICKED: you have no entry to this server^"", get_user_userid( iTempID ) );
}
}
}
}
}
Update your struct like this:
PHP Code:
enum _:PlayerData
{
Player_Name[ 32 ],
Player_Password[ 18 ],
Player_AccessFlags[ 32 ],
Player_Prefix[ 24 ],
Player_Suspended
}
And your ReadFile function like this:
PHP Code:
ReadFile( )
{
ArrayClear( g_aDatabase );
new g_iItems[ PlayerData ];
new szConfigs[ 32 ], szFormat[ 64 ], szPlayerData[ 512 ];
get_configsdir( szConfigs, charsmax( szConfigs ) );
formatex( szFormat, charsmax( szFormat ), "%s/%s", szConfigs, g_szFile );
new iFile = fopen( szFormat, "rt" );
if( iFile )
{
while( ! feof( iFile ) )
{
fgets( iFile, szPlayerData, charsmax( szPlayerData ) );
trim( szPlayerData );
if( strlen(szPlayerData) < 10 || ( szPlayerData[ 0 ] == '/' && szPlayerData[ 1 ] == '/' ) )
continue;
if(parse( szPlayerData, g_iItems[Player_Name], charsmax( g_iItems[Player_Name] ), g_iItems[Player_Password], charsmax( g_iItems[Player_Password]), g_iItems[Player_AccessFlags], charsmax( g_iItems[Player_AccessFlags] ), g_iItems[Player_Prefix], charsmax( g_iItems[Player_Prefix] ) ) < 4)
continue;
g_iItems[Player_Suspended]=(szPlayerData[ 0 ] == ';');
ArrayPushArray( g_aDatabase, g_iItems );
}
fclose( iFile );
}
}
And also overall for your needs it's better to use Tries with the name as an index, in this way you will get rid of the loop on every player in OnTaskCheckStealAdmin
Hope that this helps.
PS. there are some later editings, so please recheck the code