Raised This Month: $51 Target: $400
 12% 

Solved Need Code For CFG FILE


Post New Thread Reply   
 
Thread Tools Display Modes
Begineer Programmer
Member
Join Date: Nov 2021
Old 07-24-2022 , 19:26   Re: Need Code For CFG FILE
Reply With Quote #21

Quote:
Originally Posted by fysiks View Post
When you call it will depend on when you know the name of the map that you want to get the value for. Once you know what map name you want to use, that's when you call it.
bro it hard !!!
surely will try by reading old thread that only one option left !!!
that a simple plugin i take from thread and make modification through reading old threads
Begineer Programmer is offline
Begineer Programmer
Member
Join Date: Nov 2021
Old 07-24-2022 , 19:27   Re: Need Code For CFG FILE
Reply With Quote #22

Quote:
Originally Posted by wilian159 View Post
I did it very fast, but you need to test

PHP Code:
register_clcmd("say .a""testFunc"
PHP Code:
public testFunc()
{
    new 
xLineReturn[128]
    
copy(xLineReturncharsmax(xLineReturn), getConfigValueFromFile("maps/de_dust2.cfg""text to search"))

    if(
xLineReturn[0] != EOS)
    {
        
server_print("Test: %s"xLineReturn)
    }

PHP Code:
stock getConfigValueFromFile(const fileName[], cvarName[])
{
    new 
xLineReturn[128]
    new 
xCfgDir[64]
    
get_configsdir(xCfgDircharsmax(xCfgDir))

    new 
xFileName[128]
    
formatex(xFileNamecharsmax(xFileName), "%s/%s"xCfgDirfileName)

    new 
xFilePointer
    xFilePointer 
fopen(xFileName"rt")

    
xLineReturn[0] = EOS

    
if(xFilePointer)
    {
        new 
xLine[128]

        while(!
feof(xFilePointer))
        {
            
fgets(xFilePointerxLinecharsmax(xLine))
            
trim(xLine)

            if(
xLine[0] == EOS || xLine[0] == '#' || xLine[0] == ';' || xLine[0] == '/' && xLine[1] == '/' || !xLine[0])
                continue

            if(
containi(xLinecvarName))
            {
                
copy(xLineReturncharsmax(xLineReturn), xLine)
            }
        }

        
fclose(xFilePointer)
    }

    return 
xLineReturn

this should return the line, but you'll still have to deal with it
bro map are %s mean any next map not only one map .cfg

Last edited by Begineer Programmer; 07-24-2022 at 19:28.
Begineer Programmer is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2022 , 19:36   Re: Need Code For CFG FILE
Reply With Quote #23

Quote:
Originally Posted by Begineer Programmer View Post
bro map are %s mean any next map not only one map .cfg
If you're actually looking to learn, I would probably recommend writing the majority of the function yourself using the pieces that I provided. Something that is more tailored to your specific use case. As you get more experiences, you can make things more generic.

Also, by doing it yourself, you'll have a better understanding of how the code actually works which will be of more benefit to you in the long run.

The way he does it with returning a string from a function is generally not a good way to handle strings.
__________________

Last edited by fysiks; 07-24-2022 at 19:37.
fysiks is offline
Begineer Programmer
Member
Join Date: Nov 2021
Old 07-24-2022 , 19:42   Re: Need Code For CFG FILE
Reply With Quote #24

Quote:
Originally Posted by wilian159 View Post
I did it very fast, but you need to test

PHP Code:
register_clcmd("say .a""testFunc"
PHP Code:
public testFunc()
{
    new 
xLineReturn[128]
    
copy(xLineReturncharsmax(xLineReturn), getConfigValueFromFile("maps/de_dust2.cfg""text to search"))

    if(
xLineReturn[0] != EOS)
    {
        
server_print("Test: %s"xLineReturn)
    }

PHP Code:
stock getConfigValueFromFile(const fileName[], cvarName[])
{
    new 
xLineReturn[128]
    new 
xCfgDir[64]
    
get_configsdir(xCfgDircharsmax(xCfgDir))

    new 
xFileName[128]
    
formatex(xFileNamecharsmax(xFileName), "%s/%s"xCfgDirfileName)

    new 
xFilePointer
    xFilePointer 
fopen(xFileName"rt")

    
xLineReturn[0] = EOS

    
if(xFilePointer)
    {
        new 
xLine[128]

        while(!
feof(xFilePointer))
        {
            
fgets(xFilePointerxLinecharsmax(xLine))
            
trim(xLine)

            if(
xLine[0] == EOS || xLine[0] == '#' || xLine[0] == ';' || xLine[0] == '/' && xLine[1] == '/' || !xLine[0])
                continue

            if(
containi(xLinecvarName))
            {
                
copy(xLineReturncharsmax(xLineReturn), xLine)
            }
        }

        
fclose(xFilePointer)
    }

    return 
xLineReturn

this should return the line, but you'll still have to deal with it
Returning:

Test: mp_freezetime 1

Code !!!

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "begin"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /round""testFunc"
}

public 
testFunc()
{
    new 
xLineReturn[128]
    
copy(xLineReturncharsmax(xLineReturn), getConfigValueFromFile("maps/de_dust2.cfg""mp_maxrounds"))

    if(
xLineReturn[0] != EOS)
    {
        
client_print(0,print_chat,"Test: %s"xLineReturn)
    }


stock getConfigValueFromFile(const fileName[], cvarName[])
{
    new 
xLineReturn[128]
    new 
xCfgDir[64]
    
get_configsdir(xCfgDircharsmax(xCfgDir))

    new 
xFileName[128]
    
formatex(xFileNamecharsmax(xFileName), "%s/%s"xCfgDirfileName)

    new 
xFilePointer
    xFilePointer 
fopen(xFileName"rt")

    
xLineReturn[0] = EOS

    
if(xFilePointer)
    {
        new 
xLine[128]

        while(!
feof(xFilePointer))
        {
            
fgets(xFilePointerxLinecharsmax(xLine))
            
trim(xLine)

            if(
xLine[0] == EOS || xLine[0] == '#' || xLine[0] == ';' || xLine[0] == '/' && xLine[1] == '/' || !xLine[0])
                continue

            if(
containi(xLinecvarName))
            {
                
copy(xLineReturncharsmax(xLineReturn), xLine)
            }
        }

        
fclose(xFilePointer)
    }

    return 
xLineReturn

should return value not string

Last edited by Begineer Programmer; 07-24-2022 at 19:42.
Begineer Programmer is offline
Begineer Programmer
Member
Join Date: Nov 2021
Old 07-24-2022 , 19:44   Re: Need Code For CFG FILE
Reply With Quote #25

Quote:
Originally Posted by fysiks View Post
If you're actually looking to learn, I would probably recommend writing the majority of the function yourself using the pieces that I provided. Something that is more tailored to your specific use case. As you get more experiences, you can make things more generic.

Also, by doing it yourself, you'll have a better understanding of how the code actually works which will be of more benefit to you in the long run.

The way he does it with returning a string from a function is generally not a good way to handle strings.
Agreed !!!
@willian159
give me idea
that how to do !!!
Begineer Programmer is offline
Begineer Programmer
Member
Join Date: Nov 2021
Old 07-24-2022 , 20:01   Re: Need Code For CFG FILE
Reply With Quote #26

Quote:
Originally Posted by fysiks View Post
If you're actually looking to learn, I would probably recommend writing the majority of the function yourself using the pieces that I provided. Something that is more tailored to your specific use case. As you get more experiences, you can make things more generic.

Also, by doing it yourself, you'll have a better understanding of how the code actually works which will be of more benefit to you in the long run.

The way he does it with returning a string from a function is generally not a good way to handle strings.
Here is Code i make for any map to find
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "begin"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
}

loadsetting()
{
    new 
configDir[64], filename[96]
    
get_configsdir(szConfigsDircharsmax(szConfigsDir))
    new 
szMapname[32]
    
format(filenamecharsmax(filename), "%s/maps/%s.cfg"configDirszMapname)

is this right ?

Last edited by Begineer Programmer; 07-24-2022 at 20:02.
Begineer Programmer is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2022 , 20:19   Re: Need Code For CFG FILE
Reply With Quote #27

That only gets the file path though the map name will always be an empty string. I would probably suggest creating a function called something like "get_map_maxrounds_config" with the map name as the argument. Here is a basic outline of a function that will do what you want:

PHP Code:
get_map_maxrounds_config(szMapname[])
{
    
// Get the file name just like you did already

    // Open the file

    // Loop through the file's lines

        // Parse each line
        // if first parameter is "mp_maxrounds"
            // read second parameter, store it in a variable
    
    // Close file

    // return mp_maxrounds variable

__________________

Last edited by fysiks; 07-24-2022 at 20:27.
fysiks is offline
Begineer Programmer
Member
Join Date: Nov 2021
Old 07-24-2022 , 20:37   Re: Need Code For CFG FILE
Reply With Quote #28

Quote:
Originally Posted by fysiks View Post
That only gets the file path though the map name will always be an empty string. I would probably suggest creating a function called something like "get_map_maxrounds_config" with the map name as the argument. Here is a basic outline of a function that will do what you want:

PHP Code:
get_map_maxrounds_config(szMapname[])
{
    
// Get the file name just like you did already

    // Open the file

    // Loop through the file's lines

        // Parse each line
        // if first parameter is "mp_maxrounds"
            // read second parameter, store it in a variable
    
    // Close file

    // return mp_maxrounds variable

Logic Understand !!!
this is my code check !!!

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "begin"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
}

get_map_maxrounds_config(szMapname[])
{
    new 
configDir[64], filename[96]
    
get_configsdir(szConfigsDircharsmax(szConfigsDir))
    
format(filenamecharsmax(filename), "%s/maps/%s.cfg"configDirszMapname)
    new 
fopen(filename"rt")
    new 
szBuffer [32]="mp_maxrounds"
    
if( )
    {
        while (
fgets(f,szBuffer,charsmax(szBuffer)))
        {
            
        }
    }


Last edited by Begineer Programmer; 07-24-2022 at 20:43.
Begineer Programmer is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2022 , 20:53   Re: Need Code For CFG FILE
Reply With Quote #29

Did you try it? it looks incomplete, where is the rest of it?

Please look at the file reading code that I mentioned. There are very few modifications needed. You'll use your filename code and the the primary change is in the if statement where you will check for "mp_maxrounds" (use the equal function with the szModel variable) instead of what I'm doing there.

Also, anywhere you see a variable that starts with "g_", that will either be removed or replaced as appropriate.
__________________

Last edited by fysiks; 07-24-2022 at 20:53.
fysiks is offline
Begineer Programmer
Member
Join Date: Nov 2021
Old 07-24-2022 , 21:03   Re: Need Code For CFG FILE
Reply With Quote #30

Quote:
Originally Posted by fysiks View Post
Did you try it? it looks incomplete, where is the rest of it?

Please look at the file reading code that I mentioned. There are very few modifications needed. You'll use your filename code and the the primary change is in the if statement where you will check for "mp_maxrounds" (use the equal function with the szModel variable) instead of what I'm doing there.

Also, anywhere you see a variable that starts with "g_", that will either be removed or replaced as appropriate.
yeah i am working on what you give me !!!
Here i Find Another link too: https://forums.alliedmods.net/showpo...93&postcount=5
Begineer Programmer 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 07:19.


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