[HELP] Saving Messages
#1

Hi , i want to save all Player's messages, Like whene a player register/login.
& say his first text in (T)
i wanna that the server create a file called PlayerName.txt
then , every message will be saved in that file .
So is that Possible ? i mean , can we save any player's messages . thank you

Sorry for my bad english.
Reply
#2

pawn Код:
public OnPlayerText(playerid, text[])
{
    new PlayerLog[60], Name[MAX_PLAYER_NAME];
    format(PlayerLog, sizeof(PlayerLog), "logs/%s.txt", GetPlayerName(playerid, Name, sizeof(Name));
    new File:playerslog = fopen(PlayerLog, io_append), string[256];
    format(string, sizeof(string), "%s says: %s", GetPlayerName(playerid, Name, sizeof(Name), text);
    fwrite(playerslog, string);
    fclose(playerslog);
    return 1;
}
Very basic, simply creates a file if it doesn't exist, and when the person uses regular chat (not commands) he creates a log with the text he has in it. The name of the file is his name. I'm not even sure if this will work, I simply took this from another script and changed it to my liking.

If you want to make it so when someone uses a command, it adds that to the file, simply tell me and I can create a function that will do the above but also show what command was done.
Reply
#3

THank u a lot ! +++Rep (i will test it )
Reply
#4

Tested but not working i get 1 error for the first "format" & 1error + 1 warning for the second "format"
Код:
C:\DOCUME~1\ADMINI~1\Bureau\FCDA\GAMEMO~1\FCDA.pwn(294) : error 001: expected token: ",", but found ";"
C:\DOCUME~1\ADMINI~1\Bureau\FCDA\GAMEMO~1\FCDA.pwn(296) : warning 202: number of arguments does not match definition
C:\DOCUME~1\ADMINI~1\Bureau\FCDA\GAMEMO~1\FCDA.pwn(296) : error 001: expected token: ",", but found ";"
Reply
#5

pawn Код:
public OnPlayerText(playerid, text[])
{
    new PlayerLog[60], Name[MAX_PLAYER_NAME], string[256];
    GetPlayerName(playerid, Name, sizeof(Name));
    format(PlayerLog, sizeof(PlayerLog), "logs/%s.txt", Name);
    new File:playerslog = fopen(PlayerLog, io_append);
    format(string, sizeof(string), "%s says: %s\r\n", Name, text);
    fwrite(playerslog, string);
    fclose(playerslog);
    return 1;
}
Reply
#6

How to make it when a player writs something in it get saved in a new row not all in 1 row?
Reply
#7

Quote:
Originally Posted by MarinacMrcina
Посмотреть сообщение
How to make it when a player writs something in it get saved in a new row not all in 1 row?
I edited my post.
Reply
#8

And how can you put a date and time in front of the string that the player said?
Reply
#9

You can use this Log function

pawn Код:
stock Log(const filename[], const string[])
{
    new hour, minute, second;
    gettime(hour, minute, second);
    new year, month, day;
    getdate(year, month, day);
    new timestamp[32];
    format(timestamp, sizeof(timestamp), "[%02d/%02d/%02d | %02d:%02d:%02d] ", day, month, year, hour, minute, second);
    new File:logfile = fopen(filename, io_append);
    fwrite(logfile, timestamp);
    fwrite(logfile, string);
    fwrite(logfile, "\r\n");
    fclose(logfile);
}
pawn Код:
public OnPlayerText(playerid, text[])
{
    new PlayerLog[60], Name[MAX_PLAYER_NAME], string[256];
    GetPlayerName(playerid, Name, sizeof(Name));
    format(PlayerLog, sizeof(PlayerLog), "logs/%s.txt", Name);
    format(string, sizeof(string), "%s says: %s", Name, text);
    Log(PlayerLog, string);
    return 1;
}
Reply
#10

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
You can use this Log function

pawn Код:
stock Log(const filename[], const string[])
{
    new hour, minute, second;
    gettime(hour, minute, second);
    new year, month, day;
    getdate(year, month, day);
    new timestamp[32];
    format(timestamp, sizeof(timestamp), "[%02d/%02d/%02d | %02d:%02d:%02d] ", day, month, year, hour, minute, second);
    new File:logfile = fopen(filename, io_append);
    fwrite(logfile, timestamp);
    fwrite(logfile, string);
    fwrite(logfile, "\r\n");
    fclose(logfile);
}
pawn Код:
public OnPlayerText(playerid, text[])
{
    new PlayerLog[60], Name[MAX_PLAYER_NAME], string[256];
    GetPlayerName(playerid, Name, sizeof(Name));
    format(PlayerLog, sizeof(PlayerLog), "logs/%s.txt", Name);
    format(string, sizeof(string), "%s says: %s", Name, text);
    Log(PlayerLog, string);
    return 1;
}
thank u a lot!
but 1 question, whene i write a message , it doesn't shown in the screen before 2 or 3 seconds , is it due the code ? but anyway u gave to me a HUGE help thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)