Raised This Month: $ Target: $400
 0% 

[REQUEST]Reading from a multiple files


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Unkolix
Veteran Member
Join Date: Sep 2012
Old 02-12-2013 , 12:44   [REQUEST]Reading from a multiple files
Reply With Quote #1

I've already asked how to read from a file, but I fail when I try to read from multiple files in the same plugin. I will comment in php code. I would appreciate if someone could do it for me. I will give more information if it's needed.
PHP Code:
new const mapnames[][] =
{
    
"awp_""cs_deagle""knf_""1hp_""aim_""fy_" //Maps in which vipmenu can't be used
}
new const 
awpmapnames[][] =
{
    
"2x2""3x3""4x4""cs_max""aim"  //Maps in which awp choise won't show up
}
<...>
get_mapnameszMap charsmaxszMap ) );
for( new 
sizeofmapnames ) ; i++ )
{
    if ( 
containiszMap mapnames] ) !=-//Checks if map is the one mentioned in const mapnames
    
{
        
client_print(idprint_center"VIP meniu sitame zemelapyje neveikia!"//Sends a message that VIP can't use VIP menu on that map
    
}
}
<...>
get_mapnameszMap charsmaxszMap ) );
for( new 
sizeofmapnames ) ; i++ )
{
    if ( 
containiszMap mapnames] ) !=-//Checks if map is the one mentioned in const mapnames
    
return;
}
<...>
get_mapnameszMap charsmaxszMap ) );
for( new 
sizeofmapnames ) ; i++ )
{
    if ( 
containiszMap mapnames] ) !=-//Checks if map is the one mentioned in const mapnames
    
{
        
client_print(idprint_center"VIP meniu sitame zemelapyje neveikia!"//Sends a message that VIP can't use VIP menu on that map
    
}
    if ( 
containiszMap mapnames] ) !=-//Checks if map is the one mentioned in const mapnames
    
return; //Stop VIP from getting the VIP menu
}
<...>
for( new 
sizeofawpmapnames ) ; i++ )
{
    if ( 
containi(szMap awpmapnames]) !=-)
    {
        
bAwpMap true
        
break
    }


Last edited by Unkolix; 02-12-2013 at 13:53.
Unkolix is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-12-2013 , 13:42   Re: [REQUEST]Reading from a multiple files
Reply With Quote #2

Stop saying "consts", you never use it correctly. "const" means constant. You can't assign anything to a constant after it has been declared.

Also, where is your file read code? Reading two files is just as easy as reading one file. You either need two different file handles or you need to open one after the other. The latter is likely more appropriate here.
__________________

Last edited by fysiks; 02-12-2013 at 13:43.
fysiks is offline
Unkolix
Veteran Member
Join Date: Sep 2012
Old 02-12-2013 , 13:53   Re: [REQUEST]Reading from a multiple files
Reply With Quote #3

But I don't understand how...
PHP Code:
#define FILENAME "mapnames.ini"  
<...>
new 
g_szMapNames[64][32];
<...>
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 Unkolix; 02-12-2013 at 14:03.
Unkolix is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-12-2013 , 15:08   Re: [REQUEST]Reading from a multiple files
Reply With Quote #4

Look in my Bot Apology plugin for an example of how to read a file.
__________________
fysiks is offline
Unkolix
Veteran Member
Join Date: Sep 2012
Old 02-12-2013 , 15:37   Re: [REQUEST]Reading from a multiple files
Reply With Quote #5

It seems that I can't understand more then 75% of this:
PHP Code:
    new sorryfile[64]
    
get_configsdir(sorryfilesizeof(sorryfile) - 1)
    
add(sorryfilesizeof(sorryfile) - 1"/bot_apology.ini")
    
    if( !
file_exists(sorryfile) )
    {
        
copy(g_sorry_phrases[0], SORRYS_LEN"sorry")
        
g_sorry_count 1
        
return
    }
    
    new 
fopen(sorryfile"rt")
    
    new 
data[SORRYS_LEN]
    
g_sorry_count 0

    
while( !feof(f) && g_sorry_count SORRYS_MAX
    { 
        
fgets(fdatasizeof(data) - 1)
         
        
trim(data)
        if( !
data[0] || data[0] == ';'
            
|| data[0] == '/' && data[1] == '/' ) continue;
        
copy(g_sorry_phrases[g_sorry_count], SORRYS_LENdata)
        
g_sorry_count++
    } 

Last edited by Unkolix; 02-12-2013 at 15:37.
Unkolix is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 02-12-2013 , 16:09   Re: [REQUEST]Reading from a multiple files
Reply With Quote #6

( old read file native i know ... : P )

If you want to read from file ( addons/myidontknowwhat.txt ) example 2 things: mapname value


PHP Code:

// how many costom things to you want to be in param 2
#define d_costom 3

// param 2 from file
new const d_param2[d_costom][] = { "vipmenu""awp""and so on..." }

// Variable for readed param 2
// this goes that way
// if map is example de_dust and param 2 is awp then this variable hold 1
// vipmenu will hold 0
// awp will hold 1
// and so on... hold 2, if you add more this way the number will go, i hope you understand
new d_param2


// lets read a file

public plugin_init()
{
    new 
ab[32], line[128], c[64], d[64], e
    get_mapname
(b,29)
        
    for(
0!= -1a++) {
    
b[31] = read_file"addons/myidontknowwhat.txt"aline126b[30])
    if(!
b[31]) break
    if( !
line[0] || line[0] == ' ' || line[0] == '/' ) continue
    
parse(linec); trim(c); trim(d)
    if(
equal(c,b)) {
    for(
0d_costome++) {
    if(
equal(d,d_param2[e])) { d_param2 e; break }; }
}}}

// now what do you need to do is only check variable d_param2
// example

if ( d_param2 == )
{
    
// param2 from file was awp

.Dare Devil. is offline
Unkolix
Veteran Member
Join Date: Sep 2012
Old 02-12-2013 , 16:12   Re: [REQUEST]Reading from a multiple files
Reply With Quote #7

Quote:
Originally Posted by .Dare Devil. View Post
( old read file native i know ... : P )

If you want to read from file ( addons/myidontknowwhat.txt ) example 2 things: mapname value


PHP Code:

// how many costom things to you want to be in param 2
#define d_costom 3

// param 2 from file
new const d_param2[d_costom][] = { "vipmenu""awp""and so on..." }

// Variable for readed param 2
// this goes that way
// if map is example de_dust and param 2 is awp then this variable hold 1
// vipmenu will hold 0
// awp will hold 1
// and so on... hold 2, if you add more this way the number will go, i hope you understand
new d_param2


// lets read a file

public plugin_init()
{
    new 
ab[32], line[128], c[64], d[64], e
    get_mapname
(b,29)
        
    for(
0!= -1a++) {
    
b[31] = read_file"addons/myidontknowwhat.txt"aline126b[30])
    if(!
b[31]) break
    if( !
line[0] || line[0] == ' ' || line[0] == '/' ) continue
    
parse(linec); trim(c); trim(d)
    if(
equal(c,b)) {
    for(
0d_costome++) {
    if(
equal(d,d_param2[e])) { d_param2 e; break }; }
}}}

// now what do you need to do is only check variable d_param2
// example

if ( d_param2 == )
{
    
// param2 from file was awp

LOL WHUT?
Unkolix is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 02-12-2013 , 16:17   Re: [REQUEST]Reading from a multiple files
Reply With Quote #8

Quote:
Originally Posted by Unkolix View Post
LOL WHUT?
I did code for you, what part of my post does not you understand?
.Dare Devil. is offline
Unkolix
Veteran Member
Join Date: Sep 2012
Old 02-12-2013 , 16:20   Re: [REQUEST]Reading from a multiple files
Reply With Quote #9

PHP Code:
new const d_param2[d_costom][] = { "vipmenu""awp""and so on..." 
I have to write everything in one file? I don't understand anything you did there...
Unkolix is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 02-12-2013 , 16:35   Re: [REQUEST]Reading from a multiple files
Reply With Quote #10

Awww, Failed ... How can i be so stupid sometimes..

Allright here is new code

PHP Code:

#define max_files 3

// Here is file names...
new const d_files[max_files][] = { "addons/vipmenu.txt""addons/awp.txt""addons/andsoon.txt" }

// This is the variable, example system load vipmenu.txt and that map what server have is in the list then d_mapc[0] will be 1
// if in awp.txt have then d_mapc[1] will be 1
new d_mapc[max_files]

public 
plugin_init()
{
    new 
ab[32], line[64], e
    
get_mapname(b,29)
       
    for(
0max_filese++) {
    if(!
file_exists(d_files[e])) continue 

    for(
0!= -1a++) {
    
b[31] = read_filed_files[e], aline63b[30])
    if(!
b[31]) break
    if( !
line[0] || line[0] == ' ' || line[0] == '/' ) continue
    if(
equal(line,b)) { d_mapc[e] = 1; break }
}}} 
.Dare Devil. 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:30.


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