[HELP] Logs - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] Logs (
/showthread.php?tid=206441)
[HELP] Logs -
psoftware - 03.01.2011
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.
Re: [HELP] Logs -
Grim_ - 03.01.2011
Don't use dini, very outdated and slow. It's also not created to take on tasks like these. This is where the default file functions are perfect
pawn Код:
// 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;
}
You can simply repeat that process for different things.
Re: [HELP] Logs -
psoftware - 04.01.2011
Thanks!!! But i don't need to insert /n for a new line
Re: [HELP] Logs -
Kwarde - 04.01.2011
Yes you need it. And here's a nice log function (made by me
pawn Код:
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;
}
Example:
[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.
Re: [HELP] Logs -
psoftware - 04.01.2011
This is a nice script thank you!!!!
Re: [HELP] Logs -
Calgon - 04.01.2011
Quote:
Originally Posted by Kwarde
Yes you need it. And here's a nice log function (made by me
pawn Код:
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; }
Example:
[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.
|
That contains a severe amount of redundant code, you should consider just using Unix Timestamps and converting them to normal date/time strings when you absolutely must.
Re: [HELP] Logs -
Kwarde - 04.01.2011
How to get Unix Timestamp? I know what it is etc (right now it's 1294199340)