[TUT] Chat Log -
System64 - 27.06.2011
Hi all! This is my first tutorial on this forum and I'll show you how to make a chat log for your server
It's very simple, it have few steps!
1. Go to your scriptfiles folder and there make a folder called Logs, in him make a new text document Chat.txt (Right click>New>Text Document)
2. Copy this somewhere on the bottom of your script!
pawn Код:
stock ChatLog(playerid, text[])
{
new
File:lFile = fopen("Logs/Chat.txt", io_append),
logData[178],
fyear, fmonth, fday,
fhour, fminute, fsecond;
getdate(fyear, fmonth, fday);
gettime(fhour, fminute, fsecond);
format(logData, sizeof(logData),"[%02d/%02d/%04d %02d:%02d:%02d] %s: %s \r\n", fday, fmonth, fyear, fhour, fminute, fsecond, GetName(playerid), text);
fwrite(lFile, logData);
fclose(lFile);
return 1;
}
Let me explain,
pawn Код:
File:lFile = fopen("Logs/Chat.txt", io_append)
- with this code we make a new text document in folder Logs called Chat.txt
- how many letters will have in that log!
pawn Код:
fyear, fmonth, fday, fhour, fminute, fsecond
- variables with we can see when we open log year, month, day, hour, minute & seconds when that was written!
pawn Код:
getdate(fyear, fmonth, fday);
gettime(fhour, fminute, fsecond);
- with this 2 functions we will learn the time when it was written, year, month, day, hour, minute & seconds!
pawn Код:
format(logData, sizeof(logData),"[%02d/%02d/%04d %02d:%02d:%02d] %s: %s \r\n", fday, fmonth, fyear, fhour, fminute, fsecond, GetName(playerid), text);
- with this function we will format data for log (I dunno how to explain better)!
- variable for size of letters in log!
pawn Код:
fday, fmonth, fyear, fhour, fminute, fsecond
- dyear, month, day, hour, minute & seconds!
- with this function we will get the name of player who written something!
- text that was written by the player!
- with that it enrolled data in log
- with this it close (I dunno why this)!
One more function we need to add on the bottom of your script:
pawn Код:
stock GetName(playerid)
{
new
pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
return pName;
}
3. Just this add this in OnPlayerText callback:
If you done everything ok, enter your server, type something in chat and open Chat.txt, you will have to get something like this,[/size]
pawn Код:
[17/06/2011 09:20:15] System32: test
Normally you will write your name and your text!
Tutorial by System32
Script by Paradox
If I do something wrong or type something wrong please say!
Re: [TUT] Chat Log -
Ronaldo_raul™ - 27.06.2011
Good....but I think now all the Admin scripts are with this thingy's......
Btw Good tutorial....
Re: [TUT] Chat Log -
System64 - 27.06.2011
I dunno, I don't use admin scripts (I have mine) and I saw a lot Chat Logs but only this works for me :P
thanks dude!
Re: [TUT] Chat Log -
Lorenc_ - 28.06.2011
Why is it Croatian people always have unique ideas and creations :3 Well done, this is very useful
Re: [TUT] Chat Log -
playbox12 - 28.06.2011
Quote:
Originally Posted by Lorenc_
Why is it Croatian people always have unique ideas and creations :3 Well done, this is very useful
|
I don't see how this is unique?
Good job, I don't recommend storing everything a player says though, but thats up to you.
Re: [TUT] Chat Log -
[FTC]Scorpion - 01.07.2011
Thanks, man!
Re: [TUT] Chat Log -
System64 - 01.07.2011
Quote:
Originally Posted by playbox12
I don't see how this is unique?
Good job, I don't recommend storing everything a player says though, but thats up to you.
|
Me to, this is not unique but thanks
Re: [TUT] Chat Log -
Lorenc_ - 03.07.2011
Quote:
Originally Posted by playbox12
I don't see how this is unique?
Good job, I don't recommend storing everything a player says though, but thats up to you.
|
Though, never stated whether it is Unique, I'm just saying, they create unique stuff.
Re: [TUT] Chat Log -
Ehab1911 - 03.07.2011
Awesome dude! Love it, but it doesn't save what the players type? Like commands, it doesn't save that :S How to make it save it ^^?
Re: [TUT] Chat Log -
Lenny the Cup - 03.07.2011
It depends on which command processor you have. If you don't know which it is, just put it under OnPlayerCommandText
Re: [TUT] Chat Log -
HfV.pT - 13.08.2011
Good Job!!!
Re: [TUT] Chat Log -
System64 - 13.08.2011
thanks
Re: [TUT] Chat Log -
Snipa - 13.08.2011
You should add if(fexist(filename)) just in case they don't make the file.
Re: [TUT] Chat Log -
emokidx - 13.08.2011
hmm,, pretty useful,, nice
Re: [TUT] Chat Log -
System64 - 13.08.2011
thanks
snipa - I should but I didn't xD
Re: [TUT] Chat Log -
dEcooR - 04.03.2013
very nice ty
Re: [TUT] Chat Log -
Sibuscus - 16.03.2017
Good tutorial, but to be able to use this more efficiently for whisper for /pms for all the other command chats, I'd make it ChatLog(str) without the playerid thing in the brackets. Later on you could just use the format(str bla blah "%s PMed to %s, senderName, receiverName) and store that str in ChatLog(str)
Re: [TUT] Chat Log -
Yashas - 16.03.2017
This is terrible.
The fopen should be moved out. Why open and close a file for every chat message?
This will cause a lot of I/O blocking and take a big toll on the performance. The server is forced to wait until the I/O request is cleared.
Re: [TUT] Chat Log -
Variable™ - 16.03.2017
Quote:
Originally Posted by Yashas
This is terrible.
The fopen should be moved out. Why open and close a file for every chat message?
This will cause a lot of I/O blocking and take a big toll on the performance. The server is forced to wait until the I/O request is cleared.
|
This tutorial is very old and of course not good, the guy just bumped it unnecessarily. There are way pretty much efficient tutorials other than that one.
Re: [TUT] Chat Log -
Sibuscus - 17.03.2017
Quote:
Originally Posted by Variable™
This tutorial is very old and of course not good, the guy just bumped it unnecessarily. There are way pretty much efficient tutorials other than that one.
|
and that's why I bumped it. Can you provide me with a link to an updated tutorial?