[Tutorial] [TUT] Chat Log
#1



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

pawn Код:
logData[178]
- 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)!

pawn Код:
logData
- variable for size of letters in log!

pawn Код:
fday, fmonth, fyear, fhour, fminute, fsecond
- dyear, month, day, hour, minute & seconds!

pawn Код:
GetName(playerid)
- with this function we will get the name of player who written something!

pawn Код:
text
- text that was written by the player!

pawn Код:
fwrite(lFile, logData);
- with that it enrolled data in log

pawn Код:
fclose(lFile);
- 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:
pawn Код:
ChatLog(playerid, text);
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!
Reply
#2

Good....but I think now all the Admin scripts are with this thingy's......

Btw Good tutorial....
Reply
#3

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!
Reply
#4

Why is it Croatian people always have unique ideas and creations :3 Well done, this is very useful

Reply
#5

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.
Reply
#6

Thanks, man!
Reply
#7

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
Reply
#8

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.
Reply
#9

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 ^^?
Reply
#10

It depends on which command processor you have. If you don't know which it is, just put it under OnPlayerCommandText
Reply
#11

Good Job!!!
Reply
#12

thanks
Reply
#13

You should add if(fexist(filename)) just in case they don't make the file.
Reply
#14

hmm,, pretty useful,, nice
Reply
#15

thanks

snipa - I should but I didn't xD
Reply
#16

very nice ty
Reply
#17

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)
Reply
#18

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.
Reply
#19

Quote:
Originally Posted by Yashas
View Post
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.
Reply
#20

Quote:
Originally Posted by Variable™
View Post
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?
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)