This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Reading const from a file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Unkolix
Veteran Member
Join Date: Sep 2012
Old 02-10-2013 , 06:07   Reading const from a file
Reply With Quote #1

Heya! I am wondering if it's possible to read a const from a file.

I have this code:
PHP Code:
new mapnames
<...>
new const 
mapnames[][] =
{
    
"awp_""cs_deagle""knf_""1hp_""aim_""fy_" //Maps in which vipmenu can't be used
}
<...>
get_mapnameszMap charsmaxszMap ) );
for( new 
sizeofmapnames ) ; i++ )
{
    if ( 
containiszMap mapnames] ) !=-)
    return;

I want to make a file where those all mapnames would be and I could add more without editing the plugin.

Last edited by Unkolix; 02-10-2013 at 08:55.
Unkolix is offline
DoviuX
Senior Member
Join Date: Jun 2009
Location: Lithuania
Old 02-10-2013 , 06:51   Re: Reading const from a file
Reply With Quote #2

I suggest you'd make an .ini file.
DoviuX is offline
Send a message via Skype™ to DoviuX
Unkolix
Veteran Member
Join Date: Sep 2012
Old 02-10-2013 , 07:05   Re: Reading const from a file
Reply With Quote #3

That's not what I asked

I want to know if it's possible and if it is I would like to see an example
Unkolix is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 02-10-2013 , 07:07   Re: Reading const from a file
Reply With Quote #4

Simply read the file like any other file and then parse it per your needs
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Unkolix
Veteran Member
Join Date: Sep 2012
Old 02-10-2013 , 07:21   Re: Reading const from a file
Reply With Quote #5

Quote:
Originally Posted by YamiKaitou View Post
Simply read the file like any other file and then parse it per your needs
I don't know how :/
Unkolix is offline
nnajko
Senior Member
Join Date: May 2009
Location: Sweden
Old 02-10-2013 , 08:45   Re: Reading const from a file
Reply With Quote #6

This should work
Only updates on mapchange.

PHP Code:
g_szMapNames[64][32];
g_szMapNames[0]; //will print out the first line of the file etc.. 
PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Read From File"
#define VERSION "1.0"
#define AUTHOR "dinnk."

#define FILENAME "mapnames.ini"

new g_szMapNames[64][32];

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_clcmd("say /readfile""CmdRead");
    
    
ReadMapNames();
}

public 
CmdRead(id)
{
    new 
0;
    while( !(
equal(g_szMapNames[i], "")) )
    {
        
client_print(0print_chat"%s"g_szMapNames[i]);
        
i++;
    }
}

public 
ReadMapNames()
{
    new 
szPath[64];
    
get_configsdir(szPathcharsmax(szPath));
    
    
formatex(szPathcharsmax(szPath), "%s/%s"szPathFILENAME);
    
    if( 
file_exists(szPath) )
    {
        new 
szData[32], iLine;
        
        new 
iFile fopen(szPath"rt");
        
        if( !
iFile 
        {
            return 
PLUGIN_CONTINUE;
        }
        
        while( !
feof(iFile) )
        {
            
fgets(iFileszDatacharsmax(szData));
            
            
formatex(g_szMapNames[iLine], charsmax(g_szMapNames[]), "%s"szData);
            
            
iLine++
        }
        
        
fclose(iFile);
    }
    
    return 
PLUGIN_CONTINUE;


Last edited by nnajko; 02-10-2013 at 08:46.
nnajko is offline
Unkolix
Veteran Member
Join Date: Sep 2012
Old 02-10-2013 , 08:53   Re: Reading const from a file
Reply With Quote #7

Maybe you understood me wrong, I don't want to make that when player types in that command it shows the map names.
I made it like this:
PHP Code:
get_mapnameszMap charsmaxszMap ) );
for( new 
sizeofmapnames ) ; i++ )
{
    if ( 
containiszMap mapnames] ) !=-)
    return;

This code checks if the map is one of those mentioned in and I want that const mapnames be readed from a file mapnames.ini

Last edited by Unkolix; 02-10-2013 at 08:54.
Unkolix is offline
AngeIII
Senior Member
Join Date: Sep 2007
Location: Latvia
Old 02-10-2013 , 08:56   Re: Reading const from a file
Reply With Quote #8

just open and read line-by-line.
Quote:
//szPath -> location to your file(path)/filename.ini
new
szData[32], iLine;

new
iFile = fopen(szPath, "rt");

if( !
iFile )
{
return
PLUGIN_CONTINUE;
}

while( !
feof(iFile) )
{
fgets(iFile, szData, charsmax(szData));
// here in szData contains the line data.
// check .. set .. format..

iLine++
}

__________________
skype: pavle_ivanof
-=ThQ=-
PRIVATE SUPPORT = PAID SUPPORT

Last edited by AngeIII; 02-10-2013 at 08:58.
AngeIII is offline
Send a message via Skype™ to AngeIII
Unkolix
Veteran Member
Join Date: Sep 2012
Old 02-10-2013 , 09:00   Re: Reading const from a file
Reply With Quote #9

Quote:
Originally Posted by AngeIII View Post
just open and read line-by-line.

I don't understand it :/
Unkolix is offline
nnajko
Senior Member
Join Date: May 2009
Location: Sweden
Old 02-10-2013 , 10:02   Re: Reading const from a file
Reply With Quote #10

What I ment is that you could use parts of the code to make things work as you want.

PHP Code:
public CmdRead(id)
{
    new 
szMap[32], szString[32], szString2[32];
    
get_mapname(szMapcharsmax(szMap));
    
    new 
0;
    while( !(
equal(g_szMapNames[i], "")) )
    {
        
formatex(szStringcharsmax(szString), "%s"g_szMapNames[i]);
        
formatex(szString2charsmax(szString2), "%s"szMap);
        
        
replace(szStringcharsmax(szString), "^n""");

        if( 
containi(szString2szString) > -)
        {
            
// The current map does contain something from "FILENAME".
            
            
return;
        } 
        
        
i++;
    }
    
    
// The current map does not contain anything from "FILENAME".


Last edited by nnajko; 02-10-2013 at 10:03.
nnajko 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 17:32.


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