Raised This Month: $ Target: $400
 0% 

reading a file.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 08-10-2010 , 13:09   reading a file.
Reply With Quote #1

I'm having troubles reading a file, i looked into other codes but can't seem to find the answer.
It should check if the player's steamid is in the file on disconnect , and replace that line with a new one, or add a line when he's not in the file.

The problem is that it crashes my game when i disconnect.

PHP Code:
#pragma semicolon 1

#include <amxmodx>
#include <amxmisc>

#define VERSION "1.0"

new file[128];
new 
currentmap[64];

public 
plugin_init()
{
    
register_plugin("Player's time logger"VERSION"Drekes");
    
    
// Start the log file.
    
new currentdate[15];
    
get_time("%d"currentdatecharsmax(currentdate));
    
    new 
dir[64];
    
get_datadir(dircharsmax(dir));
    
    
format(dircharsmax(dir), "%s/timelogs"dir);
    
    if(!
dir_exists(dir))
        
mkdir(dir);
    
    
formatex(filecharsmax(file), "%s/log-%s.ini"dircurrentdate);

    
get_mapname(currentmapcharsmax(currentmap));
    
    new 
mapchangeline[128];
    
formatex(mapchangelinecharsmax(mapchangeline), "*-- Mapchange to %s --*"currentmap);
    
    
write_file(filemapchangeline);
}

public 
client_disconnect(id)
{
    new 
playtime get_user_time(id) / 60;
    
    new 
authid[35];
    
get_user_authid(idauthidcharsmax(authid));
    
    new 
data[128], filepos;
    new 
fileid[35], filetime[20];
    
    new 
writefile fopen(file"rw");
    
    if(
writefile)
    {
        while(!
feof(writefile))
        {
            
fgets(writefiledatacharsmax(data));
            
            
filepos++;
            
            if(
data[0] == '*')
                continue;
                
            
parse(datafileidcharsmax(fileid), filetimecharsmax(filetime));
            
            if(
equali(authidfileid))
            {
                new 
filetimenum str_to_num(filetime);
                                
                new 
writetime playtime filetimenum;
                
                
formatex(datacharsmax(data), "%s %i"authidwritetime);
                
                break;
            }
    
            
formatex(datacharsmax(data), "%s %i"authidplaytime);
        }
    
        
write_file(filedata);
    }
    
    
fclose(writefile);

__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
 



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 21:55.


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