AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Read a line from a file and check (https://forums.alliedmods.net/showthread.php?t=172294)

Diegorkable 11-18-2011 14:24

Read a line from a file and check
 
Hey guys,

My friend is trying to get a line from a file (you can see how the line should look like in the file from the formatex function he used), I helped him design it a bit cuz it didnt work for him and thats what came out:

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Prisoner Count"
#define VERSION "1.0"
#define AUTHOR "CreePs"

new PrisonerID[33];
new 
HighestPrisoner;
new 
filename[256]

public 
plugin_init()
{
    
get_configsdirfilename255 )
    
format(filename255"%s/prisoner.ini"filename);
    
register_clcmd("say /test""cmdTest")
}

public 
cmdTest(id)
{
    
client_print(idprint_chat"TESTDSDGFTDGF")
}
    
public 
client_putinserver(id)
{
    
Load(id);
}

Load(id)
{
    new 
data[128];
    new 
Name[64];
    new 
Authid[64];
    new 
ID[64];
    new 
Checkid[64];
    new 
Highest[256];

    
get_user_name(idName63);
    
get_user_authid(idCheckid63);
    
    new 
szReadData[200]
    new 
file fopen(filename"r")

    while( 
fgets(filedatasizeof(data) - 1) )
    {
        
parse(dataNamecharsmax(Name), Authidcharsmax(Authid), IDcharsmax(ID), Highestcharsmax(Highest) );

        if( 
equal(CheckidAuthid) )
        {
            
PrisonerID[id] = str_to_num(ID);    
            
set_user_infoid"name"Name )
            
fclose(file)
            
            return 
PLUGIN_CONTINUE
        
}
        
        
HighestPrisoner str_to_num(Highest);
    }
    
    
PrisonerID[id] = str_to_num(Highest) + 1;
                
    
get_user_authid(idAuthid63);
    
formatex(szReadDatacharsmax(szReadData) - 1"^"%s^" %s  %i %i"NameAuthidPrisonerID[id], PrisonerID[id] > HighestPrisoner PrisonerID[id] : HighestPrisoner);    
    
fputs(fileszReadData)
    
fclose(file)
            
    return 
PLUGIN_CONTINUE


Now he says it doesn't work and writes nothing, in my opinion it should work. Does someone detect something wrong?

fysiks 11-18-2011 15:53

Re: Read a line from a file and check
 
Quote:

Originally Posted by Diegorkable (Post 1598665)
Now he says it doesn't work and writes nothing, in my opinion it should work.

Wow, you are probably the laziest active member on here.

You can't write to a file that was opened for read-only access.

Diegorkable 11-18-2011 19:08

Re: Read a line from a file and check
 
Rofl, perhaps. Still I remember that I used it on my Auto-Mix plugin, and it worked well.
But if you say so, how can I open a file which I can Read & write? "rw"?

Diegorkable 11-19-2011 05:45

Re: Read a line from a file and check
 
Yeah sorry my bad, I thought it doesnt matter. The right flag would be "r+"


All times are GMT -4. The time now is 08:34.

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