Which is the best way to save chat logs/command logs, etc?
#1

Hello guys! I have searched all day for the best method to save chat logs (only the players' texts), command log (only the commands) and so on. Till now, I have found a way, but isn't working.

So, which is the best way to save these logs? And how about the .txt files, where do I save them?
Reply
#2

Try this tutorial https://sampforum.blast.hk/showthread.php?tid=160593
Reply
#3

So, i followed that tutorial, but my console crashes after I log in and type something, and the logs are still empty.

This is what I have in my script (exactly this order):

Код:
#include <file>
Код:
forward ChatLog(chattext[]);
Код:
public ChatLog(chattext[])
{
new entry[300],day,month,year,second,hour,minute, File:hFile;
gettime(hour,minute,second);
getdate(year,month,day);
format(entry,sizeof(entry),"[%02d/%02d/%04d %02d:%02d:%02d] %s\n",day, month, year, hour, minute, second, chattext);
hFile = fopen("Logs/chat.txt",io_append);
fwrite(hFile,entry);
fclose(hFile);
}
Код:
public OnPlayerText(playerid, text[])
{
new textv2[128], pname[25], Float:x, Float:y, Float:z, chattext[300];
GetPlayerName(playerid,pname,24);
GetPlayerPos(playerid,x,y,z);
format(textv2,sizeof(textv2), "%s says: %s", pname, text);
for(new i=0;i<MAX_PLAYERS;i++)
{
	if(IsPlayerInRangeOfPoint(i,100.0,x,y,z))
	{
		SendClientMessage(i,COL_WHITE,textv2);
		format(chattext,sizeof(chattext),"%s",textv2);
		ChatLog(chattext);
	}
}
return 0;
}
And this is my crash info:

Код:
[23:14:57] Incoming connection: 127.0.0.1:54308
[23:14:57] [join] BlackThief has joined the server (0:127.0.0.1)
[23:15:03] [debug] Server crashed while executing test0.1.amx
[23:15:03] [debug] AMX backtrace:
[23:15:03] [debug] #0 native fwrite () [004056e0] from samp-server.exe
[23:15:03] [debug] #1 000096d4 in public ChatLog (0x0002f770) from test0.1.amx
[23:15:03] [debug] #2 0000c34c in public OnPlayerText (0x00000000, 0x0002bea8) from test0.1.amx
[23:15:03] [debug] Native backtrace:
[23:15:03] [debug] #0 77ed3632 in ?? () from C:\Windows\SYSTEM32\ntdll.dll
[23:15:03] [debug] #1 00493990 in ?? () from samp-server.exe
[23:15:03] [debug] #2 0040531e in ?? () from samp-server.exe
What's wrong here? I can't figure out. Maybe I ommited something in the tutorials. Please help me.
Reply
#4

Replace:
pawn Код:
hFile = fopen("Logs/chat.txt",io_append);
fwrite(hFile,entry);
fclose(hFile);
with:
pawn Код:
hFile = fopen("Logs/chat.txt",io_append);
if (hFile)
{
    fwrite(hFile,entry);
    fclose(hFile);
}
I already mentioned that it can crash the server in that thread. It's good to read the comments before using something!
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Replace:

I already mentioned that it can crash the server in that thread. It's good to read the comments before using something!
Ok, now is not crashing anymore, but the text doesn't appear in my chat.txt file. Can you tell me why? It is located in Server > Logs > chat.txt

Thank you anyway!
Reply
#6

Make sure scriptfiles folder is writeable (the permissions).
Reply
#7

Thank you, is working now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)