Thread: [Solved] Need Code For CFG FILE
View Single Post
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2022 , 22:43   Re: Need Code For CFG FILE
Reply With Quote #39

Quote:
Originally Posted by Begineer Programmer View Post
PHP Code:
get_map_maxrounds(szMapname[])
{
    new 
szConfigsDir[64], szFilePath[128]
    
get_configsdir(szConfigsDircharsmax(szConfigsDir))
    
format(szFilePathcharsmax(szFilePath), "%s/maps/%s.cfg",szConfigsDirszMapname)
    new 
fopen(szFilePath"rt")
    if( 
)
    {
        new 
szCvar[32], szValue[32], szCfgData[64],iValue;
        
        while(
fgets(fszCfgDatacharsmax(szCfgData)))
        {
            
parse(szCfgDataszCvarcharsmax(szCvar), szValuecharsmax(szValue));

            if(
equali(szCvar"mp_maxrounds"))
            {
                
iValue str_to_num(szValue)
                return 
iValue;
            }
        }
        
fclose(f)
    }
    


check this one ?
An important part of learning to code is to learn how to test and debug your own plugins. There very least that you could do is to test your code on your server to see if it works. It can be done really quickly and will tell you if the basics is working.

Regarding the code, it looks mostly correct. However, I would move the return to the end of the function so that it takes into account for cases where it's defined multiple times.

EDIT: You also can't return before fclose() because it will cause issues if you don't properly close the file (as pointed out by +ARUKARI-).
__________________

Last edited by fysiks; 07-24-2022 at 22:49.
fysiks is offline