Raised This Month: $ Target: $400
 0% 

Solved Need Code For CFG FILE


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
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 #1

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
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 10:32.


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