03.01.2011, 21:59
How can i do a log in my server with dini?? I want to print in a file the status changes of my server like when players connect and disconnect or when I shut down the server or start it.
// top of script
#define LOG_FILE "log.txt"
public OnPlayerConnect( playerid )
{
new File: hFile = fopen( LOG_FILE, io_append );
if( hFile )
{
new str[ MAX_PLAYER_NAME + 15 ], name[ MAX_PLAYER_NAME ];
GetPlayerName( playerid, name, MAX_PLAYER_NAME );
format( str, sizeof( str ), "%s has connected.", name );
fwrite( hFile, str );
}
fclose( hFile );
return 1;
}
stock AddLog(filename[], log[]) //Usage: AddLog(Name_Of_File, Log_Content (string or something);
{
new day, month, year, hour, minute, second;
new str[200], File:_lfile;
getdate(year, month, day); gettime(hour, minute, second);
format(str, 200, "[%02d-%02d-%02d %02d:%02d:%02d] %s\r\n", day, month, year, hour, minute, second, log);
_lfile = fopen(filename, io_append);
fwrite(_lfile, str);
fclose(_lfile);
return 1;
}
Yes you need it. And here's a nice log function (made by me
pawn Код:
[code] AddLog("LOG.txt", "Hi there!"); If that's used on 01-01-2011 (DAY-MONTH-YEAR) and time 0:0:0, in the file "scriptfiles/LOG.txt" there will be a new line: [01-01-2011 00:00:00] Hi there! When you use it 2 seconds later again, the file will look like this: [01-01-2011 00:00:00] Hi there! [01-01-2011 00:00:02] Hi there! Got it? It gives automatic date+time. And the new line is automatic too. |