Raised This Month: $ Target: $400
 0% 

Read specific part from ini


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DarthMan
Veteran Member
Join Date: Aug 2011
Old 03-01-2017 , 07:27   Read specific part from ini
Reply With Quote #1

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;
}

Last edited by DarthMan; 03-01-2017 at 07:28.
DarthMan is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-01-2017 , 09:06   Re: Read specific part from ini
Reply With Quote #2

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.
__________________
fysiks is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 03-01-2017 , 10:04   Re: Read specific part from ini
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
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.
DarthMan is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-01-2017 , 10:26   Re: Read specific part from ini
Reply With Quote #4

Documentation is your best friend while coding, always. http://amxmodx.org/api
klippy 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 20:43.


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