AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [REQUEST]Reading from a multiple files (https://forums.alliedmods.net/showthread.php?t=208350)

Unkolix 02-12-2013 12:44

[REQUEST]Reading from a multiple files
 
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
    }



fysiks 02-12-2013 13:42

Re: [REQUEST]Reading from a multiple files
 
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.

Unkolix 02-12-2013 13:53

Re: [REQUEST]Reading from a multiple files
 
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".



fysiks 02-12-2013 15:08

Re: [REQUEST]Reading from a multiple files
 
Look in my Bot Apology plugin for an example of how to read a file.

Unkolix 02-12-2013 15:37

Re: [REQUEST]Reading from a multiple files
 
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++
    } 


.Dare Devil. 02-12-2013 16:09

Re: [REQUEST]Reading from a multiple files
 
( 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



Unkolix 02-12-2013 16:12

Re: [REQUEST]Reading from a multiple files
 
Quote:

Originally Posted by .Dare Devil. (Post 1893215)
( 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?

.Dare Devil. 02-12-2013 16:17

Re: [REQUEST]Reading from a multiple files
 
Quote:

Originally Posted by Unkolix (Post 1893218)
LOL WHUT?

I did code for you, what part of my post does not you understand?

Unkolix 02-12-2013 16:20

Re: [REQUEST]Reading from a multiple files
 
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...

.Dare Devil. 02-12-2013 16:35

Re: [REQUEST]Reading from a multiple files
 
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 }
}}} 



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

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