AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Read specific part from ini (https://forums.alliedmods.net/showthread.php?t=294524)

DarthMan 03-01-2017 07:27

Read specific part from ini
 
Hello. It's my first time trying to use containi so I am not yet very familiar with it, I know it's like that native containi(const source[],const string[]); where source is the ini file and string is the string. The real problem is how can I read only specific text from every line from the ini, in this case the models, and not anything else that goes after them? Any help will be apreciated, thanks!

Code:

public plugin_precache()
{
    new conffile_mdl[200]
    new configdir_mdl[200]
 
    get_configsdir(configdir_mdl,199)
    format(conffile_mdl,199,"%s/models.ini",configdir_mdl)
    if(!file_exists(conffile_mdl))
    {
        log_amx("amxmodx/configs/models.ini is missing!")
        return 0
    }
 
    new lines = file_size(conffile_mdl,1)
    new name[128], len
    new model_path[128]
    for(new i=0;i<=lines;i++)
    {
        read_file(conffile_mdl,i,name,127,len)
        if(equal(name,"")) continue;
        if(!equal(name,";",1)) {
            // log_amx("precache: %s", file)
            format(model_path, charsmax(model_path), "models/player/%s/%s.mdl",name,name)
            precache_model(model_path);
        }
    }
    return PLUGIN_HANDLED;
}


fysiks 03-01-2017 09:06

Re: Read specific part from ini
 
Where are you using contiaini()? Why would you use containi()?

Note that read_file() is deprecated and should not be used. You should use fopen() (you can see an example in my bot plugin in my signature.

If you want to have 'end of line' comments then you need to use something like strtok() where the token is your comment delimiter (often the semi-colon in INI files) to separate the data from the comment.

DarthMan 03-01-2017 10:04

Re: Read specific part from ini
 
Quote:

Originally Posted by fysiks (Post 2499693)
Where are you using contiaini()? Why would you use containi()?

Note that read_file() is deprecated and should not be used. You should use fopen() (you can see an example in my bot plugin in my signature.

If you want to have 'end of line' comments then you need to use something like strtok() where the token is your comment delimiter (often the semi-colon in INI files) to separate the data from the comment.

Thanks for telling me that. I did not use containi because I jsut found it today and I have tog et used to it.

klippy 03-01-2017 10:26

Re: Read specific part from ini
 
Documentation is your best friend while coding, always. http://amxmodx.org/api


All times are GMT -4. The time now is 20:43.

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