Raised This Month: $ Target: $400
 0% 

help with file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
risontek22
Member
Join Date: Mar 2013
Location: localhost
Old 09-01-2013 , 03:20   help with file
Reply With Quote #1

hello, i want to make log stock. i Tried make this but this doesnt work help pls
PHP Code:
new const g_constLogDirectory[]    = "addons/amxmodx/data/lol/log.txt";

public 
plugin_init()
{
    
lolfile_log(g_constLogDirectory,"HLDS Start....");
}

public 
lolfile_log( const file[], const log[] )
{
    new 
file_index fopen(g_constLogDirectory,"a+");

    new 
log_text[128],log_time[16];
    
    
get_time("%m/%d/%Y - %H:%M:%S",log_time,sizeof(log_time) - 1);
    
    
formatex(log_text,sizeof(log_text) - 1,"%s : %s^n",log_time,log);
    
    
fputs(file_index,log_text);
    
    
fclose(file_index);
    
    return 
0;


Last edited by risontek22; 09-01-2013 at 09:41.
risontek22 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-01-2013 , 08:40   Re: help with file
Reply With Quote #2

While a+ creates files it doesn't create folders. You'll have to use dir_exists() to check if the folder exists and use mkdir() to create it otherwise.

It's also bad to hardcode paths. You should really use get_localinfo along with "amxx_datadir".

You should also include a failsafe, just in case.
if ( ! file_index )
return;

Since you don't use the returned value you don't need to return 0 at the end. You can remove it or just leave it at "return", the result will be the same either way.
__________________
Black Rose is offline
SpaWn2KiLl
Member
Join Date: Aug 2012
Old 09-01-2013 , 09:31   Re: help with file
Reply With Quote #3

Try this:

PHP Code:
new const g_constLog[]    = "log.txt";

public 
plugin_init()
{
    
lolfile_log(g_constLogDirectory,"HLDS Start....");
}

public 
lolfile_log( const file[], const log[] )
{
    new 
path[200]
    new 
newpath[200]

    
get_basedir(path,199

    
formatex(newpath,charsmax(newpath), "%s/data/gangsystem"path)

    if(!
dir_exists(newpath))
        
mkdir(newpath)

    new 
g_constLogDirectory[200]
    
formatex(g_constLogDirectorycharsmax(g_constLogDirectory), "%s/%s"newpathg_constLog)

    new 
file_index fopen(g_constLogDirectory,"at");

    new 
log_text[128],log_time[16];
    
    
get_time("%m/%d/%Y - %H:%M:%S",log_time,sizeof(log_time) - 1);
    
    
formatex(log_text,sizeof(log_text) - 1,"%s : %s^n",log_time,log);
    
    
fprintf(file_index log_text)
    
    
fclose(file_index);

__________________

Last edited by SpaWn2KiLl; 09-01-2013 at 09:36.
SpaWn2KiLl is offline
risontek22
Member
Join Date: Mar 2013
Location: localhost
Old 09-01-2013 , 09:38   Re: help with file
Reply With Quote #4

FIXED! Thanx Black Rose a LOT!
PHP Code:
#include <amxmodx>

new const g_constDirectory[]    = "addons/amxmodx/data/lol/";
new const 
g_constLogDirectory[]    = "addons/amxmodx/data/lol/log.txt";

public 
plugin_init()
{
    
lolfile_log(g_constLogDirectory,"HLDS Start....");
}


public 
lolfile_log( const file[], const log[] )
{
    if( 
dir_exists(g_constDirectory) == )
    {
        
mkdir(g_constDirectory);
    }
    
    new 
file_index fopen(g_constLogDirectory,"a+");
    
    if( ! 
file_index )
    {
        return 
1;
    }
    
    new 
log_text[128],log_time[25];
    
    
get_time("%d.%m. %Y - %H:%M:%S",log_time,sizeof(log_time) - 1);
        
    
formatex(log_text,sizeof(log_text) - 1,"%s : %s^n",log_time,log);
    
    
fputs(file_index,log_text);
        
    
fclose(file_index);
        
    return 
0;


Last edited by risontek22; 09-01-2013 at 09:43.
risontek22 is offline
risontek22
Member
Join Date: Mar 2013
Location: localhost
Old 09-01-2013 , 09:40   Re: help with file
Reply With Quote #5

SpaWn2KiLl, you were late
risontek22 is offline
SpaWn2KiLl
Member
Join Date: Aug 2012
Old 09-01-2013 , 09:41   Re: help with file
Reply With Quote #6

Quote:
Originally Posted by risontek22 View Post
SpaWn2KiLl, you were late
No problem XD, my way works too... I was editing the code in the forum and not in notepad or amxx studio XD
__________________
SpaWn2KiLl is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-01-2013 , 10:07   Re: help with file
Reply With Quote #7

Quote:
Originally Posted by SpaWn2KiLl View Post
No problem XD, my way works too... I was editing the code in the forum and not in notepad or amxx studio XD
The problem with doing so is that you don't see the result. For example, the size of log_time is too small.

Quote:
Originally Posted by risontek22 View Post
FIXED! Thanx Black Rose a LOT!
It's better, but not complete I would say.

const file[] is never used because you use the hardcoded variable g_constLogDirectory[] instead.

And again, you really should use "amxx_datadir", because some people actually moves it.
Do you want me to write the whole code?
__________________

Last edited by Black Rose; 09-01-2013 at 10:09.
Black Rose 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 19:05.


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