Thread: [Solved] Loop order
View Single Post
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 01-16-2018 , 15:11   Re: Loop order
Reply With Quote #17

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 ArraySizeg_aDatabase );

    new 
g_iItemsPlayerData ];

    new 
szPlayers32 ], iNumszName32 ], szAuthID32 ], szPassword18 ], iTempID;
    
get_playersszPlayersiNum );


    for( new 
iiNumi++ )
    {
        
iTempID szPlayers];

        for( new 
iIndexiIndex iArraySizeiIndex++ )
        {
            
ArrayGetArrayg_aDatabaseiIndexg_iItems );
            
            
get_user_infoiTempID"name"szNamecharsmaxszName ) );
            
get_user_authidiTempIDszAuthIDcharsmaxszAuthID ) );
            
get_user_infoiTempID"_pw"szPasswordcharsmaxszPassword ) );
            
trim(szName);
            
trim(szPassword);

            if( 
equalg_iItems[Player_Name], szName ) || equalg_iItems[Player_Name], szAuthID ) )
            {
                if( 
equalg_iItems[Player_Password], szPassword ) )
                {
                    if( 
g_iItems[Player_Suspended] ) 
                    {
                        
remove_user_flagsiTempID );
                        
log_to_file"DebugTest.txt""#2 Called" );
                    }
                    else {
                           
remove_user_flagsiTempID );
                           
set_user_flagsiTempIDread_flagsg_iItems[Player_AccessFlags]) );
                    
                            
log_to_file"DebugTest.txt""#3 Called" );
                   }
                }
                else
                {
                    
server_cmd"kick #%d ^"KICKEDyou have no entry to this server^""get_user_useridiTempID ) );        
                }
            }
        }
    }

Update your struct like this:
PHP Code:
enum _:PlayerData
{
    
Player_Name32 ],
    
Player_Password18 ],
    
Player_AccessFlags32 ],
    
Player_Prefix24 ],
    
Player_Suspended

And your ReadFile function like this:
PHP Code:
ReadFile( )
{
    
ArrayClearg_aDatabase );

    new 
g_iItemsPlayerData ];

    new 
szConfigs32 ], szFormat64 ], szPlayerData512 ];
    
get_configsdirszConfigscharsmaxszConfigs ) );
    
    
formatexszFormatcharsmaxszFormat ), "%s/%s"szConfigsg_szFile );
    
    new 
iFile fopenszFormat"rt" );
    
    if( 
iFile )
    {
        while( ! 
feofiFile ) )
        {    
            
fgetsiFileszPlayerDatacharsmaxszPlayerData ) );
            
trimszPlayerData );
            
            if( 
strlen(szPlayerData) < 10 || ( szPlayerData] == '/' && szPlayerData] == '/' ) )
            continue;
            
            if(
parseszPlayerDatag_iItems[Player_Name], charsmaxg_iItems[Player_Name] ), g_iItems[Player_Password], charsmaxg_iItems[Player_Password]), g_iItems[Player_AccessFlags], charsmaxg_iItems[Player_AccessFlags] ), g_iItems[Player_Prefix], charsmaxg_iItems[Player_Prefix] ) ) < 4)
             continue;
            
             
g_iItems[Player_Suspended]=(szPlayerData] == ';');
            
ArrayPushArrayg_aDatabaseg_iItems );
        }
        
fcloseiFile );
    }

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

Last edited by Clauu; 01-17-2018 at 03:22.
Clauu is offline